Не проходит в маркет усреднитель

 

Приветствую! 

Не проходит в маркет простой  усреднитель.

 

Тестирую у себя различными способами, обходится без ошибок. Спросил у модераторов настройки с которыми они тестируют, тоже самое.

Может быть кто то что то подскажет? 

double stop=StopLoss,take=TakeProfit;
....

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ModifyOrders()
  {
   bool m;
   int err=0;
   double all=0,tp=0,sl=0,count=0;

   double StopLevel=MarketInfo(NULL,MODE_STOPLEVEL);
   if(StopLevel==0) StopLevel=MarketInfo(NULL,MODE_SPREAD)*3;

   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
              {
               all+=OrderOpenPrice()*OrderLots();
               count+=OrderLots();
              }
           }
        }
     }

   if(count>0) all=NormalizeDouble(all/count,Digits);

   for(int k=1; k<=10; k++)
     {
      for(int i=OrdersTotal()-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
              {
               if(OrderCloseTime()==0 && OrderType()<2)
                 {
                  if(stop<StopLevel)
                    {
                     Print("The parameter is incorrect! StopLoss will be set to the size of the Spread*3");
                     stop=(int)StopLevel;
                    }
                  if(take<StopLevel)
                    {
                     Print("The parameter is incorrect! TakeProfit will be set to the size of the Spread*3");
                     take=(int)StopLevel;
                    }
                  if(OrderType()==0)
                    {
                     tp=NormalizeDouble(all+take*Point,Digits);
                     sl=NormalizeDouble(all-stop*Point,Digits);

                     if(OrderTakeProfit()!=tp || OrderStopLoss()!=sl)
                       {
                        m=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
                        Print("SL: ",sl," TP: ",tp);
                        if(!m)
                          {
                           err=GetLastError();
                           Print("Error(",err,") modifying order: ",ErrorDescription(err));

                           // Блокировка работы советника
                           if(ErrorsAction(err)==2)
                             {
                              Trade=false;
                              Print("Stop the Advisor!");
                              return;
                             }
                           // Длительная пауза
                           if(ErrorsAction(err)==1)
                             {
                              Sleep(1000*300); return;
                             }
                           //  Небольшая пауза
                           if(ErrorsAction(err)==0)
                             {
                              Sleep(1000*10);
                             }
                          }
                       }
                    }
                 }

               if(OrderType()==1)
                 {
                  tp=NormalizeDouble(all-take*Point,Digits);
                  sl=NormalizeDouble(all+stop*Point,Digits);
                  if(OrderTakeProfit()!=tp || OrderStopLoss()!=sl)
                    {
                     m=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
                     Print("SL: ",sl," TP: ",tp);
                     
                     if(!m)
                       {
                        err=GetLastError();
                        Print("Error(",err,") modifying order: ",ErrorDescription(err));

                        // Блокировка работы советника
                        if(ErrorsAction(err)==2)
                          {
                           Trade=false;
                           Print("Stop the Advisor!");
                           return;
                          }
                        // Длительная пауза
                        if(ErrorsAction(err)==1)
                          {
                           Sleep(1000*300); return;
                          }
                        //  Небольшая пауза
                        if(ErrorsAction(err)==0)
                          {
                           Sleep(1000*10);
                          }
                       }
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
 
Ну в принты добавь OrderOpenPrice() и всё поймёшь.
 
AlexeyVik:
Ну в принты добавь OrderOpenPrice() и всё поймёшь.
Попробовал на другом терминале там есть ошибка. До этого гонял на альпах не было ничего. параметры передает правильно, но ошибку все равно сыпет:

 
Опытным путем пришел к тому что стоплевел должен быть не меньше 3-х спредов, только тогда нет ошибки.
Причина обращения: