Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change limit order price on every tick

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

    Change limit order price on every tick

    I'm new to Ninja so I may be asking a stupid question. I have a strategy which places a limit order when a condition is true. While the condition is true I need to evaluate and may update the limit order price after each tick.

    I have 2 questions.

    1) Do I use OnBarUpdate or onMarketData to change the limit order price?

    2) To change an existing limit order, do I need to cancel and then enter a new limitorder after each tick? or do I just enter a new limit order? Can I change the limitorder after each tick?

    Thanks,

    Afshin

    #2
    Hello,

    1) Do I use OnBarUpdate or onMarketData to change the limit order price?

    This is up to you, both would work but it depends on how you want to handle it.

    2) To change an existing limit order, do I need to cancel and then enter a new limitorder after each tick? or do I just enter a new limit order? Can I change the limitorder after each tick?

    Either one would work. EnterLongLimit() with the same signal name would just update the order.

    You may want to read the following however, as there is some nuance to how that works :



    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi Adam,
      I also want to change managed entry order in method OnMarketData on every change of bid or ask price but have a synchronization problem.
      Before I change order I check if order is not filled ( entry.OrderState != OrderState.Filled) but nevertheless on same time of order change order is filled and strategy canels entry order and close position.

      Is it possible to avoid this situation ?

      If you need additional trace info I can send full trace.log

      regards
      Klaus

      Comment


        #4
        Klaus,

        Is this a multi-series strategy? I.e. does it use multiple time frames and / or instruments to determine the order entry?
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Adam,
          it is a single time frame / instrument strategy

          Comment


            #6
            Klaus,

            I am wondering if you are having a similar issue here :



            Post 20 and higher.

            I may need to see some code to look into this further.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              This is my code


              private IOrder order = null;
              private bool isBuy = true;
              private int offsetTicks = 1;
              private int barsInProgress = 0;
              private int quantity = 1;
              private string orderName = "Test";

              public double BuyOrderPrice(double askPrice)
              {
              return (askPrice - offsetTicks * TickSize);
              }

              public double SellOrderPrice(double bidPrice)
              {
              return (bidPrice + offsetTicks * TickSize);
              }

              protected override void OnMarketData(MarketDataEventArgs e)
              {

              switch( e.MarketDataType )
              {
              case MarketDataType.Ask:
              if( !isBuy )
              return;
              break;

              case MarketDataType.Bid:
              if( isBuy )
              return;
              break;

              default:
              return;
              }

              // get new limit price, only change order if different from previous
              double newLimitPrice = isBuy? BuyOrderPrice(e.Price): SellOrderPrice(e.Price);

              if( order == null || (order.LimitPrice != newLimitPrice && order.OrderState != OrderState.Filled) )
              {
              order = isBuy?
              EnterLongLimit (barsInProgress, true, quantity, newLimitPrice, orderName):
              EnterShortLimit(barsInProgress, true, quantity, newLimitPrice, orderName);
              }
              }

              entry order is only placed in OnMarketData

              Comment


                #8
                Hello,

                Thanks for providing that - in your strategy have you enabled the TraceOrders property? If so, do you have the output from that time?

                If not, I'd suggest enabling this which will output valuable debugging information to help determine why the order was cancelled:

                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Hello Matthew,
                  sorry for delay.
                  Attached trace info

                  Comment


                    #10
                    This limit order is expiring when the condition is no longer true:

                    Strategy.StrategyBase.Process.ExpiredOrder

                    Please see our Reference Sample on Keeping Orders Alive for more information:

                    MatthewNinjaTrader Product Management

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    655 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    370 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    109 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
                    577 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X