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

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

Manage alerts

Loading saved threads...

car20 · External communityPost link
External question — Stack Overflow Stack Exchange Author: car20 Original post: https://stackoverflow.com/questions/77271312 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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
Quote
Report
Mark SdS · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Mark SdS Original post: https://stackoverflow.com/a/77277770 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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()
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Mark SdS Source score (net votes, not local likes): 1 Original post: https://stackoverflow.com/a/77277770 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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()

Cancel quote

Checking account access…