Restrict to opening one trade (with Take Profit and Stop Loss) per bar
1 replies
gkouro
4 years ago #256168
Hi I would like to restrict my bot (MT4) to open one trade per bar
via the AlgoWizard I have done the following:
Buy: Bars since Order Open for Long to be greater than 0(so at least one new bar until last long order open)
and Bars since Order Open for Short to be greater than or equal to 0 (I just use this because of the symmetrical conditions. It will always be True)
and
Sell: Bars since Order Open for Short to be greater than 0 (symmetrical to above)
and Bars since Order Open for Long to be greater than or equal to 0 (symmetrical to above)
I attach the strategy
In MQL4 I have coded this as follows:
datetime prevtimeb;
datetime prevtimes;
...
void OnTick()
{
// BUY
if(buy_condition1 && buy_condition2 && prevtimeb!=Time[0])
(
Open_Order(OP_BUY,sl,tp);
prevtimeb=Time[0];
}
// SELL
if(sell_condition1 && sell_condition2 && prevtimes!=Time[0])
(
Open_Order(OP_SELL,sl,tp);
prevtimes=Time[0];
}
}
Backtesting both bots (with same conditions etc.) does not produce similar results.
Any ideas?
tomas262
4 years ago #256616
Hello,
by default a strategy made with Wizard is set to trade once per bar open – it evaluates conditions on bar open only
Viewing 1 replies (of 1 total)