Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order issue

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

    Order issue

    Simple question:

    I have two types of orders, A and B.

    A will Exit A or B and Enter A.
    B can only Exit A and Open B.

    I've tried working with VariableX (set to value 0 or 1 when entering A or B) combined with If VariableX == 1 or 0, in order to identify an open A or open B position but this does not work.

    Any suggestions?

    Many thanks,

    Michael

    #2
    Hello,

    If I understand you correctly you are trying to create/use OCO (One cancels other) functionality?


    If this is the case you will need to use the Unmanaged approach to manage your orders: http://www.ninjatrader.com/support/h...d_approach.htm

    However depending on your goal there may be another way to go about coding your strategy.

    Could you please clarify which order types you are using and how you wish to manage them.

    I look forward to assisting you further.
    LanceNinjaTrader Customer Service

    Comment


      #3
      It is more basic:
      if (CrossAbove(IndicatorX,0,1))
      {
      ExitShort("","")
      EnterLong("","")
      }
      And the other way around for CrossBelow.
      Then if (IndicatorX > 0,9) { ExitLong("","") and ExitShort("","")}
      With this set-up there are moments where Position.Quantity == 0. What I try to code is that with the second if-statement every Exit signal is followed by an ONE opposite Entry signal, resulting in a position.quantity always => 1. This one position is then held untill the first if-statement is hit. It is like 1 trade connecting the two ends.
      I thought this would have been a quick fix, but I'm unsuccessful using Variable0/Variable1 as a dummy variable.

      Thanks

      Michael

      Comment


        #4
        Hello,

        You will also want to make sure you are checking the current market position.

        Example of how you might consider doing this
        Code:
         if (Position.MarketPosition == MarketPosition.Long)
                        {
                            ExitLong();
                            EnterShort();                    
                        }
        else if (Position.MarketPosition == MarketPosition.Short)
                        {
                            ExitShort();
                            EnterLong();
                        }
        http://www.ninjatrader.com/support/h...etposition.htm

        If orders are not being triggered at all please ensure your CrossAbove/below condition is being met. It may also be that your initial trade is not being triggered properly.

        You would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

        If you would like me to take a closer look please attach your source code.

        Let me know if I can be of further assistance.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Checking MarketPosition fixed the problem!
          Superb assistance, as always
          Many thanks!
          Michael

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 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
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X