NeuralNetwork

Author: NNTA
Price Data Components
Series array that contains open prices of each bar
Miscellaneous
Uses files from the file systemIt reads information from a file
0 Views
0 Downloads
0 Favorites
NeuralNetwork
ÿþ//+------------------------------------------------------------------+

//|                                                NeuralNetwork.mq5 |

//|                                                             NNTA |

//|                                                  https://nnta.ru |

//+------------------------------------------------------------------+

#property copyright "NNTA"

#property link      "https://nnta.ru"

#property version   "1.00"

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_label1  "BetaNN"

#property indicator_type1   DRAW_NONE



string signals[][6];



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int OnInit()

  {

   EventSetTimer(3);

   ObjectsDeleteAll(0,"nnta");

   Comment("\n>:;NG0NAL : A5@25@C...");

   file_del();

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

   EventKillTimer();

   ObjectsDeleteAll(0,"nnta");

   Comment("");

   string file_name;

   long search_handle=FileFindFirst(_Symbol+"_nn.txt",file_name);

   if(search_handle!=-1)

     {

      FileDelete(file_name);

      FileFindClose(search_handle);

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const int begin,

                const double &price[])

  {

   return(rates_total);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OnTimer()

  {

   string data=getfile();

   if(data!="" && data!="-")

     {

      Comment("");

      plot(data);

     }

   if(data=="-")

      Comment("\n4C >B25B A5@25@0...");

   if(data=="")

      Comment("\nERROR: ;O MB>9 ?0@K =5B 40==KE 8;8 =5B A2O78 A A5@25@><!");

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int make_sig_arr(string data)

  {

   string lines[];

   ushort u_sep=StringGetCharacter("&",0);

   int k=StringSplit(data,u_sep,lines);

   int ars=ArrayRange(lines,0);

   ArrayFree(signals);

   for(int i=1; i<ars && !IsStopped(); i++)

     {

      string lines2[];

      ushort sep=StringGetCharacter(",",0);

      int k2=StringSplit(lines[i],sep,lines2);

      int ars2=ArrayRange(lines2,0);

      ArrayResize(signals,ArrayRange(signals,0)+1);

      int j=ArrayRange(signals,0)-1;

      signals[j][0]=lines2[0];

      signals[j][1]=lines2[1];

      signals[j][2]=lines2[2];

      signals[j][3]=lines2[3];

      //signals[j][4]=lines2[4];

      //signals[j][5]=lines2[5];

     }

   return ArrayRange(signals,0);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int count_siganls(string dur)

  {

   int res=0;

   int size=ArrayRange(signals,0);

   for(int i=0; i<size; i++)

     {

      if(signals[i][3]==dur)

         res++;

     }

   return res;

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void plot(string data)

  {

   int total_signals=make_sig_arr(data);

   for(int i=0; i<total_signals-1; i++)

     {

      int signal_time=(int)StringToInteger(signals[i][1]);

      int signal_duration_sek=(int)StringToInteger(signals[i][3])*60*60;

      datetime signal_end_time=0;

      if((signal_time+signal_duration_sek)>(int)iTime(NULL,PERIOD_M1,0))

         signal_end_time=(datetime)(signal_time+signal_duration_sek);

      else

        {

         int signal_bars=(int)MathRound(signal_duration_sek/((int)iTime(NULL,0,0)-(int)iTime(NULL,0,1)));

         int signal_end_bar=(int)iBarShift(NULL,0,(datetime)(signal_time))-signal_bars;

         signal_end_time=iTime(NULL,0,signal_end_bar);

        }

      plot_signal(signals[i][0],signals[i][3],signals[i][2],(datetime)signal_time,signal_end_time);

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void plot_signal(string signal_id, string signal_dur, string direction, datetime start_time, datetime end_time)

  {

   string name="nnta_"+signal_id;

   int start_bar=iBarShift(NULL,0,start_time);

   double price=iOpen(NULL,PERIOD_M1,iBarShift(NULL,PERIOD_M1,start_time));



   int width=5;

   if(signal_dur=="1")

      width=2;

   if(signal_dur=="2")

      width=3;

   if(signal_dur=="3")

      width=4;

   if(signal_dur=="6")

      width=5;

   if(signal_dur=="12")

      width=6;

   if(signal_dur=="24")

      width=7;



   color cl=clrGray;



   if(direction=="DOWN")

     {

      ObjectCreate(0,name,OBJ_ARROW_DOWN,0,iTime(NULL,0,start_bar),price);

      ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_BOTTOM);

      ObjectSetInteger(0,name,OBJPROP_COLOR,clrRed);

      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);

      ObjectSetInteger(0,name,OBJPROP_WIDTH,width);

      ObjectSetInteger(0,name,OBJPROP_BACK,false);

      cl=clrRed;

      DrawArrowedLine(name+"l",iTime(NULL,0,start_bar),price,end_time,price,cl,STYLE_SOLID,2);

     }

   if(direction=="UP")

     {

      ObjectCreate(0,name,OBJ_ARROW_UP,0,iTime(NULL,0,start_bar),price);

      ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_TOP);

      ObjectSetInteger(0,name,OBJPROP_COLOR,clrGreen);

      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);

      ObjectSetInteger(0,name,OBJPROP_WIDTH,width);

      ObjectSetInteger(0,name,OBJPROP_BACK,false);

      cl=clrGreen;

      DrawArrowedLine(name+"l",iTime(NULL,0,start_bar),price,end_time,price,cl,STYLE_SOLID,2);

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void DrawLine(string label,

              datetime x1,

              double y1,

              datetime x2,

              double y2,

              color clr=clrGray,

              ENUM_LINE_STYLE st=STYLE_DOT,

              int w=1

             )

  {

   ObjectCreate(0,label,OBJ_TREND,0,x1,y1,x2,y2);

   ObjectSetInteger(0,label,OBJPROP_COLOR,clr);

   ObjectSetInteger(0,label,OBJPROP_STYLE,STYLE_DOT);

   ObjectSetInteger(0,label,OBJPROP_WIDTH,w);

   ObjectSetInteger(0,label,OBJPROP_RAY,0);

   ObjectSetInteger(0,label,OBJPROP_BACK,false);

  }



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void DrawArrowedLine(string label,

                     datetime x1,

                     double y1,

                     datetime x2,

                     double y2,

                     color clr=clrBlack,

                     ENUM_LINE_STYLE st=STYLE_DASH,

                     int w=1

                    )

  {

   ObjectCreate(0,label,OBJ_TREND,0,x1,y1,x2,y2);

   ObjectSetInteger(0,label,OBJPROP_COLOR,clr);

   ObjectSetInteger(0,label,OBJPROP_STYLE,st);

   ObjectSetInteger(0,label,OBJPROP_WIDTH,w);

   ObjectSetInteger(0,label,OBJPROP_RAY,0);

   ObjectSetInteger(0,label,OBJPROP_BACK,false);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

string getfile()

  {

   string fileName=_Symbol+"_nn.txt";

   string res="-";

   if(FileIsExist(fileName))

     {

      int file_handle=FileOpen(fileName,FILE_READ|FILE_TXT|FILE_ANSI);

      res=FileReadString(file_handle);

      FileClose(file_handle);

     }

   else

      Comment("4C 40==K5 >B A5@25@0...");

   return res;

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void file_del()

  {

   for(int ls=0; ls<100; ls++)

     {

      string file_name;

      long search_handle=FileFindFirst(_Symbol+"_nn.txt",file_name);

      if(search_handle!=-1)

        {

         FileDelete(file_name);

         FileFindClose(search_handle);

         break;

        }

      FileFindClose(search_handle);

     }

  }

//+------------------------------------------------------------------+

Comments