Number of trades per bar

 

how do i make one trade per bar, based on the close price. my backtest makes thousands of traders per bar (see chart)

Files:
chart.gif  44 kb
 

use the:

if(OrdersTotal()<x)

{

.... code to execute eg: buy /sell

}

statement where x=max trades

 

Code

trevman:
how do i make one trade per bar, based on the close price. my backtest makes thousands of traders per bar (see chart)

Trevman,

You can use something like below to limit code execution to 1 time / bar

datetime Timestamp = 0;

if(Timestamp != iTime(NULL,0,0))

{

Timestamp = iTime(NULL,0,0);

..your code here..

}

Cheers,

Herbert

 
leeb:
use the:

if(OrdersTotal()<x)

{

.... code to execute eg: buy /sell

}

statement where x=max trades

i have that but that limits the trades to one trade per time rather than per bar, but thanks

 

Herbert, i cant seem to get that bit of code to work. i dont get any errors but i still get ALOT of trades per bar

 
trevman:
Herbert, i cant seem to get that bit of code to work. i dont get any errors but i still get ALOT of trades per bar

Make sure to declare and initialize the variable TimeStamp as a global variable.

Embrace the code you only want to execute once / bar with the code I showed you.

Please have a look in the Candles.mq4 in the below thread, which I wrote yesterday, using the same 1/bar restriction.

https://www.mql5.com/en/forum

Cheers

 

i tried candles.mq4 between 1999-2007 but it doesnt even make a trade

 
trevman:
i tried candles.mq4 between 1999-2007 but it doesnt even make a trade

It does trade, like the attached report shows.

However that is not the reason for showing you this EA. Just look at the way the TimeStamp code has been implemented.

Ik you still cannot get it working, send me the EA or just the part you want to restrict and I will have a look at it. (PM me for my e-mail address)

Cheers