Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trailing stop updating unexpectedly...

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

    Trailing stop updating unexpectedly...

    Let's hope I can make this make sense and I do very much appreciate your help. I am getting unexpected trailing stop behavior. I have a multi-timeframe strategy that uses 15min bars coupled with 1tick bars. Below is part of the switch statement where '6' corresponds to the 15min, primary, BarsInProgress, and '7' is the tick-level BarsInProgress. So, the issue is, the trailing stop works just fine unless the position lasts more than one bar, in which case, the stop is updated (as if being called, referenced to the 15min timeframe) even if the price has not hit a new position-high. This does not happen 100% of the time, but when it does, it often raises the stop above the current market price thereby crashing the strategy and ending my trading day. Do you see or have any knowledge why a SetTrailStop call, placed in one timeframe appears to be updated by a second timeframe.

    So, in reference to the code below, I had a position in ZN this morning, trading as expected, trail updating as new highs were hit, and exiting if the target was hit. But, in one instance, when a new 15min bar started, the trailing stop was updated above the market and shut off the strategy.

    I hope that is clear, probably not, but any feedback would be much appreciated. I think there is sufficient code as there are no

    case 6:
    aliveLong[BarsInProgress] = true;
    if ((trading) && (IHigh[BarsInProgress] != 0)) {
    currAsk = GetCurrentAsk();
    if (orders[BarsInProgress] != null) {
    if (orders[BarsInProgress].OrderState != OrderState.Filled) {
    CancelOrder(orders[BarsInProgress]);
    orders[BarsInProgress] = null;
    }
    }
    /*if ((IHigh[BarsInProgress] + TickSize) >= currAsk) {
    orders[BarsInProgress] = EnterLongStop(BarsInProgress + 1, true, contracts[BarsInProgress], IHigh[BarsInProgress] + TickSize, "Long ZN " + ToTime(Time[0]));
    } else {
    orders[BarsInProgress] = EnterLongStop(BarsInProgress + 1, true, contracts[BarsInProgress], currAsk, "Long ZN " + ToTime(Time[0]));
    Print("ZN Ask used rather than IHigh[]");
    }
    SetProfitTarget("Long ZN " + ToTime(Time[0]), CalculationMode.Ticks, targetTicks[BarsInProgress]);
    SetTrailStop("Long ZN " + ToTime(Time[0]), CalculationMode.Ticks, stopTicks[BarsInProgress], false);*/
    }
    break;
    case 7:
    if (tracking) {
    if (Close[0] > IHigh[BarsInProgress-1]) {
    IHigh[BarsInProgress-1] = Close[0];
    }
    if (Close[0] < ILow[BarsInProgress-1]) {
    ILow[BarsInProgress-1] = Close[0];
    if (aliveLong[BarsInProgress - 1] && trading) {
    orders[BarsInProgress - 1] = EnterLong(contracts[BarsInProgress - 1], "ZN Long Reversal" + ToTime(Time[0]));
    SetProfitTarget("ZN Long Reversal" + ToTime(Time[0]), CalculationMode.Ticks, targetTicks[BarsInProgress - 1]);
    SetTrailStop("ZN Long Reversal" + ToTime(Time[0]), CalculationMode.Ticks, stopTicks[BarsInProgress - 1], false);
    aliveLong[BarsInProgress - 1] = false;
    }
    }
    }
    break;

    Thanks for any help,
    Aaron

    #2
    Hi masterjaz99, thanks for your post.

    Do you reset your trailing stops once you are flat?

    I suggest you use TraceOrders = True in your Initialize() to clarify why the trailing stop price gets modified in those unexpected ways you describe.

    Please see this link here - http://www.ninjatrader-support.com/H...aceOrders.html

    Comment


      #3
      Any idea why the Trailing Stop functionality updates based on the primary time-frame when the order is based on a secondary timeframe? I looked back at the order log for today and saw that when ever I am in a position based on a 1-tick timeframe, the trailing stop is updated when the 15min period updates.

      Below is an example from today. Entered a reversal in the ZN based on the 1-tick timeframe using the code I posted earlier. You can see I enter the trade and then the trailing stop moves as expected. Jump ahead to 8:45am and you can see the trailing stop is updated, and I carefully check to assure that ZN was not hitting new position highs...


      Entry and Trailing Stop working as expected:

      1/2/2009 8:38:46 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Working Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.96875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:38:46 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Accepted Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.96875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:38:45 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=PendingChange Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.96875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:29 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Working Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.953125 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:29 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Accepted Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.953125 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:29 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=PendingChange Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.953125 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:07 AM,Order,Order='1H28KR332/7232016240' Name='Profit target' New State=Working Instrument='ZN 03-09' Action=Sell Limit price=126.234375 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:07 AM,Order,Order='1H28KR332/7232016240' Name='Profit target' New State=Accepted Instrument='ZN 03-09' Action=Sell Limit price=126.234375 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:07 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Working Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.921875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:07 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Accepted Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.921875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:07 AM,Order,Order='efe351c4b7834173831a02ba844acc25/7232016240' Name='Profit target' New State=PendingSubmit Instrument='ZN 03-09' Action=Sell Limit price=126.234375 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:07 AM,Order,Order='d5ea18416b434b5dafae83b2450c7392/7232016240' Name='Trail stop' New State=PendingSubmit Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=125.921875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:07 AM,Position,Instrument='ZN 03-09' Account='7232016240' Avg price=126.15625 Quantity=1 Market position=Long Operation=Insert Currency=UsDollar,
      1/2/2009 8:33:07 AM,Execution,Execution='mjvm5axx15k0' Instrument='ZN 03-09' Account='7232016240' Exchange=ECbot Price=126.15625 Quantity=1 Market position=Long Operation=Insert Order='1H28KR328' Time='1/2/2009 8:33:06 AM',
      1/2/2009 8:33:07 AM,Order,Order='1H28KR328/7232016240' Name='ZN Long Reversal83302' New State=Filled Instrument='ZN 03-09' Action=Buy Limit price=126.625 Stop price=0 Quantity=1 Type=Market Filled=1 Fill price=126.15625 Error=NoError Native error='',
      1/2/2009 8:33:06 AM,Order,Order='1H28KR328/7232016240' Name='ZN Long Reversal83302' New State=Working Instrument='ZN 03-09' Action=Buy Limit price=126.625 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:05 AM,Order,Order='1H28KR328/7232016240' Name='ZN Long Reversal83302' New State=Working Instrument='ZN 03-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:04 AM,Order,Order='1H28KR328/7232016240' Name='ZN Long Reversal83302' New State=Accepted Instrument='ZN 03-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:33:04 AM,Order,Order='df6f495ac1af494cb3dd902a1f8215af/7232016240' Name='ZN Long Reversal83302' New State=PendingSubmit Instrument='ZN 03-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',

      Trailing stop updating when a new 15min period begins:
      1/2/2009 8:54:55 AM,Order,Order='1H28KR332/7232016240' Name='Profit target' New State=Cancelled Instrument='ZN 03-09' Action=Sell Limit price=126.234375 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:54:55 AM,Position,Instrument='ZN 03-09' Account='7232016240' Avg price=126.15625 Quantity=0 Market position=Long Operation=Remove Currency=UsDollar,
      1/2/2009 8:54:55 AM,Execution,Execution='1hwvhes176j6ht' Instrument='ZN 03-09' Account='7232016240' Exchange=ECbot Price=126.046875 Quantity=1 Market position=Short Operation=Insert Order='1H28KR330' Time='1/2/2009 8:54:54 AM',
      1/2/2009 8:54:55 AM,Order,Order='1H28KR332/7232016240' Name='Profit target' New State=PendingCancel Instrument='ZN 03-09' Action=Sell Limit price=126.234375 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:54:55 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Filled Instrument='ZN 03-09' Action=Sell Limit price=125.453125 Stop price=126.046875 Quantity=1 Type=Stop Filled=1 Fill price=126.046875 Error=NoError Native error='',
      1/2/2009 8:54:54 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Working Instrument='ZN 03-09' Action=Sell Limit price=125.453125 Stop price=126.046875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:06 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Working Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=126.046875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:06 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=Accepted Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=126.046875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:06 AM,Order,Order='1H28KR378/7232016240' Name='Short 6E 84500' New State=Working Instrument='6E 03-09' Action=SellShort Limit price=0 Stop price=1.3821 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:06 AM,Order,Order='1H28KR378/7232016240' Name='Short 6E 84500' New State=Accepted Instrument='6E 03-09' Action=SellShort Limit price=0 Stop price=1.3821 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:05 AM,Order,Order='1H28KR325/7232016240' Name='Short 6E 83000' New State=Cancelled Instrument='6E 03-09' Action=SellShort Limit price=0 Stop price=1.3821 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:05 AM,Order,Order='1H28KR375/7232016240' Name='Long 6E 84500' New State=Working Instrument='6E 03-09' Action=Buy Limit price=0 Stop price=1.3957 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:05 AM,Order,Order='1H28KR375/7232016240' Name='Long 6E 84500' New State=Accepted Instrument='6E 03-09' Action=Buy Limit price=0 Stop price=1.3957 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:04 AM,Order,Order='1H28KR322/7232016240' Name='Long 6E 83000' New State=Cancelled Instrument='6E 03-09' Action=Buy Limit price=0 Stop price=1.3957 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:04 AM,Order,Order='1H28KR372/7232016240' Name='Short GC 84500' New State=Working Instrument='GC 02-09' Action=SellShort Limit price=0 Stop price=868.8 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:04 AM,Order,Order='1H28KR372/7232016240' Name='Short GC 84500' New State=Accepted Instrument='GC 02-09' Action=SellShort Limit price=0 Stop price=868.8 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:03 AM,Order,Order='1H28KR320/7232016240' Name='Short GC 83000' New State=Cancelled Instrument='GC 02-09' Action=SellShort Limit price=0 Stop price=868.8 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
      1/2/2009 8:45:03 AM,Order,Order='1H28KR330/7232016240' Name='Trail stop' New State=PendingChange Instrument='ZN 03-09' Action=Sell Limit price=0 Stop price=126.046875 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',


      In this case, I was lucky as the trailing stop updated at the new 15min was within allowable orders (not above the market price for long, or below for short).

      I looked at many trades today and found this issue throughout, although it is not always obvious. I also cannot tell where the stop price for the new 15min period comes from...

      Any help would be great. I don't think Trace Orders will help as this is a multi-timeframe trailing stop functionality issue.

      Thanks,
      Aaron

      Comment


        #4
        More Information (Part 1)

        Sorry to keep posting tons and tons of trade logs, but the answer is in there somehow. I am now looking at a series of events in the NQ that exhibit the same behavior. See the data below, and I've highlighted the issue. As you can see the trailing stop jumps from 1222.25 to 1216 without hitting intermediate values, with 1216 actually being above the current market price, hence the strategy flips out and is shut off.

        GW:Cancel reject received for order 00005DA5.Trigger price must be > last price or last day price; Stop Price doesn't match',
        1/2/2009 8:15:02 AM,Order,Order='14a789949d6f49ef94402e02a715a16b/7232016240' Name='Short GC 81500' New State=PendingSubmit Instrument='GC 02-09' Action=SellShort Limit price=0 Stop price=868.8 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:15:02 AM,Strategy,Strategy 'ShortIndexTick' submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.,
        1/2/2009 8:15:02 AM,Order,Order='1H28KR258/7232016240' Name='Trail stop' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:15:02 AM,Order,Order rejected: Broker or exchange option

        GW:Cancel reject received for order 00005DA4.Trigger price must be > last price or last day price; Stop Price doesn't match Affected Order: BuyToCover 1 Stop @ 1216,
        1/2/2009 8:15:02 AM,Order,Order='1H28KR258/7232016240' Name='Trail stop' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1216 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=OrderRejected Native error='Order rejected: Broker or exchange option

        GW:Cancel reject received for order 00005DA4.Trigger price must be > last price or last day price; Stop Price doesn't match',
        1/2/2009 8:15:01 AM,Order,Order='1H28KR262/7232016240' Name='Trail stop' New State=PendingChange Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1216 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:15:01 AM,Order,Order='1H28KR258/7232016240' Name='Trail stop' New State=PendingChange Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1216 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',

        1/2/2009 8:13:16 AM,Order,Order='1H28KR264/7232016240' Name='Profit target' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='1H28KR264/7232016240' Name='Profit target' New State=Accepted Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='1H28KR262/7232016240' Name='Trail stop' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='1H28KR262/7232016240' Name='Trail stop' New State=Accepted Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='bf2493efbe094fb6950b1965a39ef52f/7232016240' Name='Profit target' New State=PendingSubmit Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='ce3504dca4f14205aa1b5d290f44305e/7232016240' Name='Trail stop' New State=PendingSubmit Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='1H28KR260/7232016240' Name='Profit target' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='1H28KR260/7232016240' Name='Profit target' New State=Accepted Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='1H28KR258/7232016240' Name='Trail stop' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Order,Order='1H28KR258/7232016240' Name='Trail stop' New State=Accepted Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:16 AM,Position,Instrument='NQ 03-09' Account='7232016240' Avg price=1217.25 Quantity=2 Market position=Short Operation=Update Currency=UsDollar,
        1/2/2009 8:13:16 AM,Execution,Execution='170is8g1tzh22n' Instrument='NQ 03-09' Account='7232016240' Exchange=Globex Price=1217.25 Quantity=1 Market position=Short Operation=Insert Order='1H28KR256' Time='1/2/2009 8:13:15 AM',
        1/2/2009 8:13:16 AM,Order,Order='1H28KR256/7232016240' Name='NQ Short Reversal81311' New State=Filled Instrument='NQ 03-09' Action=SellShort Limit price=1211.25 Stop price=0 Quantity=2 Type=Market Filled=2 Fill price=1217.25 Error=NoError Native error='',
        1/2/2009 8:13:15 AM,Order,Order='1e90d4d49fca4c79b7119713f5ca086d/7232016240' Name='Profit target' New State=PendingSubmit Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:15 AM,Order,Order='87b3d7004b8641f48be5f5c430f8b050/7232016240' Name='Trail stop' New State=PendingSubmit Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:15 AM,Position,Instrument='NQ 03-09' Account='7232016240' Avg price=1217.25 Quantity=1 Market position=Short Operation=Insert Currency=UsDollar,
        1/2/2009 8:13:15 AM,Execution,Execution='pfwyez17dy4zu' Instrument='NQ 03-09' Account='7232016240' Exchange=Globex Price=1217.25 Quantity=1 Market position=Short Operation=Insert Order='1H28KR256' Time='1/2/2009 8:13:14 AM',
        1/2/2009 8:13:15 AM,Order,Order='1H28KR256/7232016240' Name='NQ Short Reversal81311' New State=PartFilled Instrument='NQ 03-09' Action=SellShort Limit price=1211.25 Stop price=0 Quantity=2 Type=Market Filled=1 Fill price=1217.25 Error=NoError Native error='',
        1/2/2009 8:13:14 AM,Order,Order='1H28KR256/7232016240' Name='NQ Short Reversal81311' New State=Working Instrument='NQ 03-09' Action=SellShort Limit price=1211.25 Stop price=0 Quantity=2 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:13 AM,Order,Order='1H28KR256/7232016240' Name='NQ Short Reversal81311' New State=Working Instrument='NQ 03-09' Action=SellShort Limit price=0 Stop price=0 Quantity=2 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:13 AM,Order,Order='1H28KR256/7232016240' Name='NQ Short Reversal81311' New State=Accepted Instrument='NQ 03-09' Action=SellShort Limit price=0 Stop price=0 Quantity=2 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
        1/2/2009 8:13:12 AM,Order,Order='2417abbe987f4c36b1cc204fefb17018/7232016240' Name='NQ Short Reversal81311' New State=PendingSubmit Instrument='NQ 03-09' Action=SellShort Limit price=0 Stop price=0 Quantity=2 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',



        Even more wierd, while highlighting the trades and prices, I noticed that the trailing stop function then sends the correct value or so it appears after it has sent the incorrect stop value. See red vs. blue highlighting.

        I added some more log rows (post Part 2) to show that when the original trailing stop is cancelled after the strategy closes the rouge position, the stop value is once again correct. I do not have any code that updates the trailing stop on the 15min bar update (it has been commented out), so this must be within the trailing stop functionality. Please have your programmers have a look.

        I have more examples of the same behavior if needed.

        Hope we can work through this as I don't want to program my own trailing stop functionality.

        Thanks for all your help,
        Aaron

        Comment


          #5
          Part 2

          1/2/2009 8:15:15 AM,Order,Order='1H28KR262/7232016240' Name='Trail stop' New State=Cancelled Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:15 AM,Order,Order='1H28KR264/7232016240' Name='Profit target' New State=Cancelled Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:15 AM,Order,Order='1H28KR258/7232016240' Name='Trail stop' New State=Cancelled Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:15 AM,Order,Order='1H28KR260/7232016240' Name='Profit target' New State=Cancelled Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:15 AM,Order,Order='1H28KR262/7232016240' Name='Trail stop' New State=PendingCancel Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:15 AM,Order,Order='1H28KR264/7232016240' Name='Profit target' New State=PendingCancel Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:15 AM,Order,Order='1H28KR258/7232016240' Name='Trail stop' New State=PendingCancel Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:15 AM,Order,Order='1H28KR260/7232016240' Name='Profit target' New State=PendingCancel Instrument='NQ 03-09' Action=BuyToCover Limit price=1215.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error='',

          1/2/2009 8:15:15 AM,Position,Instrument='NQ 03-09' Account='7232016240' Avg price=1217.25 Quantity=0 Market position=Short Operation=Remove Currency=UsDollar,
          1/2/2009 8:15:15 AM,Execution,Execution='i78xak1b0ghuw' Instrument='NQ 03-09' Account='7232016240' Exchange=Globex Price=1218.25 Quantity=2 Market position=Long Operation=Insert Order='1H28KR281' Time='1/2/2009 8:15:14 AM',
          1/2/2009 8:15:15 AM,Order,Order='1H28KR281/7232016240' Name='Close' New State=Filled Instrument='NQ 03-09' Action=BuyToCover Limit price=1224.25 Stop price=0 Quantity=2 Type=Market Filled=2 Fill price=1218.25 Error=NoError Native error='',
          1/2/2009 8:15:14 AM,Order,Order='1H28KR281/7232016240' Name='Close' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=1224.25 Stop price=0 Quantity=2 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:14 AM,Order,Order='1H28KR281/7232016240' Name='Close' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=2 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:14 AM,Order,Order='1H28KR281/7232016240' Name='Close' New State=Accepted Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=2 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',

          1/2/2009 8:15:03 AM,Order,Order='1H28KR262/7232016240' Name='Trail stop' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1222.25 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
          1/2/2009 8:15:03 AM,Order,Order rejected: Broker or exchange option

          GW:Cancel reject received for order 00005DA5.Trigger price must be > last price or last day price; Stop Price doesn't match Affected Order: BuyToCover 1 Stop @ 1216,
          1/2/2009 8:15:03 AM,Order,Order='1H28KR262/7232016240' Name='Trail stop' New State=Working Instrument='NQ 03-09' Action=BuyToCover Limit price=0 Stop price=1216 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=OrderRejected Native error='Order rejected: Broker or exchange option

          This is the log that shows the trailing stop is cancelled with the correct price.

          So, the ultimate question is: Where did the 1216 price come from and why was it submitted???

          Thanks,
          Aaron

          Comment


            #6
            Hi masterjaz99, thanks for posting the TraceOrder outputs. A few suggestions that come to mind - 1. Try plotting your TrailStop price from the strategy, easier to see where it goes off 2. Use BarsInProgress to update the trailing stop only when the OnBarUpdate is called from the 1 Tick chart - http://www.ninjatrader-support.com/H...BarSeries.html

            Comment


              #7
              Thanks for the reply. I guess the issue is that I am not updating the stop, as I am using the built-in SetTrailStop() function and rely on it to properly update when a new position high is hit. So, in reality, this may be a Ninja Trader functionality.

              I think I will try removing the primary 15min timeframe and see, but if this works, it may be wise to have your programmers check this out. Also of note, this only occurs when I place an order in the 1-tick OnBarUpdate, when I place an order in the 15min OnBarUpdate but track it in the 1-tick timeframe, everything appears to work normally. Again, this does not occur 100% of the time, so we'll have to work together to get this solved.

              I do appreciate you help and hope someone from NT may also be looking over the issue.

              Aaron

              Comment


                #8
                Hello,

                Someone reply to your post on Monday. Sorry for the delay.
                DenNinjaTrader Customer Service

                Comment


                  #9
                  Hi masterjaz99, the internal SetTrailStop logic will move the trailstop evey tick...please post your latest code for review here. Thanks!

                  Comment


                    #10
                    Ben and Bertrand,
                    I really appreciate your help and support with this issue. The code has not changed from what was originally posted. The main issue, as I see it, is found in the order log previously posted.

                    Look at the order 1H28KR258 and see how it changes price from the correct 1222.25 to 1216 without hitting any intermediate values and then returns to the 1222.25 when canceled. The only thing that happens there is the 15min bar event fires off, and is suspect as the anomolous price occurs at 8:15:01.

                    I checked the charts and 1216 was not the market price at 8:15 nor was it a notable price in any way. I have absolutely no idea from where it came. The only thing that may occur is that on the 15min event, my strategy allows for a second position to be entered, but with a new name and a new trailing stop linked to that new name. My guess is that this is a minor bug associated with multi-timeframe trading.

                    Currently, I have re-written the code to exclude the 15min timeframe and only use 1 tick, thereby possibly avoiding this issue. Sadly, the market today is not trading in a fashion to test the new code (no position has been held across multiple 15min bars). I will update you with results from my new code (thereby implicating multi-timeframe issues), and will provide both strategies in their entirety via private mail.

                    Hope that is clear?

                    Thanks again,
                    Aaron

                    Comment


                      #11
                      Hi Aaron, thanks for your patience with this issue. Here's what we think is the reason for the behavior you see: your calls like this [BarsInProgress - 1] access your primary bars object, which would be the 15min one. At the time you are calling those on the 1 tick chart, you could be for example 9 min into the next developing 15min bar, but you still access the last completed bar with the call (which would explain the trail stop value jump you noticed). Please also review this link here ('How Data is referenced') - http://www.ninjatrader-support.com/H...struments.html

                      Comment


                        #12
                        Sounds very reasonable and logical. I am going to focus on my new code that removes the 15min timeframe for the while. It is a little more difficult to program, but if it works, then it will be worth it. Thank you very much for your help and I hope others may see this if they recognize this unexpected, yet ultimately understandable, behavior.

                        Happy Holidays,
                        Aaron

                        Comment


                          #13
                          You are welcome Aaron, please let us know where / when you get stuck...Happy holidays to you as well!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          558 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          324 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          101 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          545 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          547 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X