I'm probably missing something here so would appreciate any clarity that can be offered into how SetTrailStop is expected to behave.
I'll present my scenario.
1) I'm using ES ##-## Daily bars
2) I call SetTrailStop only once in State=Configure
else if (State == State.Configure)
{
SetTrailStop(CalculationMode.Ticks, 400);
}
if (CurrentBar == 37)
{
EnterLong();
}
That's it. Here is the result:
In the chart below, the order is submitted on 3/15 and the trade is entered at the open of 3/16.
It enters at a price of 4301.50. And the chart shows that the trailing stop is executed at the exact same price.
This _partially_ relates to a previous post of mine wondering why the trail stop executes at the open price. But my question for this post is more about why the stop order is submitted with its specific stop price. See order details below.
Here are the printed orders (discussion below):
1: CB=37, TM=2022-03-15 16:00 (start of OnBarUpdate for 3/15/2022 bar)
orderId='NT-00000-116' account='Sim101' name='Buy' orderState=Submitted instrument='ES ##-##' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-03-15 16:00:00' gtd='2099-12-01' statementDate='2023-01-24'
orderId='NT-00000-116' account='Sim101' name='Buy' orderState=Accepted instrument='ES ##-##' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-03-15 16:00:00' gtd='2099-12-01' statementDate='2023-01-24'
orderId='NT-00000-116' account='Sim101' name='Buy' orderState=Working instrument='ES ##-##' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-03-15 16:00:00' gtd='2099-12-01' statementDate='2023-01-24'
2: CB=37, TM=2022-03-15 16:00, SP=NaN (end of OnBarUpdate for 3/15/2022 bar)
orderId='NT-00001-116' account='Sim101' name='Trail stop' orderState=Submitted instrument='ES ##-##' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4319.25 quantity=1 tif=Day oco='NT-00000-116' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-03-15 16:00:00' gtd='2099-12-01' statementDate='2023-01-24'
orderId='NT-00001-116' account='Sim101' name='Trail stop' orderState=Accepted instrument='ES ##-##' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4319.25 quantity=1 tif=Day oco='NT-00000-116' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-03-15 16:00:00' gtd='2099-12-01' statementDate='2023-01-24'
orderId='NT-00001-116' account='Sim101' name='Trail stop' orderState=Working instrument='ES ##-##' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4319.25 quantity=1 tif=Day oco='NT-00000-116' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-03-15 16:00:00' gtd='2099-12-01' statementDate='2023-01-24'
orderId='NT-00000-116' account='Sim101' name='Buy' orderState=Filled instrument='ES ##-##' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Day oco='' filled=1 averageFillPrice=4301.5 onBehalfOf='' id=-1 time='2022-03-15 16:00:00' gtd='2099-12-01' statementDate='2023-01-24'
orderId='NT-00001-116' account='Sim101' name='Trail stop' orderState=Filled instrument='ES ##-##' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4319.25 quantity=1 tif=Day oco='NT-00000-116' filled=1 averageFillPrice=4301.5 onBehalfOf='' id=-1 time='2022-03-15 16:00:00' gtd='2099-12-01' statementDate='2023-01-24'
1: CB=38, TM=2022-03-16 16:00 (start of OnBarUpdate for 3/16/2022 bar)
2: CB=38, TM=2022-03-16 16:00 (end of OnBarUpdate for 3/16/2022 bar)
On 3/15 we see that the buy order is submitted. Good.
Then before OnBarUpdate runs for the 3/16 bar, the buy order is filled. Good.
The trail stop order is submitted with a price of 4319.25, that is the high of the 3/16 bar minus the 400 tick offset applied in SetTrailStop. Bad.
In theory, the trail stop would have been submitted immediately after the buy order was filled at the open of the 3/16 bar. But if that's the case, how did the trail stop order know what the high of the bar was, so as to calculate the price with respect to the high of the bar? The high hasn't happened yet.
Shouldn't the stop price have been calculated with respect to the entry price of the buy order? Is this just a trick applied to this special case when we are using standard fill processing and we know that the trail stop will be triggered and executed during the bar?
I'm just very leery of anything that even appears to use future data. I wouldn't think such a trick would be necessary.
Right now, this behavior looks incorrect to me, as though the trail stop order is seeing into the future when it shouldn't be.
Why isn't the trail stop order submitted with a price that is calculated with respect to the entry price of the buy order instead of the high price of the bar?

Comment