Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 fernandobr, Today, 09:11 AM
          0 responses
          0 views
          0 likes
          Last Post fernandobr  
          Started by itrader46, Today, 09:04 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by timmbbo, Today, 08:59 AM
          0 responses
          2 views
          0 likes
          Last Post timmbbo
          by timmbbo
           
          Started by bmartz, 03-12-2024, 06:12 AM
          5 responses
          33 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by Aviram Y, Today, 05:29 AM
          4 responses
          14 views
          0 likes
          Last Post Aviram Y  
          Working...
          X