Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

using EnterShortLimit and EnterLongLimit together

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

    using EnterShortLimit and EnterLongLimit together

    Hello

    Code in OnBarUpdate():

    if( some condition )
    EnterLongLimit(buyPrice, "long" );
    else
    EnterShortLimit(sellPrice, "short" );

    Some of the orders are (randomly?) ignored. I get the message:

    Strategy '...': An Enter() method to submit an entry order at '2/1/2018 12:00:00 PM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.

    Calculate is set to Calculate.OnBarClose.
    Why are the orders ignored?



    #2
    Hello StasV,

    Thanks for your post and welcome to the NinjaTrader forums.

    In the "managed approach" there are specific rules to prevent unwanted positions. You would need to review these rules in the context of your strategy coding.
    Please see, "Internal Order Handling Rules that Reduce Unwanted Positions" on this page: https://ninjatrader.com/support/help...d_approach.htm

    Comment


      #3
      I do not submit two orders in opposite directions simultaneously. For each bar, I submit either one or another depending on the condition.
      In other words, if the condition is true, I submit EnterLongLimit, otherwise I submit EnterShortLimit. On bar close the order is cancelled. For the next bar another order is opened depending on teh condition. There is no violation of your rules. Why doesn't the code work?

      Comment


        #4
        Hello StasV,

        Thanks for your reply.

        There is not enough information provided to answer.

        Please post your complete code.

        Alternatively, if you prefer not to show publicly, please feel free to send into PlatformSupport[at]NinjaTrader[dot]Com
        Mark the e-mail Atten: Paul, ticket# 2260719 and include a link to this thread for reference as well as the source code file found in Documents>Ninjatrader8>bin>Custom>Strategies> and will have the same name as the strategy and would be a CS file type.

        Comment


          #5
          protected override void OnBarUpdate()
          {

          if(Position.MarketPosition == MarketPosition.Flat)
          {
          if( Close[0] < Close[5])
          EnterLongLimit(Close[0] - Threshold, "long" );
          else
          EnterShortLimit(Close[0] + Threshold, "short" );

          }
          }

          Comment


            #6
            Hello StasV,

            Thanks for your reply.

            Are you using any Set methods in your code in OnStateChange()? (SetProfitTarget, SetStopLoss, SettrailStop)?

            Are you certain the error you are seeing is for the strategy code you are presenting?

            Comment


              #7
              protected override void OnBarUpdate()
              {

              if(Position.MarketPosition == MarketPosition.Flat)
              {
              if( Close[0] < Close[5])
              EnterLongLimit(Close[0] - Threshold, "long" );
              else
              EnterShortLimit(Close[0] + Threshold, "short" );
              }

              if(Position.MarketPosition == MarketPosition.Long)
              {
              SetProfitTarget("long", CalculationMode.Price, TakePriceLong );
              SetStopLoss("long", CalculationMode.Ticks, StopLoss, false );
              }

              if(Position.MarketPosition == MarketPosition.Short)
              {
              SetProfitTarget("short", CalculationMode.Price, TakePriceShort );
              SetStopLoss("short", CalculationMode.Ticks, StopLoss, false );
              }

              }

              At every moment either long or short orders are given. Never both orders are given. There should be no conflict. Still the code does not work.

              Comment


                #8
                Hello StasV,

                Thanks for your reply.

                Based on the limit code provided I reconstructed (using fixed values for your variables and tick setting for setprofittaregt, check for currentBar < 5 and using wait until flat start behavior) and the strategy runs without issues when tested on ES 09-19 1 minute bars.

                The only conflict I can see with your code is that you are not setting your Profit Target to a known value when flat. The Set methods will retain that last value applied and as soon as an entry order is filled the set method with that last value applied will be automatically used. As your stop value is in ticks, likely you would not have an issue. For further information on the SetProfitTarget , please review the "tips" in the help guide page here: https://ninjatrader.com/support/help...ofittarget.htm

                I would suggest set your profit target in ticks when flat as an "initial" value and then when the entry order is filled and the position is updated your set profit order can then readjust to the price you have selected. Note: When using CalculationMode.ticks in the set methods, the tick value will be added or subtracted automatically according to the entry direction so you do not need to know the entry direction first.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                52 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
                48 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X