Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Long or short with the same entry condition always enters long why?

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

    Long or short with the same entry condition always enters long why?

    Hi. Excuse my English. Thank you for your time.
    I use this code:

    if (entryOrder == null && logica == true)
    {

    entryOrder = EnterLongStop(Convert.ToInt32(DefaultQuantity),Hig h[0] + TickSize*2,"Long"+ CurrentBar);
    entryOrder = EnterShortStop(Convert.ToInt32(DefaultQuantity),Lo w[0] - TickSize*2,"Short"+ CurrentBar);

    }

    The input logic is the same for long and short:

    Volume[0]>Volume[1]

    always execute the long order first.
    Why if sometimes first there is the condition to enter short?
    thank you.

    #2
    Hello julifro,

    Thanks for your post.

    Unless otherwise specified, a strategy will use the "Managed approach". From the help guide, "The Managed approach in NinjaScript is the most commonly used approach because of the ease-of-use it has to offer. The order methods are wrapped with an invisible convenience layer that allows you to focus on your system's trading rules leaving the underlying mechanics of order management and the relationships between entry and exit orders and positions to NinjaTrader. "

    The Managed approach has "Internal Order Handling Rules that Reduce Unwanted Positions". Using two orders to enter in the opposite direction violates one of the rules. Here are the details, "Methods that generate orders to enter a position will be ignored if:" (and the applicable rule here is), "The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction". In your code, EngterLongStop() is the first order and would be accepted.

    The 2nd order will always be ignored. If you reverse the order and place the short order first you would then see that the long order is ignored. If you look at the "log" tab of the control center you would likely see an error message about ignored orders and to see the managed approach section of the help guide. Here is the full link for your review: https://ninjatrader.com/support/help...d_approach.htm

    What you would need to do is rework your logic so that only one or the other order is placed, for example:

    if (Condition-A)
    {
    EnterlongStop(...);
    }
    else if (Condition-B)
    {
    EnterShortStop(...);
    }


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.
      I have put the code as indicated and it keeps going in first long.
      The condition is the same for both long and short. It goes long if the price closes above the bar and short if it closes below the bar.
      If the first entry of the day should be short it ignores it and makes the first entry always long.

      if (entryOrder == null && logica == true)
      {

      entryOrder = EnterLongStop(Convert.ToInt32(DefaultQuantity),Hig h[0] + TickSize*2,"Long"+ CurrentBar);

      }

      else if (entryOrder == null && logica == true)
      {
      entryOrder = EnterShortStop(Convert.ToInt32(DefaultQuantity),Lo w[0] - TickSize*2,"Short"+ CurrentBar);
      }

      Comment


        #4
        Hello julifro,

        Thanks for your reply.

        Using the same conditions for both is the same as what you had originally posted and so the results would be expected to be the same, which you have verified. In summary, you cannot place a long and short entry order at the same time as only the first one will be used.

        You would need to rewrite your entry conditions to monitor price and if the price exceeds a value for a long, then place a long entry order. If the price goes down instead, then place a short order.


        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Okay. Thanks for the clarification. Now it works. It's really complicated to have the mind of a programmer. You are special people. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by helpwanted, Today, 03:06 AM
          1 response
          16 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          11 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          6 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          244 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          387 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X