Скачать книгу

TicketSell0;

      datetime Count=1;

      double Buf_0[100000];

      double Buf_1[100000];

      string File_Name="Indicator.csv";

      int K;

      int i;

      //+–+

      //| Expert initialization function |

      //+–+

      int OnInit()

      {

      //–

      int Handle=FileOpen(File_Name,FILE_CSV|FILE_READ,";");

      while(Count>0)

      {

      Count=StrToTime(FileReadString(Handle));

      Buf_0[i]=StrToDouble(FileReadString(Handle));

      Buf_1[i]=StrToDouble(FileReadString(Handle));

      i++;

      }

      //–

      return(INIT_SUCCEEDED);

      }

      //+–+

      //| Expert deinitialization function |

      //+–+

      void OnDeinit(const int reason)

      {

      //–

      }

      //+–+

      //| Expert tick function |

      //+–+

      void OnTick()

      {

      //–

      for( i=1; i<=OrdersHistoryTotal(); i++)

      {

      if(OrderSelect(i-1,SELECT_BY_POS,MODE_HISTORY)==true)

      {

      if(TicketBuy1==OrderTicket()) MagicBuy1=0;

      if(TicketSell0==OrderTicket()) MagicSell0=0;

      }

      }

      //–Buy0

      if(MagicBuy1==0 && K>0 && Buf_0[K-1]<Buf_1[K-1] && Buf_0[K]>Buf_1[K] && TimeHour(TimeCurrent())>H1 && TimeHour(TimeCurrent())<H2 && H1<H2)

      {

      bool send1=OrderSend(Symbol(),OP_BUY,1,Ask,3,Bid-Loss1*Point,Ask+Profit1*Point,NULL,1,0,Red);

      for( i=1; i<=OrdersTotal(); i++)

      {

      if(OrderSelect(i-1,SELECT_BY_POS)==true)

      {

      TicketBuy1=OrderTicket();

      MagicBuy1=OrderMagicNumber();

      }

      }

      }

      if(MagicBuy1==1 && K>0 && Buf_0[K-1]>Buf_1[K-1] && Buf_0[K]<Buf_1[K])

      {

      bool close1=OrderClose(TicketBuy1,1,Bid,2,Blue);

      }

      //–Sell0

      if(MagicSell0==0 && K>0 && Buf_0[K-1]>Buf_1[K-1] && Buf_0[K]<Buf_1[K] && TimeHour(TimeCurrent())>H3 && TimeHour(TimeCurrent())<H4 && H3<H4)

      {

      bool send0=OrderSend(Symbol(),OP_SELL,1,Bid,3,Ask+Loss0*Point,Bid-Profit0*Point,NULL,3,0,Green);

      for( i=1; i<=OrdersTotal(); i++)

      {

      if(OrderSelect(i-1,SELECT_BY_POS)==true)

      {

      TicketSell0=OrderTicket();

      MagicSell0=OrderMagicNumber();

      }

      }

      }

      if(MagicSell0==3 && K>0 && Buf_0[K-1]<Buf_1[K-1] && Buf_0[K]>Buf_1[K])

      {

      bool close0=OrderClose(TicketSell0,1,Ask,2,Blue);

      }

      K++;

      }

      //+–+

      Выше представлен полученный результат. Как видно из кода скрипта мы ограничили время совершения сделок и выставили ограничения по прибыли и убытку.

      //–Buy0

      if(MagicBuy1==0 && K>0 && Buf_0[K-1]<Buf_1[K-1] && Buf_0[K]>Buf_1[K] && TimeHour(TimeCurrent())>H1 && TimeHour(TimeCurrent())<H2 && H1<H2)

      {

      bool send1=OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,NULL,1,0,Red);

      for( i=1; i<=OrdersTotal(); i++)

      {

      if(OrderSelect(i-1,SELECT_BY_POS)==true)

      {

      TicketBuy1=OrderTicket();

      MagicBuy1=OrderMagicNumber();

      }

      }

      }

      if(MagicBuy1==1 && K>0 && Buf_0[K-1]>Buf_1[K-1] && Buf_0[K]<Buf_1[K] )

      {

      bool close1=OrderClose(TicketBuy1,1,Bid,2,Blue);

      }

      //–Sell0

      if(MagicSell0==0 && K>0 && Buf_0[K-1]>Buf_1[K-1] && Buf_0[K]<Buf_1[K] && TimeHour(TimeCurrent())>H3 && TimeHour(TimeCurrent())<H4 && H3<H4)

      {

      bool send0=OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,NULL,3,0,Green);

      for( i=1; i<=OrdersTotal(); i++)

      {

      if(OrderSelect(i-1,SELECT_BY_POS)==true)

      {

      TicketSell0=OrderTicket();

      MagicSell0=OrderMagicNumber();

      }

      }

      }

      if(MagicSell0==3

Скачать книгу