Was reviewing a strategy under development and noticed that when using SetTrailStop with a specified number of ticks, the actual stop price being initially placed was much closer to the entry than expected. To isolate the issue from any of my other code, I built a simple strategy (attached) that trades a specific instance where I've observed this and logs the order information obtained through OnOrderUpdate(). It tests SetStopLoss() against SetTrailStop() with the same settings, and highlights a wide difference in initial stop position between the two. My expectation (which may be incorrect) is that these two methods, supplied with the same parameters, should yield roughly the same initial stop price when the associated order is placed.
Here's what I'm seeing in this test case, using MNQ DEC24 on a 2m chart:
SetStopLoss(signalName, CalculationMode.Ticks, 150, false);// Expected result
In this, we can see Mode=Ticks and Value=150, which on this instrument should translate to a stop value $37.5 from entry. And that is what we get, with an short entry at $20084.75 and stop at $20122.25 (20122.25 - 20084.75 = 37.5).
9/23/2024 9:12:00 AM Strategy 'ValidateTrailStopStrategy': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='test-order' Mode=Ticks Value=150 IsSimulatedStop=False IsMarketIfTouched=False 9/23/2024 9:12:00 AM Strategy 'ValidateTrailStopStrategy': Entered internal SubmitOrderManaged() method at 9/23/2024 9:12:00 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='test-order' FromEntrySignal='' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'test-order' limitPrice: '0' stopPrice: '0' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Submitted' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'test-order' limitPrice: '0' stopPrice: '0' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Accepted' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'test-order' limitPrice: '0' stopPrice: '0' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Working' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'Stop loss' limitPrice: '0' stopPrice: '20122.25' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Submitted' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'Stop loss' limitPrice: '0' stopPrice: '20122.25' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Accepted' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'Stop loss' limitPrice: '0' stopPrice: '20122.25' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Working' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'test-order' limitPrice: '0' stopPrice: '0' quantity: '1' filled: '1' averageFillPrice: '20084.75' orderState: 'Filled' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: ''
Here's the same trade using a trail stop, also using Mode=Ticks and Value=150, which should (I believe) also translate to a stop value $37.5 from entry. However, here we get the same short entry at $20084.75 but a stop at $20090. 20090 - 20084.75 = 5.25, or 21 ticks. Naturally, this results in the trade being stopped out prematurely.
9/23/2024 9:12:00 AM Strategy 'ValidateTrailStopStrategy': Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='test-order' Mode=Ticks Value=150 IsSimulatedStop=False IsMarketIfTouched=False 9/23/2024 9:12:00 AM Strategy 'ValidateTrailStopStrategy': Entered internal SubmitOrderManaged() method at 9/23/2024 9:12:00 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='test-order' FromEntrySignal='' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'test-order' limitPrice: '0' stopPrice: '0' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Submitted' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'test-order' limitPrice: '0' stopPrice: '0' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Accepted' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'test-order' limitPrice: '0' stopPrice: '0' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Working' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'Trail stop' limitPrice: '0' stopPrice: '20090' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Submitted' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'Trail stop' limitPrice: '0' stopPrice: '20090' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Accepted' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'Trail stop' limitPrice: '0' stopPrice: '20090' quantity: '1' filled: '0' averageFillPrice: '0' orderState: 'Working' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'test-order' limitPrice: '0' stopPrice: '0' quantity: '1' filled: '1' averageFillPrice: '20084.75' orderState: 'Filled' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: '' 9/23/2024 9:12:00 AM [OnOrderUpdate] Order Name: 'Trail stop' limitPrice: '0' stopPrice: '20090' quantity: '1' filled: '1' averageFillPrice: '20090' orderState: 'Filled' time: '9/23/2024 9:12:00 AM' error: 'NoError' comment: ''

Comment