Hi I tired to open trade on the next bar by using the code from earnforex web. After using this code I use this code to open the trade,
But when I backtested my strategy I found that EA will open trade on next candle but on the close price or near close price (pic attached, logic where dot occur). Anyone can tell why EA open trade near close price instead of open price?
MQL4:
slippage = 0; if(logic == 1) { OpenCandle = iOpen(Symbol(),PERIOD_CURRENT,0); double openPriceBuy = OpenCandle; double stoplossBuy = OpenCandle - stoploss; double takeProfitBuy = OpenCandle + takeprofit; double lotsizeBuy = 0.01; int ticket = OrderSend(Symbol(),OP_BUY,lotSizeBuy,openPriceBuy,slippage,stoplossBuy,takeProfitBuy,"BUY",MagicNumber); } if(logic == 2) { OpenCandle = iOpen(Symbol(),PERIOD_CURRENT,0); double openPriceSell = OpenCandle; double stoplossSell = OpenCandle - stoploss; double takeProfitSell = OpenCandle + takeprofit; double lotsizeSell = 0.01; int ticket = OrderSend(Symbol(),OP_BUY,lotSizeSell,openPriceSell,slippage,stoplossSell,takeProfitSell,"BUY",MagicNumber); }
But when I backtested my strategy I found that EA will open trade on next candle but on the close price or near close price (pic attached, logic where dot occur). Anyone can tell why EA open trade near close price instead of open price?
Attachments
Last edited by a moderator: