Download MetaTrader 5

How to prevent EA to open trades on every new candle once all conditions are met ?

To add comments, please log in or register
salexes
812
salexes  

Hello,

 I just started learning MQL language and I have a question, right now I have build a EA which is checking if all my different conditions to take a trade are met. When this happens then the order should be executed once.

Right now if all conditions are met it openens a trade at that moment, but on every candle after this (where conditions are still met) too, how can I limit it to only take a trade once?


Can I somehow set a flag so it will be checked if an order was already executed once, and once the conditions change and are not met anymore it gets reset, till the next time all conditions are met?


Best regards, 

salexes 

whroeder1
16575
whroeder1  
salexes:

Right now if all conditions are met it openens a trade at that moment, but on every candle after this (where conditions are still met) too, how can I limit it to only take a trade once?

Can I somehow set a flag so it will be checked if an order was already executed once, and once the conditions change and are not met anymore it gets reset, till the next time all conditions are met?

Right now your condition is testing a level
bool isBuy = Bid > X;
Don't test a level, test a change in signal.
static bool isBuy = false;
bool wasBuy = isBuy; isBuy = Bid > X;
if(isBuy && !wasBuy) // new signal
no flag needed.
To add comments, please log in or register