Search code examples
mql4

The problem of using the for loop in the OrderSend MQL4 function


I have a problem in MQL4 programming. I would be grateful if my friends could help me. I first calculated the value of Tenkensen and Kijonsen with the formula . With the execution of the expert , I expect 4 transactions of the Buy Limit type to be opened according to the defined arrays.(Each time the loop is executed) But by executing the code, one transaction, two transactions and three transactions are opened randomly. When I use the **comment **function, everything is correct, but the results are not correct with SendOrder Thanks

extern int SL = 20;    // Enter StopLost (pips)
extern int TP = 20 ; //Enter TakeProfit(pips)

string charts[] = {"USDCAD","USDJPY"};  // charts can be added like "EURUSD" , "USDCHF" 
int TimeFrame[] = {43200,10080};     // 43200 => PERIOD_MN1 , 10080 => PERIOD_W1

int OnInit()
  {
  
SL *=10;
TP *=10;
  
   for(int i = 0; i<2; i++)
     {
      for(int j = 0; j<2; j++)
        {
         Sleep(5000);
 
            double TenkenSen = (iHigh(charts[i],TimeFrame[j],iHighest(charts[i],TimeFrame[j],MODE_HIGH,9,0))+ iLow(charts[i],TimeFrame[j],iLowest(charts[i],TimeFrame[j],MODE_LOW,9,0))) /2; // Computing TenKensen ICHIMOKO
            double KijonSen  = (iHigh(charts[i],TimeFrame[j],iHighest(charts[i],TimeFrame[j],MODE_HIGH,26,0))+ iLow(charts[i],TimeFrame[j],iLowest(charts[i],TimeFrame[j],MODE_LOW,26,0))) /2; // Computing KijonSen ICHIMOKO
            
            int TiketBuy = OrderSend(charts[i],OP_BUYLIMIT,0.01,KijonSen,5,KijonSen-(SL*Point),KijonSen+(TP*Point),"Test",2222,0,clrGreen);
               
                 }
    }
   
   return(INIT_SUCCEEDED);
  }

I get different results by changing the array values


Solution

  • It might have to do with the location of your for loop, it is inside the onInit() function? And it is remarkable that orders are accepted since you're not using normalizeDouble()