Trailing Stoploss acting very strange during backtesting
25 Mar 2018, 12:16
I applied a trailing stoploss to a trading algorithm. The bid rises and the position stoploss is modified nicely then the price action comes down to the stoploss level but the trades are not exectuted for 4 bars at 10 pips below the stoploss.
Here is a char shot:
http://roboforex.ctrader.com/c/4jb6n
Here is a link to the events with the position modified entries highlighted :
https://1drv.ms/x/s!AtUxdR-7aDCchlnBeeyMx1mNSK5b
It should close at 1.35305 but suddenly closes at 1.35206.
I can't figure out why its behaving like that.
Replies
PanagiotisCharalampous
26 Mar 2018, 12:29
Hi lec0456,
Thanks for reporting this. Could we have a cBot and backtesting parameters that will allow us to reproduce this issue?
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
26 Mar 2018, 14:03
( Updated at: 19 Mar 2025, 08:57 )
Hi lec0456,,
cBot with code would be preferable. If you cannot post it here, please send it to support@ctrader.com.
Best Regards,
Panagiotis
@PanagiotisCharalampous

lec0456
26 Mar 2018, 11:22
So, to update. I still can not figure out why cAlgo backtest engine fails to close the trade when the price goes below the stoploss.
What I did however, was place some code to programatically close the trade if price goes below the SL. But this code should not be necessary.
foreach (var position in Positions) { if (position.TradeType == TradeType.Buy && position.StopLoss != null && position.StopLoss > Symbol.Bid) ClosePosition(position); if (position.TradeType == TradeType.Sell && position.StopLoss != null && position.StopLoss < Symbol.Ask) ClosePosition(position); }So, the issue is why is the backtesting engine not executing trades after Stoplosses are hit? Whats going on?
You can compare the difference in the charts after I added the code to close after SL is hit:
http://roboforex.ctrader.com/c/qn06n
If i don' put the code in, cAlgo does not close the trade for an hour and 3 previous bars all cross the SL multiple times.
@lec0456