Download MetaTrader 5
To add comments, please log in or register
Format text in the messages editor. It is convenient!
jasma
23
jasma 2014.03.21 09:35 

Hey guys,

I am using one EA to open trades and the other EA to close trades. The problem is: if the order is opened and closed on the same bar, I dont want the EA to open it again on the same bar even if the same condition is met.

Could help me by telling how it could be done?

Thanks

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.03.21 11:02  
jasma:

Hey guys,

I am using one EA to open trades and the other EA to close trades. The problem is: if the order is opened and closed on the same bar, I dont want the EA to open it again on the same bar even if the same condition is met.

Could help me by telling how it could be done?

Thanks

Search the forum for "once per bar"
Toast
220
Toast 2014.03.21 11:28  

Create a variable with global scope

datetime LastBar = 0;

Run this at the start of OnTick()

if(LastBar == Time[0]) { return; }
LastBar = Time[0];
Keith Watford
Moderator
7990
Keith Watford 2014.03.21 13:40  
toast:

Create a variable with global scope

datetime LastBar = 0;


Run this at the start of OnTick()

if(LastBar == Time[0]) { return(rates_total); }
LastBar = Time[0];


OnTick is a void function, so a value is not returned

rates_total is only used in indicators as far as I know

and is meaningless in an EA

Toast
220
Toast 2014.03.21 14:24  

Quite right - my apologies. Didn't really give it much thought as I typed it out.

Replace return(rates_total) with return.

Edited above post.

/
To add comments, please log in or register