Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with OCO.

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

    Problem with OCO.

    Good morning.
    Think I need NinjaTrader support help.
    I a have simple situation: the current price and two levels-above and below the price.(Let's say "LevelPlus1" and "LevelMinus1").
    If EMA of price crossabove or crossbelow the levels-TP or SL is triggered. Other order is cancel by OCO.
    Now, "version A (with limit order)"
    ...Unmanaged = true;
    TraceOrders = true;
    if (SELL != null
    && SELL.OrderState == OrderState.Filled
    && TPafterSELL == null
    && SLafterSELL == null
    && ((EMA(15)[0] >= LevelPlus1) || (EMA(15)[0] <= LevelMinus1)))
    {TPafterSELL = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, LevelMinus1, 0, "1", "TAKE PROFIT");
    SLafterSELL = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, 1, 0, LevelPlus1, "1", "STOP LOSS");}
    and,"version B (with market order)"
    ...{TPafterSELL = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, LevelMinus1, 0, "1", "TAKE PROFIT");
    SLafterSELL = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, 1, 0, LevelPlus1, "1", "STOP LOSS");}
    Please look at attached screenshots. I don't know what is the right decision.Please help.Thank You in advance.
    Attached Files

    #2
    Hi CRUISE, are those screenshots from realtime trading / sim trading this system on live data and the simulator? If you execute market order stop market orders in realtime you're trading against the current spread in the market, this would be contrast to backtesting those order types using 'last' prices only, thus it would be expected to see a differences in execution prices here.

    Comment


      #3
      Thank you for your prompt response.No,it's from backtest on historical data.
      I very need Your advise - what type of orders I must use in this situation.Now - for backtest ,and later-for RT.

      Comment


        #4
        Thanks - for the profit target exit you would normally use a limit order to try avoiding paying the spread, for the stop out normally a Stop Market is preferred, as a StopLimit could potentially leave you unfilled here.

        Comment


          #5
          Thank You for clear advise for RT trading.I fully understand it.
          But I must to backtest my modest idea before it.
          Please look at two lines of my code again .There's simpliest situation. I need a clear answer - what is it - my mistake or bug of NinjaTrader. Backtest is not working correct for me now.If this simple situation is not possible to code in Ninja I will go to another software and will not waste anyone's time.
          Thank You.

          Comment


            #6
            CRUISE, you would need to run this with TraceOrders turned on to exactly see at which price you would submit the orders, this can sometimes be misleading as rounding can affect those levels, too. Limit order would be filled at the set price in backtesting and never better to be conservative as possible when gauging performence achieved.



            If you can attach the full script you run or send to support at ninjatrader dot com we can give it a run on our end as well.

            Thanks,

            Comment


              #7
              Thank You for reply.
              1.You read my first post? I guess not.What is it on line number 9?Correct,"TraceOrders = true;".
              2.For whom I attached the Output window?Correct,for NinjaTrader support.It's nothing personal.
              My fault - I didn't explain that Output window is for screenshot number 4 - the most important of all.Look at the NAME of filled SL order!
              NT canceled (OCO) wrong order on wrong price level.
              3.I am wasting too much time for NinjaScript already.Now I want to deside - I will stay on or not.
              I don't understand - what is the clear URL?It's on the main site?They will give me a clear answer
              about possibility coding this simple situation.
              With best regards

              Comment


                #8
                CRUISE, thanks for the clarifications - please contact me with your complete strategy code at support at ninjatrader dot com Attn Bertrand so we can give it a run here and attempt to reproduce the issue on our end.

                Thanks in advance,

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                660 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                375 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                110 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                579 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X