Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel Replace?

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

    Cancel Replace?

    In a strategy with using a ExitLongLimit for a profit:
    privatevoid BuyProfit()
    {
    if (Position.MarketPosition == MarketPosition.Long)
    {
    ExitLongLimit(Position.AvgPrice + Target * TickSize,
    "Buy1_Profit", "Buy1");
    }
    }
    What would be the best way to Cancel and Replace this order with a BreakEven if conditions became unfavorable?

    Thanks

    #2
    Hi Ken,

    You could change the limit price on the order. If you resubmit the same statement with updated price, then it will modify the order with the new parameters. You can also submit ExitLong() statement conditionally. If the strategy position is flat, it cancels all outstanding exit orders.

    A sample for modifying target and stop loss levels is here. It uses set statements but the same principles apply- you're modifying the price of an order after defined conditions:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      So if I'm not using Set, how do I change "Target" to "BreakEven"?
      Thanks

      Comment


        #4
        If you resubmit the same statement but with an updated price, then it will modify the order with the new parameters.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I'm sorry, the reason I'm asking is because I don't know how to do that. "Target" is an int variable. If I use the variable: (Private int BreakEven = 0)

          If "New Condition"
          ExitLongLimit(Position.AvgPrice + BreakEven * TickSize, "Buy1_BreakEven ", "Buy1");


          What happens to the original "Buy1_Profit" ExitLongLimit? Does it get canceled because of the "from" order "Buy1"? Or do I need to do something else to cancel it?

          Thanks

          Comment


            #6
            Hi Ken,

            Best suggestion I have is to play around with it. If you keep everything the same except the price, you'll see the order is modified each time you submit a new ExitLongLimit(). You don't have to cancel but you can do that if you want. There is a sample on CancelOrder() available here.

            Attached is a strategy that submits a new ExitLongLimit with every bar. It starts far and then moves closer to price.
            Attached Files
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Thanks for your input. Does the ExitLongLimit name have to remain the same or can it be changed to suit?
              if (Position.MarketPosition == MarketPosition.Long && doOnce)
              {
              firstBar = CurrentBar;
              doOnce =
              false;
              ExitLongLimit(Position.AvgPrice + TickSize *
              50, "Buy1_at_50 ", "Buy1");
              }

              if (!doOnce && CurrentBar - firstBar == 1)
              ExitLongLimit(Position.AvgPrice + TickSize *
              40, "Buy1_at_40 ", "Buy1");

              if (!doOnce && CurrentBar - firstBar == 2)
              ExitLongLimit(Position.AvgPrice + TickSize *
              30, "Buy1_at_30 ", "Buy1");

              if (!doOnce && CurrentBar - firstBar == 3)
              ExitLongLimit(Position.AvgPrice + TickSize *
              20, "Buy1_at_20 ", "Buy1");

              if (!doOnce && CurrentBar - firstBar >= 4)
              ExitLongLimit(Position.AvgPrice + TickSize *
              10, "Buy1_at_10 ", "Buy1");

              Comment


                #8
                It depends how you have it coded. These conditions are not true on the same bar, so one order is expiring and another is submitting.

                If you submit an order with a different signal name while another is active, then you will see multiple orders submitted. You have to keep everything the same except for price in order to modify the order and not submit a duplicate.

                To track strategy order submission and view related messages, add TraceOrders = true; to your initialize() method and view output in Tools > Ouptut Window.

                There is a lot of background info available in the managed order section of our help guide:
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  In the example below the only condition is being "long". So if another condition is present that says if you're long and "this" then BreakEven. Will the BuyBreakEven() replace or add another ExitLongLimit? Both methods would be running at the same time.

                  private
                  void BuyProfit()
                  {
                  if (Position.MarketPosition == MarketPosition.Long)
                  {
                  ExitLongLimit(Position.AvgPrice + Target * TickSize,
                  "Buy1_Profit", "Buy1");
                  }
                  }
                  private void BuyBreakEven()
                  {
                  if (Position.MarketPosition == MarketPosition.Long && This)
                  {
                  ExitLongLimit(Position.AvgPrice + BreakEven * TickSize,
                  "Buy1_Profit", "Buy1");
                  }
                  }

                  Comment


                    #10
                    Yes, if true it processes that statement and submits / modifies the order. It will modify price using the latest ExitLongLimit() statement submitted. If both those conditions are true on the same bar or same tick then the actual price level depends on what order it processes the code.

                    You have to control the desired order submission / modification through your conditional checks or selectively making calls to these custom methods.
                    Last edited by NinjaTrader_RyanM1; 03-22-2011, 02:02 PM.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Obviously in this senario both conditions could be true at the same time, but the BreakEven needs to supercede the Target at this point. Since the BreakEven becomes the closer target and if it is filled and there is no longer an active long position will the original ExitLongLimit at the Target price be cancelled? And if so does it matter what each ExitLongLimit is named if they are both "from" Buy1?

                      Comment


                        #12
                        If one is filled and your position is closed, Ninja cancels all remaining exit orders.

                        It matters what each are named depending on desired behavior.
                        With same signal name: Order is modified. The ExitLongLimit() statement that is received last will determine the price level.

                        With unique signal names: Multiple orders are submitted.
                        Ryan M.NinjaTrader Customer Service

                        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