Trailing Stop Loss not Shown and does not work in Tick Level Back Test

Created at 12 Feb 2024, 10:17
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!
sirinath's avatar

sirinath

Joined 25.11.2021

Trailing Stop Loss not Shown and does not work in Tick Level Back Test
12 Feb 2024, 10:17


The trailing stop loss level is not shown in:

1 Positions

2 In the chart

 

Also I am not sure if it works at all as the stop loss does not seam to execute even when hasTrailingStopLoss is set to true.

This is when back testing with tick data from server on a 1 minute bar chart.

 

My expectation is that the trailing stop loss price is fully managed by the system as the price moves.

 

The code is roughly

 

		if (...) {
			double price = Symbol.Ask;
			double distance = 1;
			double trail = distance + 0.1;
			double target = price + (trail * Symbol.PipSize);
			double volume = Symbol.VolumeInUnitsMin;
			string lable = $"Long {bpc}";
			string comment = $"Long {volume} at {target} with trailing SL of {trail} pips ({distance}%) from {price}";
			TradeOperation result = PlaceStopOrderAsync(TradeType.Buy, SymbolName, volume , target, lable, trail, null, null, comment, true, StopTriggerMethod.Opposite, StopTriggerMethod.Opposite, null);
		}

		if (...) {
			double price = Symbol.Bid;
			double distance = 1;
			double trail = distance + 0.1;
			double target = price - (trail * Symbol.PipSize);
			double volume = Symbol.VolumeInUnitsMin;
			string lable = $"Short {spc}";
			string comment = $"Short {volume} at {target} with trailing SL of {trail} pips ({distance}%) from {price}";
			TradeOperation result = PlaceStopOrderAsync(TradeType.Sell, SymbolName, volume , target, lable, trail, null, null, comment, true, StopTriggerMethod.Opposite, StopTriggerMethod.Opposite, null);
		}
 

@sirinath
Replies

sirinath
12 Feb 2024, 12:20

I suspect this might be perhaps due to rounding of the number pips but not sure.


@sirinath

firemyst
13 Feb 2024, 00:39 ( Updated at: 13 Feb 2024, 00:44 )

Are you able to provide screen captures of your back-test parameters?

 

Also, I don't believe async trade operations are fully supported in backtest or work as expected in backtest by their very nature… eg, in backtest mode, everything is “instantaneous” as opposed to live markets where one async call may execute right away, others will have a delay, etc etc.


@firemyst

sirinath
13 Feb 2024, 03:28

RE: Trailing Stop Loss not Shown and does not work in Tick Level Back Test

 

 

 

Asyc I think should be simulated even in back tests I believe. I mean all the API should be available in backtest otherwise what is the point of the backtest as you will get some incorrect result.


@sirinath

PanagiotisCharalampous
13 Feb 2024, 07:02

Hi there,

Check the logs to see if the trailing stop loss is actually set. You could be using an invalid stop loss value.

Best regards,

Panagiotis


@PanagiotisCharalampous