Trailing Stoploss acting very strange during backtesting

Created at 25 Mar 2018, 12:16
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
lec0456's avatar

lec0456

Joined 14.11.2012

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.


@lec0456
Replies

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

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

lec0456
26 Mar 2018, 13:22

Will a compiled cBot be suficient or do you require the source code?  My cBot is pretty complex, and uses several custom indicators so I would need to take out the relavant part if you need the source code.

Also, where should  I send it?


@lec0456

PanagiotisCharalampous
26 Mar 2018, 14:03

Hi lec0456,,

cBot with code would be preferable. If you cannot post it here, please send it to community@spotware.com.

Best Regards,

Panagiotis


@PanagiotisCharalampous