Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Which trade first?

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

    Which trade first?

    Hello,

    when I have in my coding eg 2 setups and both setups with conditions are true but only one entry should be realized - how can I do this when having for each trade setup referring names (L1, L2, S1, S2) and stops. Of course I can avoid both entries at same time by entry-handling and having same name for the entries - but then I can not distinguish which trade is realized (I could with eg background color of course) but for further reasons (like tradecounter) I need to have seperate names for the entries.

    Thanks
    Tony

    #2
    Hello tonynt,
    You can check for the current MarketPosition before you shoot an order like,

    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
    {
      //place entry order
    }
    The above code checks that if you are flat then only you place an order.

    Let me know if it resolves your issue.

    Regards,
    Joydeep.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hello,

      thanks for your reply. Of course I do this but the entries occur same moment of time. I have UniqueEntries and EntriesPerDirection1. But there are sometimes 2 entries - 1 entry per setup (as it can happen that both setups are true in some market situation) but only 1 entry should be realized)


      Please see attached jpg (setup1 = trade S1A and S2A and setup2 = S1B and S2B but only 1 trade with 2 positions should be done and not 2 trades with 4 positions). How can I do this please?

      Thanks
      Tony

      Originally posted by NinjaTrader_Joydeep View Post
      Hello tonynt,
      You can check for the current MarketPosition before you shoot an order like,

      Code:
      if (Position.MarketPosition == MarketPosition.Flat)
      {
        //place entry order
      }
      The above code checks that if you are flat then only you place an order.

      Let me know if it resolves your issue.

      Regards,
      Joydeep.
      Attached Files
      Last edited by tonynt; 12-14-2011, 06:36 AM. Reason: clearify

      Comment


        #4
        Hello tonynt,
        In such scenario, you can use a bool internally in your code which will let you know that you are in a trade. Like,

        in variable,
        Code:
        private bool isInTrade = false;
        in OnBarUpdate
        Code:
        if (condition && Position.MarketPosition == MarketPosition.Flat && isInTrade == false)
        {
          //shoot entry order
          //set the bool to true so that no further order takes place
          isInTrade = true;
        }
        do remember to set the isInTrade to false when the trade gets squared off or if the entry order gets rejected/cancelled.

        Let me know if I can be of any further help.

        Regards,
        Joydeep.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thanks, this should work.

          But what do you mean please with set isInTrade to false? How can I do this in an automated strategy (I think with maybe barssinceentry()... or even when flat? Or do you mean other way?

          Thanks
          Tony

          Originally posted by NinjaTrader_Joydeep View Post
          Hello tonynt,
          In such scenario, you can use a bool internally in your code which will let you know that you are in a trade. Like,

          in variable,
          Code:
          private bool isInTrade = false;
          in OnBarUpdate
          Code:
          if (condition && Position.MarketPosition == MarketPosition.Flat && isInTrade == false)
          {
            //shoot entry order
            //set the bool to true so that no further order takes place
            isInTrade = true;
          }
          do remember to set the isInTrade to false when the trade gets squared off or if the entry order gets rejected/cancelled.

          Let me know if I can be of any further help.

          Regards,
          Joydeep.
          Last edited by tonynt; 12-14-2011, 07:04 AM. Reason: wrong questioned in english

          Comment


            #6
            Hello tonynt,
            In OnExecution or OnOrderUpdate event you can reassign the value of isInTrade.

            like
            protected override void OnExecution(IExecution execution)
            {
            if (Position.MarketPosition == MarketPosition.Flat)
            isInTrade = false;
            }

            I am giving some basic ideas, feel free to experiment around.

            Let me know if I can be of any further help.

            Regards,
            Joydeep.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Thank you,

              this is what I have done in the meantime in OnOrderUpdate... if flat... variable=false

              It works.

              Thank you for the accurate support.

              Best regards
              Tony

              and
              Originally posted by NinjaTrader_Joydeep View Post
              Hello tonynt,
              In OnExecution or OnOrderUpdate event you can reassign the value of isInTrade.

              like
              protected override void OnExecution(IExecution execution)
              {
              if (Position.MarketPosition == MarketPosition.Flat)
              isInTrade = false;
              }

              I am giving some basic ideas, feel free to experiment around.

              Let me know if I can be of any further help.

              Regards,
              Joydeep.

              Comment


                #8
                Hello tonynt,
                Glad it resolved your issue. Happy trading.

                Regards,
                Joydeep.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  When I do complete now my strategies I want to add this question in concern:

                  I do 2 entries with script and 1 entry with charttrader-atm. To avoid all this we corresponded above (variables, orderstate..) is it possible to call the 3rd position in my script-strat with

                  if(orderId.Length == 0 && atmStrategyId.Length == 0
                  && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat
                  && Position.MarketPosition != MarketPosition.Flat

                  // so that the atm is realized when not flat in the script(this to avoid all the setups for the atm again) or how could I realize my 3rd position from atm easily?

                  (Because when I do so I can check one instrument, but when I check in the strategy-tab another instrument this is unchecked from Ninja immediately)

                  Then I´ll have got everything I need.

                  Thanks
                  Tony


                  Originally posted by NinjaTrader_Joydeep View Post
                  Hello tonynt,
                  Glad it resolved your issue. Happy trading.

                  Regards,
                  Joydeep.
                  Last edited by tonynt; 12-14-2011, 07:45 AM. Reason: typing error

                  Comment


                    #10
                    Hello tonynt,
                    You can do it, but do remember Managed order and Atm orders differs fundamentally. Atm orders cannot access the OnExecution etc events. So it will be very complex if you mix the two.

                    Also the code snippet you sent there is an error. if atmStrategyId's length is 0 (zero) then its futile to call the GetAtmStrategyMarketPosition, as no unique id exists (atmStrategyId = string.empty). Do take care on that. Also you have to take into account of the isInTrade bool.

                    Originally posted by tonynt View Post
                    if(orderId.Length == 0 && atmStrategyId.Length == 0
                    && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat
                    && Position.MarketPosition != MarketPosition.Flat
                    Do let me know if I can be of any further help.

                    Regards,
                    Joydeep.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Yes, sorry, this was futile to add the GetAtmStrategyMarketPosition. (also the uncheck issue was because I didn´t have historical, return - because of the atm)

                      I do already mix the 2 without problems - and even I start the strategies with customized buttons which I could do with the great support also from members here.

                      The only question now is because of the tradecounter for the atm-section in my strategy and therefore I want to ask if in my script-strat I can call the atm-position/atm-trade with (to avoid all duplicate conditions and tradecounting which I don´t need as the only "condition" for the atm is when not flat in script)

                      if(orderId.Length == 0 && atmStrategyId.Length == 0
                      && Position.MarketPosition != MarketPosition.Flat)

                      Thanks
                      Tony


                      Originally posted by NinjaTrader_Joydeep View Post
                      Hello tonynt,
                      You can do it, but do remember Managed order and Atm orders differs fundamentally. Atm orders cannot access the OnExecution etc events. So it will be very complex if you mix the two.

                      Also the code snippet you sent there is an error. if atmStrategyId's length is 0 (zero) then its futile to call the GetAtmStrategyMarketPosition, as no unique id exists (atmStrategyId = string.empty). Do take care on that. Also you have to take into account of the isInTrade bool.



                      Do let me know if I can be of any further help.

                      Regards,
                      Joydeep.
                      Last edited by tonynt; 12-14-2011, 08:36 AM. Reason: clearify, typing error english

                      Comment


                        #12
                        Hello tonynt,
                        Positions would return the results for the Managed order entries and not the atm orders. For accessing the info regarding the atm orders you have to use the atm functions. Do visit the below page for more info on atm functions http://www.ninjatrader.com/support/h...gy_methods.htm

                        Mixing the two is not an issue, besides being the strategy becoming too complex.

                        Let me know if I can be of any further help.

                        Regards,
                        Joydeep.
                        JoydeepNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by michi08, 10-05-2018, 09:31 AM
                        3 responses
                        740 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by sightcareclickhere, Today, 01:55 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post sightcareclickhere  
                        Started by Mindset, 05-06-2023, 09:03 PM
                        9 responses
                        258 views
                        0 likes
                        Last Post ender_wiggum  
                        Started by Mizzouman1, Today, 07:35 AM
                        4 responses
                        18 views
                        0 likes
                        Last Post Mizzouman1  
                        Started by philmg, Today, 01:17 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_ChristopherJ  
                        Working...
                        X