use the:
if(OrdersTotal()<x)
{
.... code to execute eg: buy /sell
}
statement where x=max trades
Code
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
use the:
if(OrdersTotal()<x)
{
.... code to execute eg: buy /sell
}
statement where x=max tradesi 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
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.
Cheers
i tried candles.mq4 between 1999-2007 but it doesnt even make a trade
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
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
how do i make one trade per bar, based on the close price. my backtest makes thousands of traders per bar (see chart)