Sleep code

 

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

 
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"
 

Create a variable with global scope

datetime LastBar = 0;

Run this at the start of OnTick()

if(LastBar == Time[0]) { return; }
LastBar = Time[0];
 
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

 

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.

Reason: