I'm learning to write an advisor... - page 7

 

Also, am I checking the condition of the foot on the three criteria correctly?

  //проверяем если есть поза, стоит стоп и не стоит БУ        
       if ((OrdersTotal()>0)&& (OrderStopLoss()!=0) && (OrderStopLoss()!= SLBU))
            ModifySLinBU();   //передаем управление в ф-ю установки БУ

Or is it

  //проверяем если есть поза, стоит стоп и не стоит БУ        
       if ((OrdersTotal()>0)&& (OrderStopLoss()!=0 && SLBU))
            ModifySLinBU();   //передаем управление в ф-ю установки БУ
 

Have you heard of a "period shift" on this forum?

Let me explain. For example H4 candlesticks are different in all brokerage companies, it is clear - because the server time is different. How to shift these candlesticks according to time, to get other characteristics at the output - the maximum, minimum, open, close...

What is all this for? My brokerage company has the same candlesticks and the strategy that I implement by my Expert Advisor works, but there are many errors of chart mismatching. (As far as I understand, this is a problem of my brokerage company and it is not welcomed during analysis by forum participants!)

But having downloaded the MetaQuotes history there are no errors, but even during visual testing the candlesticks do not show many signals and the EA test using them gives bad results.

That's why I started to think about it - to "shift" candlesticks to coincide with my brokerage company or another one.

 

How to reduce your DC errors and improve modelling quality?



EUR/0.1-10 lot/1 year/300-322000

 

See if I am processing the order change correctly? What are the possible pitfalls here?

//+------------------------------------------------------------------+
//| Открытие позиции на покупку
//+------------------------------------------------------------------+
void OpenBuy() 
  { 
   RefreshRates();
      if ((OrdersTotal()==0) && (Ask == Enter)) //бъем до упора эту цену
         {
            if (IsTradeContextBusy()==false)
               {
                  OrderSend(Symbol(), OP_BUY, Lot, Enter, Slippage, 0, 0, 0, MAGIC,0, clOpenBuy);
                  if (OrdersTotal()>0)
                     {
                        Modify = false;                              //флаг установки SL и TP - не установлен
                        ModifySL();                        
                     }
                  else Print("Ошибка установки ордера BAY по цене ",OrderOpenPrice()," код ошибки ="+GetLastError());
               }  
         }              
      if ( UseSound) PlaySound( NameFileSound);
  } 
//+------------------------------------------------------------------+
//| Открытие позиции на продажу
//+------------------------------------------------------------------+
void OpenSell() 
  { 
   RefreshRates();
      if ((OrdersTotal()==0)&&(Bid == Enter))  //бъем до упора эту цену
         { 
            if (IsTradeContextBusy()==false)
               {
                  OrderSend(Symbol(), OP_SELL, Lot, Enter, Slippage, 0, 0, 0, MAGIC,0, clOpenSell);
                  if (OrdersTotal()>0)
                     {
                        Modify = false;                              //флаг установки SL и TP - не установлен
                        ModifySL();
                     }   
                  else Print("Ошибка установки ордера SELL по цене ",OrderOpenPrice()," код ошибки ="+GetLastError());
               }
         }
      if ( UseSound) PlaySound( NameFileSound);        
  } 
//+------------------------------------------------------------------+
//| Модификация ордера на установку SL и TP                                                                 |
//+------------------------------------------------------------------+
void ModifySL()
   {
      if (OrderSelect(0, SELECT_BY_POS)==true) // Если есть открытый ордер
         {       
            if (OrderType()==OP_BUY)
               {
                  StopL = SLB(); 
                  TakeP = TPB();
                  Modify = OrderModify(OrderTicket(),OrderOpenPrice(), StopL, TakeP,0,Red);
                  if ( Modify == false) Print("Ошибка изменения ордера #",OrderTicket(), " при попытке установить СТОП ", StopL,". Текущая цена- ",Bid,", код ошибки ="+GetLastError());
               }
            else
               {
                  StopL = SLS(); 
                  TakeP = TPS();
                  Modify = OrderModify(OrderTicket(),OrderOpenPrice(), StopL, TakeP,0,Red);
                  if ( Modify == false) Print("Ошибка изменения ордера #",OrderTicket(), " при попытке установить СТОП ", StopL,". Текущая цена- ",Ask,", код ошибки ="+GetLastError());
               }
         }     
   }

Then int Start () checks for modification...

//+------------------------------------------------------------------+
//| Проверка открытого оредра на установку SL,TP и установка SL,TP
//+------------------------------------------------------------------+
    if ((OrdersTotal()>0) && ( Modify == false)) ModifySL();  //SL и TP - не установлен
 

Thank you who helped!)

I am currently learning how to run an EA on different symbols at the same time...

Can you tell me if this variant is good for finding an order belonging to a symbol on which the EA is running?

for (int i=1; i<=OrdersTotal(); i++)          //Цикл по всем ордерам,..
  {                                           //отражённым в терминале
      if(OrderSelect( i-1, SELECT_BY_POS)==true)//Если есть следующий         
        {
          if(OrderSymbol()==Symbol())
            {
              if (OrderType()==OP_BUY)
               {
                 ... 
               }  
              else
               {
                 ...
               }

            }
        } 
  }                                         //Конец тела цикла
Reason: