Metatrader 4 | No trades to be placed on EA re-initialization

Metatrader 4 | No trades to be placed on EA re-initialization

Manage alerts

Loading saved threads...

user14476920 · External communityPost link
External question — Stack Overflow Stack Exchange Author: user14476920 Original post: https://stackoverflow.com/questions/65897796 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 an EA which places a trade - considering all other conditions are met - at the beginning of the candlestick bar & based on the "datetime time[0]`. Naturally, if I were to reinitialize the EA, the EA would "re-recognise" the conditions and execute another trade. How would I stop that from happening on the oninit section of my EA? Thanks
Quote
Report
tomgny · External communityPost link
External answer — Stack Overflow Stack Exchange Author: tomgny Original post: https://stackoverflow.com/a/66029663 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Declare global variable bool initTrade = true; and: int OnInit() { if(OrdersTotal() > 0){ if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS)){ if(Minute() == TimeMinute(OrderOpenTime()) && Hour() == TimeHour(OrderOpenTime()) && Day() == TimeDay(OrderOpenTime())){ initTrade = false; } if(initTrade){ //Open init order logic... } } } return(INIT_SUCCEEDED); }
Quote
Report

Post Reply

Checking account access…