Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetTrailStop Appears to See Future Data (?)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    SetTrailStop Appears to See Future Data (?)

    UPDATE: While the below example is a case where a trailing stop exits a position in the same bar it was entered, the behavior described below with regard to the stop price of the trailing stop order also happens when the trailing stop does not exit in the same bar. The stop order is still submitted with a price that is relative to the high of the bar, even though technically, the trailing stop order would have been submitted at the open of the bar and therefore not yet know anything about the high price of the bar.


    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
    Code:
    else if (State == State.Configure)
    {
        SetTrailStop(CalculationMode.Ticks, 400);
    }​
    3) I have a simple entry on a specific BarIndex. Happens to be 3/15/2022.
    Code:
    if (CurrentBar == 37)
    {
        EnterLong();
    }​
    4) I'm using standard order fill resolution.

    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.

    Click image for larger version  Name:	image.png Views:	0 Size:	35.3 KB ID:	1232570

    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?
    Last edited by BarzTrading; 01-24-2023, 11:23 PM.

    #2
    Hello BarzTrading,

    Set methods set the trigger for the entry to place the stop and target the moment the entry fills.

    The price of the order, when using CalculationMode.Ticks, is based on the AverageFillPrice of the entry, and is not based on any specific data.

    After the order is submitted, the movement of trailing or breakeven actions, and the fill of the order in historical, is based on data. The order fills based on the bar data available on the fill bar.

    With no intra-bar granularity, the order is filled if it is within the bar.


    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X