Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Only update Limit order if it's Higher for Long and Lower for Short

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

    Only update Limit order if it's Higher for Long and Lower for Short

    I am trying to place exit order on Long and Short but somehow it's coming on everybar and ignoring submitorder.


    Here is the Log message. Need help to understand this log message also. My intension is to Update the Limit price if it goes higher than the current limit else keep the same limit exit order.

    Specifically I need help with this part.


    Code:
       if ( Position.MarketPosition == MarketPosition.Long)
                {
                    EnterLongLimit(Convert.ToInt32(DefaultQuantity), (EMA3[0] + ((ATR1[0] * Multiplier) )) , @"APBull");
                }
    
                if ( Position.MarketPosition == MarketPosition.Short)
                {
    
                    EnterShortLimit(Convert.ToInt32(DefaultQuantity), (EMA3[0] - ((ATR1[0] * Multiplier) )) , @"APBear");
                }​




    Code:
    protected override void OnBarUpdate()
            {
                if (CurrentBars[0] < BarsRequiredToTrade)
                {
                    return;
                }
                if (BarsInProgress != 0)
                    return;
    
                if (CurrentBars[0] < 1)
                    return;
    
                 // Set 1
                if (LONGENTRYCONDITION)
                {
                    Print("Entering Long Position @" + GetCurrentAsk(0));
                    EnterLong(Convert.ToInt32(DefaultQuantity), @"APBull");
    
                }
    
                if ( Position.MarketPosition == MarketPosition.Long)
                {
                    EnterLongLimit(Convert.ToInt32(DefaultQuantity), (EMA3[0] + ((ATR1[0] * Multiplier) )) , @"APBull");
                }
    
                if ( Position.MarketPosition == MarketPosition.Short)
                {
    
                    EnterShortLimit(Convert.ToInt32(DefaultQuantity), (EMA3[0] - ((ATR1[0] * Multiplier) )) , @"APBear");
                }
    
                 // Set 2
                if (SHORTENTRYCONDITION)
                {
                    Print("Entering Short Position @" + GetCurrentAsk(0));
                    EnterShort(Convert.ToInt32(DefaultQuantity), @"APBear");
                }
    
            }​

    #2
    Hello futtrader,

    It looks like if you are already long you want to place a second long limit order entry to scale in, is this correct?

    Do you have EntriesPerDirection set to 2?
    What is EntryHandling set to?



    "My intension is to Update the Limit price if it goes higher than the current limit else keep the same limit exit order."

    I'm not seeing any exit orders being called. ExitLongLimit() / ExitShortLimit would be a limit exit order for a long / short position.


    You have if (LONGENTRYCONDITION) / if (SHORTENTRYCONDITION) calling EnterLong() / EnterShort(), and this would reverse the position if the opposite was open, depending on the value of these bools.


    I see you are using some prints.

    Print the time of the bar, print all values used in the condition that triggers the order or action, include labels for each value and comparison operator.
    https://ninjatrader.com/support/foru...121#post791121

    Enable TraceOrders in State.Configure to see if any orders are being ignored, rejected, or submitted.

    Save the output from the NinjaScript Output window to a text file by right-clicking and selecting Save As.
    Attach the output text file to your next reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello futtrader,

      It looks like if you are already long you want to place a second long limit order entry to scale in, is this correct?

      Do you have EntriesPerDirection set to 2?
      What is EntryHandling set to?
      https://ninjatrader.com/support/help...rdirection.htm
      https://ninjatrader.com/support/help...ryhandling.htm

      "My intension is to Update the Limit price if it goes higher than the current limit else keep the same limit exit order."

      I'm not seeing any exit orders being called. ExitLongLimit() / ExitShortLimit would be a limit exit order for a long / short position.
      https://ninjatrader.com/support/help...d_approach.htm

      You have if (LONGENTRYCONDITION) / if (SHORTENTRYCONDITION) calling EnterLong() / EnterShort(), and this would reverse the position if the opposite was open, depending on the value of these bools.


      I see you are using some prints.

      Print the time of the bar, print all values used in the condition that triggers the order or action, include labels for each value and comparison operator.
      https://ninjatrader.com/support/foru...121#post791121

      Enable TraceOrders in State.Configure to see if any orders are being ignored, rejected, or submitted.

      Save the output from the NinjaScript Output window to a text file by right-clicking and selecting Save As.
      Attach the output text file to your next reply.


      Sorry my bad. I am trying to put the exit orders but somehow it's not hitting.


      Do you have EntriesPerDirection set to 2? No I just need exit order not the second long entry. EntriesPerDirection is set to 1 which is correct.


      You can see last order never got exited even though limit price is way below bid price.

      HTML Code:
      Current Bid Price:16944.25
      12/22/2023 4:55:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 4:55:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16943.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16946.25
      12/22/2023 5:00:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:00:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16943.75 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16958.25
      12/22/2023 5:05:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:05:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16946.75 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16953.25
      12/22/2023 5:10:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16948.00 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16956.5
      12/22/2023 5:15:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:15:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16949.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16960
      12/22/2023 5:20:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:20:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16950.75 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16963
      12/22/2023 5:25:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:25:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16952.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16962.5
      12/22/2023 5:30:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:30:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16954.00 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16955.75
      12/22/2023 5:35:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:35:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16961.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16979.5
      12/22/2023 5:40:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:40:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16970.00 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16997.75
      12/22/2023 5:45:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 5:45:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16976.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
      Current Bid Price:16984.75​



      Here is the updated code.


      Code:
              protected override void OnBarUpdate()
              {
                  if (CurrentBars[0] < BarsRequiredToTrade)
                  {
                      return;
                  }
                  if (BarsInProgress != 0)
                      return;
      
                  if (CurrentBars[0] < 1)
                      return;
      
                   // Set 1
                   if ( Position.MarketPosition != MarketPosition.Long && LONGENTRYCONDITION)
                  {
                      Print("Entering Long Position @" + GetCurrentAsk(0));
                      EnterLong(Convert.ToInt32(DefaultQuantity), @"APBull");
      
                  }
      
                  if ( Position.MarketPosition == MarketPosition.Long)
                  {
                      Print("Current Bid Price:" + GetCurrentBid(0));
                      ExitLongLimit(Convert.ToInt32(DefaultQuantity), (EMA3[0] + ((ATR1[0] * Multiplier) - 10)) , "LongTargetHit", @"APBull");
                  }
      
                  if ( Position.MarketPosition == MarketPosition.Short)
                  {
                      Print("Current Bid Price:" + GetCurrentBid(0));
                      ExitShortLimit(Convert.ToInt32(DefaultQuantity), (EMA3[0] - ((ATR1[0] * Multiplier) ) + 10),"ShortTargetHit",  @"APBear");
                  }
      
                   // Set 2
                  if ( Position.MarketPosition != MarketPosition.Short && SHORTENTRYCONDITION)
                  {
                      Print("Entering Short Position @" + GetCurrentAsk(0));
                      EnterShort(Convert.ToInt32(DefaultQuantity), @"APBear");
      
                  }
      
              }​
      Attached Files
      Last edited by futtrader; 12-22-2023, 04:55 PM.

      Comment


        #4
        Hello futtrader,

        To confirm, your inquiry now is no longer about scaling in with EnterLongLimit() but adding an exit limit as a profit target, is this correct?

        The order is being submitted, and updated to a new calculated price on each bar update, and the order has not filled, is this correct?

        In OnBarUpdate print the Time, Open, High, Low, Close, outside of any conditions.

        Print(string.Format("{0} | Open[0]: {1}, High[0]: {2}, Low[0]: {3}, Close[0]: {4}", Time[0], High[0], Low[0], Close[0]));

        In OnOrderUpdate() print the order object. (So we can see at what price an order is working, and compare this to the high / low of each new bar update)

        In OnBarUpdate() in the action block of the condition that submits the order, print the calculated price for the limit along with the bid price.
        Code:
        if ( Position.MarketPosition == MarketPosition.Long)
        {
        double longTargetHitLimitPrice = (EMA3[0] + ((ATR1[0] * Multiplier) - 10));
        Print(string.Format("{0} | GetCurrentBid(): {1} >= longTargetHitLimitPrice: {2}", Time[0], GetCurrentBid(), longTargetHitLimitPrice));
        ExitLongLimit(Convert.ToInt32(DefaultQuantity), longTargetHitLimitPrice, "LongTargetHit", @"APBull");
        }

        With the output you have provided, it does appear that the limit price of the order was never below than the last bid update. A limit sell limit order used as a profit target would need the bid price to be equal to or greater than the limit for the limit to fill.

        Current Bid Price:16962.75
        12/22/2023 1:40:00 PM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 1:40:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16990.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'

        16962.75 is not greater than 16990.50​

        Current Bid Price:16960.25
        12/22/2023 1:50:00 PM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 1:50:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16986.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'​

        16960.25 is not greater than 16986.25

        Current Bid Price:16961
        12/22/2023 1:55:00 PM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 1:55:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16984.00 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'​

        16961 is not greater than 16984.

        I'm not seeing on any of this output any place where the bid is equal to or higher than the newly updated limit price.


        Are you intending to be updating the limit to a new price on each bar update?

        If not, use isLiveUntilCancelled as true and call the ExitLongLimit() method once, and then not again.
        The ProfitChaseStopTrailExitOrdersExample here submits a limit and stop and a profit target and stop loss once when the entry fills from OnExecutionUpdate().


        Or alternatively, save the calculated limit price to a variable once, at the time of entry, and supply this variable to the exit method.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello futtrader,

          To confirm, your inquiry now is no longer about scaling in with EnterLongLimit() but adding an exit limit as a profit target, is this correct?

          The order is being submitted, and updated to a new calculated price on each bar update, and the order has not filled, is this correct?

          In OnBarUpdate print the Time, Open, High, Low, Close, outside of any conditions.

          Print(string.Format("{0} | Open[0]: {1}, High[0]: {2}, Low[0]: {3}, Close[0]: {4}", Time[0], High[0], Low[0], Close[0]));

          In OnOrderUpdate() print the order object. (So we can see at what price an order is working, and compare this to the high / low of each new bar update)

          In OnBarUpdate() in the action block of the condition that submits the order, print the calculated price for the limit along with the bid price.
          Code:
          if ( Position.MarketPosition == MarketPosition.Long)
          {
          double longTargetHitLimitPrice = (EMA3[0] + ((ATR1[0] * Multiplier) - 10));
          Print(string.Format("{0} | GetCurrentBid(): {1} >= longTargetHitLimitPrice: {2}", Time[0], GetCurrentBid(), longTargetHitLimitPrice));
          ExitLongLimit(Convert.ToInt32(DefaultQuantity), longTargetHitLimitPrice, "LongTargetHit", @"APBull");
          }

          With the output you have provided, it does appear that the limit price of the order was never below than the last bid update. A limit sell limit order used as a profit target would need the bid price to be equal to or greater than the limit for the limit to fill.

          Current Bid Price:16962.75
          12/22/2023 1:40:00 PM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 1:40:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16990.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'

          16962.75 is not greater than 16990.50​

          Current Bid Price:16960.25
          12/22/2023 1:50:00 PM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 1:50:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16986.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'​

          16960.25 is not greater than 16986.25

          Current Bid Price:16961
          12/22/2023 1:55:00 PM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 1:55:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16984.00 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'​

          16961 is not greater than 16984.

          I'm not seeing on any of this output any place where the bid is equal to or higher than the newly updated limit price.


          Are you intending to be updating the limit to a new price on each bar update?

          If not, use isLiveUntilCancelled as true and call the ExitLongLimit() method once, and then not again.
          The ProfitChaseStopTrailExitOrdersExample here submits a limit and stop and a profit target and stop loss once when the entry fills from OnExecutionUpdate().
          https://ninjatrader.com/support/foru...269#post802269

          Or alternatively, save the calculated limit price to a variable once, at the time of entry, and supply this variable to the exit method.
          https://ninjatrader.com/support/foru...596#post806596
          Thank you for your detail response.


          Here is the log with the code you have provided for the ExitLongLimit method.

          How can I do this ?

          In OnOrderUpdate() print the order object. (So we can see at what price an order is working, and compare this to the high / low of each new bar update)


          HTML Code:
          Entering Long Position @16908
          12/22/2023 12:05:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 12:05:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='APBull' FromEntrySignal=''
          12/22/2023 12:10:00 AM | Open[0]: 16908.25, High[0]: 16911.75, Low[0]: 16904, Close[0]: 16905.75
          12/22/2023 12:10:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 12:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16916.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 2:20:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 2:20:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16924.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 2:25:00 AM | Open[0]: 16920, High[0]: 16921, Low[0]: 16918.5, Close[0]: 16920.5
          12/22/2023 2:25:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 2:25:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16924.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 2:30:00 AM | Open[0]: 16920.75, High[0]: 16920.75, Low[0]: 16915.5, Close[0]: 16920
          12/22/2023 2:30:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 2:30:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16925.00 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 2:35:00 AM | Open[0]: 16920, High[0]: 16922, Low[0]: 16916.75, Close[0]: 16918.25
          12/22/2023 2:35:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 2:35:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16925.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 2:40:00 AM | Open[0]: 16918, High[0]: 16919, Low[0]: 16915.5, Close[0]: 16918.75
          12/22/2023 2:40:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 2:40:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16925.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 2:45:00 AM | Open[0]: 16918.75, High[0]: 16924.25, Low[0]: 16918.25, Close[0]: 16924.25
          12/22/2023 2:45:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 2:45:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16926.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 2:50:00 AM | Open[0]: 16924.5, High[0]: 16929, Low[0]: 16923.25, Close[0]: 16926
          12/22/2023 2:50:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 2:50:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16927.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 2:55:00 AM | Open[0]: 16926.25, High[0]: 16931.75, Low[0]: 16921.75, Close[0]: 16930
          12/22/2023 2:55:00 AM | GetCurrentBid(): 16930 >= longTargetHitLimitPrice: 16929.2635247565
          12/22/2023 2:55:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 2:55:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16929.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 3:00:00 AM | Open[0]: 16930, High[0]: 16932.75, Low[0]: 16929, Close[0]: 16932.5
          12/22/2023 3:00:00 AM | GetCurrentBid(): 16932.5 >= longTargetHitLimitPrice: 16930.2259220458
          12/22/2023 3:00:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 3:00:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16930.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 3:05:00 AM | Open[0]: 16932.25, High[0]: 16936.5, Low[0]: 16931.75, Close[0]: 16934.5
          12/22/2023 3:05:00 AM | GetCurrentBid(): 16934.5 >= longTargetHitLimitPrice: 16931.4548877962
          12/22/2023 3:05:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 3:05:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16931.50 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 3:10:00 AM | Open[0]: 16933.75, High[0]: 16935.75, Low[0]: 16931.75, Close[0]: 16933.5
          12/22/2023 3:10:00 AM | GetCurrentBid(): 16933.5 >= longTargetHitLimitPrice: 16932.3448920803
          12/22/2023 3:10:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 3:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16932.25 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull'
          12/22/2023 3:15:00 AM | Open[0]: 16934, High[0]: 16937, Low[0]: 16932.75, Close[0]: 16936
          12/22/2023 3:15:00 AM | GetCurrentBid(): 16936 >= longTargetHitLimitPrice: 16933.4210652287
          12/22/2023 3:15:00 AM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Entered internal SubmitOrderManaged() method at 12/22/2023 3:15:00 AM: BarsInPro​

          Code:
          protected override void OnBarUpdate()
                  {
                      if (CurrentBars[0] < BarsRequiredToTrade)
                      {
                          return;
                      }
                      if (BarsInProgress != 0)
                          return;
          
                      if (CurrentBars[0] < 1)
                          return;
          
                      Print(string.Format("{0} | Open[0]: {1}, High[0]: {2}, Low[0]: {3}, Close[0]: {4}", Time[0], Open[0], High[0], Low[0], Close[0]));
          
                       // Set 1
                       if (Position.MarketPosition != MarketPosition.Short && ShortEntryCondition)
                      {
                          Print("Entering Long Position @" + GetCurrentAsk(0));
                          EnterLong(Convert.ToInt32(DefaultQuantity), @"APBull");
          
                      }
          
                      if ( Position.MarketPosition == MarketPosition.Long)
                      {
          //                Print("ExitLong - Current Bid Price:" + GetCurrentBid(0));
          //                ExitLongLimit(Convert.ToInt32(DefaultQuantity), (EMA3[0] + ((ATR1[0] * Multiplier) - 10)) , "LongTargetHit", @"APBull");
                          double longTargetHitLimitPrice = (EMA3[0] + ((ATR1[0] * Multiplier) - 3));
                          if(GetCurrentBid() >= longTargetHitLimitPrice)
                          {
                              Print(string.Format("{0} | GetCurrentBid(): {1} >= longTargetHitLimitPrice: {2}", Time[0], GetCurrentBid(), longTargetHitLimitPrice));
                          }
          
                          ExitLongLimit(Convert.ToInt32(DefaultQuantity), longTargetHitLimitPrice, "LongTargetHit", @"APBull");
                      }
          
          //            if ( Position.MarketPosition == MarketPosition.Short && GetCurrentBid(0) > (EMA3[0] - ((ATR1[0] * Multiplier) + 3)))
                      if ( Position.MarketPosition == MarketPosition.Short)
                      {
          //                Print("ExitShort - Current Bid Price:" + GetCurrentBid(0));
          //                ExitShortLimit(Convert.ToInt32(DefaultQuantity), (EMA3[0] - ((ATR1[0] * Multiplier) ) + 10),"ShortTargetHit",  @"APBear");
                          double shortTargetHitLimitPrice = (EMA3[0] - ((ATR1[0] * Multiplier) - 3));
                          if (GetCurrentBid() <= shortTargetHitLimitPrice)
                          {
                              Print(string.Format("{0} | GetCurrentBid(): {1} <= shortTargetHitLimitPrice: {2}", Time[0], GetCurrentBid(), shortTargetHitLimitPrice));
                          }
                          ExitShortLimit(Convert.ToInt32(DefaultQuantity), shortTargetHitLimitPrice, "LongTargetHit", @"APBull");    
                      }
          
                       // Set 2
                      if (Position.MarketPosition != MarketPosition.Short && LongEntryCondition)
                      {
                          Print("Entering Short Position @" + GetCurrentAsk(0));
                          EnterShort(Convert.ToInt32(DefaultQuantity), @"APBear");
          
                      }
          
                  }​

          Comment


            #6
            Hello futtrader,

            Thank you for your reply.

            More information regarding OnOrderUpdate() may be found here:


            The first example on that page demonstrates how to print the order state:
            Code:
            protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                                                int quantity, int filled, double averageFillPrice,
                                                Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
            {
              Print("The most current order state is: " + order.OrderState);   // OrderState.PartFilled
              Print("This particular order update state is: " + orderState); // OrderState.Working
            }​
            To print the order object, you could print out order.ToString():
            Code:
            protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                                                int quantity, int filled, double averageFillPrice,
                                                Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
            {
            // Print out the order object
            Print(order.ToString());
            }​
            We look forward to assisting you further.

            Comment


              #7
              Thank you. Please find attached log with order object info.

              If you focus on this window.

              Start time: 12/22/2023 12:05:00 AM
              End Time: 12/22/2023 2:00:00 PM

              You will see multiple times Bid price is higher than the sell limit price.
              See message: GetCurrentBid(): XXXXX >= longTargetHitLimitPrice: XXXXX


              But one more thing I've notice is I can not see Order object get printed in for all the submitted order.


              My intension is to dynamically update the LimitOrder (Eventually StopLoss also) based on where price is going.

              Code:
              protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                                                            int quantity, int filled, double averageFillPrice,
                                                            Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
                      {
                          Print(Time[0] + " DEBUG The most current order state is: " + order.OrderState);   // OrderState.PartFilled
                           Print(Time[0] + " DEBUG This particular order update state is: " + orderState); // OrderState.Working
                          Print(order.ToString());
                      }
              
                      protected override void OnBarUpdate()
                      {
                          if (CurrentBars[0] < BarsRequiredToTrade)
                          {
                              return;
                          }
                          if (BarsInProgress != 0)
                              return;
              
                          if (CurrentBars[0] < 1)
                              return;
              
                          Print(string.Format("{0} | Open[0]: {1}, High[0]: {2}, Low[0]: {3}, Close[0]: {4}", Time[0], Open[0], High[0], Low[0], Close[0]));
              
                          bool BuyCondition = <SOME BOOL EXPRESSION>;
              
                          bool SellCondition = <SOME BOOL EXPRESSION>;
              
              
                           //Set 1 SignalPositive
                          if ( Position.MarketPosition != MarketPosition.Long && BuyCondition)
                          {
                              Print("Entering Long Position @" + GetCurrentAsk(0));
                              EnterLong(Convert.ToInt32(DefaultQuantity), @"APBull");
                          }
              
                          if ( Position.MarketPosition == MarketPosition.Long)
                          {
                              double longTargetHitLimitPrice = (EMA3[0] + ((ATR1[0] * Multiplier) - 3));
                              if(GetCurrentBid() >= longTargetHitLimitPrice)
                              {
                                  Print(string.Format("{0} | GetCurrentBid(): {1} >= longTargetHitLimitPrice: {2}", Time[0], GetCurrentBid(), longTargetHitLimitPrice));
                              }
              
                              ExitLongLimit(Convert.ToInt32(DefaultQuantity), longTargetHitLimitPrice, "LongTargetHit", @"APBull");
                          }
              
                          if ( Position.MarketPosition == MarketPosition.Short)
                          {
                              double shortTargetHitLimitPrice = (EMA3[0] - ((ATR1[0] * Multiplier) - 3));
                              if (GetCurrentBid() <= shortTargetHitLimitPrice)
                              {
                                  Print(string.Format("{0} | GetCurrentBid(): {1} <= shortTargetHitLimitPrice: {2}", Time[0], GetCurrentBid(), shortTargetHitLimitPrice));
                              }
                              ExitShortLimit(Convert.ToInt32(DefaultQuantity), shortTargetHitLimitPrice, "LongTargetHit", @"APBull");    
                          }
              
                           // Set 2
                          if ( Position.MarketPosition != MarketPosition.Short && SellCondition)
                          {
                              Print("Entering Short Position @" + GetCurrentAsk(0));
                              EnterShort(Convert.ToInt32(DefaultQuantity), @"APBear");
                          }
              
                      }
              ​
              Attached Files
              Last edited by futtrader; 12-26-2023, 12:28 AM.

              Comment


                #8
                Hello futtrader,

                I am seeing the order information in the print output.

                orderId='NT-00039-777' account='Sim101' name='APBull' orderState=Submitted instrument='NQ MAR24' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-12-22 00:05:00' gtd='2099-12-01' statementDate='2023-12-25'


                That said, I am not seeing a limit order was submitted at 12:05, but I am seeing a 'Stop loss' order was submitted.

                orderId='NT-00040-777' account='Sim101' name='Stop loss' orderState=Working instrument='NQ MAR24' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=16888.25 quantity=1 tif=Gtc oco='NT-00032-777' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-12-22 00:05:00' gtd='2099-12-01' statementDate='2023-12-25'


                It looks like the limit order may be getting ignored.

                12/11/2023 7:20:00 PM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Ignored SubmitOrderManaged() method at 12/11/2023 7:20:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16475.75 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull' Reason='An Exit() method to submit an exit order has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.'

                This may be due to using SetStopLoss() and trying to submit a limit order at the same time.

                From the help guide:
                "Methods that generate orders to exit a position will be ignored if:
                •A position is open and an order submitted by a set method (SetStopLoss() for example) is active​"


                Since the limit is not being submitted with SetProfitTarget(), may I confirm you are not violating the internal order handling rules and that you are submitting the stop loss with ExitLongStopMarket() and you are not trying to mix SetStopLoss() with ExitLongLimit()?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello futtrader,

                  I am seeing the order information in the print output.

                  orderId='NT-00039-777' account='Sim101' name='APBull' orderState=Submitted instrument='NQ MAR24' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-12-22 00:05:00' gtd='2099-12-01' statementDate='2023-12-25'


                  That said, I am not seeing a limit order was submitted at 12:05, but I am seeing a 'Stop loss' order was submitted.

                  orderId='NT-00040-777' account='Sim101' name='Stop loss' orderState=Working instrument='NQ MAR24' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=16888.25 quantity=1 tif=Gtc oco='NT-00032-777' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-12-22 00:05:00' gtd='2099-12-01' statementDate='2023-12-25'


                  It looks like the limit order may be getting ignored.

                  12/11/2023 7:20:00 PM Strategy 'EEdgeAPlusSetupUnlocked/312501222': Ignored SubmitOrderManaged() method at 12/11/2023 7:20:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=16475.75 StopPrice=0 SignalName='LongTargetHit' FromEntrySignal='APBull' Reason='An Exit() method to submit an exit order has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.'

                  This may be due to using SetStopLoss() and trying to submit a limit order at the same time.

                  From the help guide:
                  "Methods that generate orders to exit a position will be ignored if:
                  •A position is open and an order submitted by a set method (SetStopLoss() for example) is active​"


                  Since the limit is not being submitted with SetProfitTarget(), may I confirm you are not violating the internal order handling rules and that you are submitting the stop loss with ExitLongStopMarket() and you are not trying to mix SetStopLoss() with ExitLongLimit()?
                  The link that you shared is not working and yes I am using SetStopLoss inside if (State == State.DataLoaded)

                  Would you be able to provide the example that I can adjust my Limit Price and StopLoss on every bar or each Price change ?

                  Comment


                    #10
                    Hello futtrader,

                    The link is correct, but there is a tracker causing malformed urls on the forum. Using the uBlock origin browser extension can prevent this.

                    The help guide I am linking is in NinjaScript > Language Reference > Strategy > Order Methods > Managed Approach > Internal Order Handling Rules that Reduce Unwanted Positions.
                    The text of the link is below.
                    Don't use SetStopLoss() if you plan to use ExitLongLimit() as this violates the internal order handling rules.
                    Use ExitLongStopMarket() / ExitShortStopMarket() instead.

                    Below is a link to an example 'ProfitChaseStopTrailExitOrdersExample' of an adjusted stop and target.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello futtrader,

                      The link is correct, but there is a tracker causing malformed urls on the forum. Using the uBlock origin browser extension can prevent this.

                      The help guide I am linking is in NinjaScript > Language Reference > Strategy > Order Methods > Managed Approach > Internal Order Handling Rules that Reduce Unwanted Positions.
                      The text of the link is below.


                      Don't use SetStopLoss() if you plan to use ExitLongLimit() as this violates the internal order handling rules.
                      Use ExitLongStopMarket() / ExitShortStopMarket() instead.

                      Below is a link to an example 'ProfitChaseStopTrailExitOrdersExample' of an adjusted stop and target.
                      https://ninjatrader.com/support/foru...269#post802269
                      Not Sure where this strategy - ProfitChaseStopTrailExitOrdersExample is tested but enabling for 5 days for NQ Mar 24 takes 2-3 minute to load in chart. I am first trying to understand how this work and then may be import my code here or export it. But it would be great if Strategy is created with some Entry logic like MACrossOver or SMA and guide how to enable this to debug.

                      Set

                      Comment


                        #12
                        Hello futtrader,

                        The initial stop and limit are submitted in OnExecutionUpdate() on lines 227and 237. These orders are assigned to variables on lines 249, 96, and 99.
                        Once the orders are submitted and working and assigned to a variable, they can be modified on lines 149 and 203.

                        The exits can apply to any entries in any entry conditions.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NullPointStrategies, Today, 05:17 AM
                        0 responses
                        53 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