Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bracket Order (Multiple entry -Market +Limit with different trail stop)

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

    Bracket Order (Multiple entry -Market +Limit with different trail stop)

    I am trying to code a strategy which is following a typical basket order..
    if(Short)
    // Basket order 1: submit a market order with 1 qty , trail stop 10 tick & target 10 tick
    // Basket order 2: submit a limit order Ask + 3 ticks with 2 qty :- trail stop 8 tick & target 20 tick
    // Basket order 3: submit a limit order Ask + 7 ticks with 3 qty. - trail stop 6 tick & target 30 tick

    ach of these will have a different trail stop and target. i have coded majority of the part but for some weird reason ninja is throwing moving ordr 1 trail stop loss below market price even if the price is going down, actually changing trail stop. this only happens when trail stop becomes very close to order 2/3 limit price and once they are filled ninja is changing order 1 trail stoploss for weird reason moving it up above market price and resulting into below exception.
    2019-07-13 21:17:59:337|0|32|Playback101, Stop price can't be changed below the market. affected Order: BuyToCover 2 StopMarket @ 59.43

    Attaching log for review, as well as some of my snippet which is creating long order and placing stoptrail order.

    On barUpdate:
    if(BarsInProgress == 1) { 1 second data series

    if (SHORT_CONDICTION ) {
    exitOpenPendingPosition(); // exit any open limit order if they are not yet filled.
    if (PositionAccount.MarketPosition == MarketPosition.Long) ExitLong();

    EnterShort(1,"ShortOrder-MKT"); // Basket Order 1: Market Order
    entryOrderShort1a = EnterShortLimit(0,true,2,GetCurrentAsk() +3*TickSize,"ShortLimitOrder-1a"); // Basket Order 2: Limit Order
    entryOrderShort1b = EnterShortLimit(0,true,3,GetCurrentAsk() +7*TickSize,"ShortLimitOrder-1b");// Basket Order 2: Limit Order
    lastShortBarCounter = CurrentBars[0];
    }
    }


    if(State == State.DataLoaded) {

    SetProfitTarget("ShortOrder-MKT", CalculationMode.Ticks, target_MktOrder); // Basket order 1: Target
    SetProfitTarget("ShortLimitOrder-1a", CalculationMode.Ticks, target_basket1); // Basket order 2: Target , keep order 3 open and only trail.

    SetTrailStop("ShortOrder-MKT", CalculationMode.Ticks, 10,false);//, 0.03, 0.3, 0.01);
    SetTrailStop("ShortLimitOrder-1a", CalculationMode.Ticks, 8,false);//, 0.03, 0.3, 0.01);
    SetTrailStop("ShortLimitOrder-1b", CalculationMode.Ticks, 6,false);//, 0.03, 0.3, 0.01);
    }
    Attached Files
    Last edited by Manishzain; 07-14-2019, 10:47 AM. Reason: updating right log fil

    #2
    If i change trailstop to regular stoploss then this works fine, but i want to to use trail stop as part of basket order. i also have following settings
    EntryHandling = EntryHandling.UniqueEntries;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;

    Comment


      #3
      Hello Manishzain,

      When using set trail stop, this is still logic that is reacting to the price and then sending an order and is still subject to an inflight execution.

      If a change order is sent and the price changes before it is received it is possible that change order will be on the wrong side of the market.

      Below is a link to the help guide on in-flight-executions.


      To correct this, increase the trail distance to prevent the change orders from being on the wrong side of the market when the price is fluctuating.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        I also thought so that may be trail stop is on tighter side, so i had it increased to 30 ticks for all the orders listed above but still the same issue even after that, then i added tick series to my strategy to also ensure that trail stop is updated every tick if price moves away from it, still no luck.. Instead during replay i noticed that trail stopped moved even though price move closer to it during market replay. which is very odd. i am attaching logs for ur review.
        you can search on this trail stop order.. 4c84ef85ba664420a58d3f3383713f15/Playback101 you will it was changed multiple times successfully but failed immediately after limit order (last order for basket) filled(80f554e61f2e416a846c63dbd9118309/Playback101).

        Attached Files

        Comment


          #5
          Hello Manishzain,

          The error itself, 'Stop price can't be changed below the market' means the order is on the wrong side of the market.

          I recommend you print the price and the ask at the same time so that you can see what the price was that was invalid.
          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