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

MarketPosition.Flat

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

    MarketPosition.Flat

    Question 1 : my strategy executes multi trades on the same bar,so in strategy builder I set condition of Bars Since Exit > 2 , it executes no trades. bars in progress untouched.
    Question 2 : I have a same strategy running on eur.usd 10 seconds and 30 seconds time frame , i set (Position.MarketPosition = MarketPosition.Flat) in strategy builder, but the second strategy still open new trades.​

    #2
    1) Setting the condition: (Bars Since Exit > 2) the very first trade cannot initiate.
    Try this: (Bars Since Exit > 2) OR (Bars Since Exit == -1)
    2) Setting the condition: (Position.MarketPosition = MarketPosition.Flat) should wait for your position to get flat before initiate a new trade. That's ok.
    Check again your other conditions. Also check the setting "If Any" or "If All" in your Conditions panel.
    Last edited by KonstantinosNT; 03-09-2023, 07:16 AM.

    Comment


      #3
      Hello Bill, thanks for writing in. I agree with Konstantinos, the first question your likely never getting an initial entry order. and question 2 the MarketPosition object is only reading Strategy position, not the Account position, see Strategy Position vs Account Position. It's generally not recommended to run two strategies on the same instrument and on the same account since they have the possibility of trading against each other (one goes long and the other goes short) and they are not aware of each others position in the market.
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        hello, in strategy builder I tried (BarsSinceExitExecution(0, "", 0) > 2)) and (BarsSinceExitExecution(0, "", 0) == -1))​ still unable open trade .

        Comment


          #5
          Originally posted by KonstantinosNT View Post
          1) Setting the condition: (Bars Since Exit > 2) the very first trade cannot initiate.
          Try this: (Bars Since Exit > 2) OR (Bars Since Exit == -1)
          2) Setting the condition: (Position.MarketPosition = MarketPosition.Flat) should wait for your position to get flat before initiate a new trade. That's ok.
          Check again your other conditions. Also check the setting "If Any" or "If All" in your Conditions panel.
          Look again what I wrote: Use OR , not AND.

          Comment


            #6
            HI i have a similar issue where in my strategy right when i enable it it takes two trades based on two different strategies.. I went to strategy builder and generated this example from above. Do those two lines should fix my issue?
            And also . what is the purpose of last line CrossoverDetected = false? Should i include it in my strategy too?
            And I have && Position.MarketPosition == MarketPosition.Flat also but its part of the time filter clause. Should Market position be included as part of entry logic?
            I have marketposition clause
            thank you

            if ((CrossoverDetected == true)
            && ((CrossoverBar[5] - (CurrentBars[0])) == -5)
            && (BarsSinceExitExecution(0, "", 0) > 2)
            && (BarsSinceExitExecution(0, "", 0) == -1))
            {
            EnterLong(Convert.ToInt32(DefaultQuantity), "");
            CrossoverDetected = false;
            }​
            Last edited by tkaboris; 03-09-2023, 10:58 AM.

            Comment


              #7
              Hi, In both cases, you will need to use
              (BarsSinceExitExecution(0, "", 0) > 2)
              || (BarsSinceExitExecution(0, "", 0) == -1)​ //Not &&

              To create this, make a new condition group and use If Any instead of If All, then use that group along with the Crossover conditions using If All.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                I have a same strategy running on eur.usd 10 seconds and 30 seconds time frame , i set PositionAccount.MarketPosition == MarketPosition.Flat,but the 2 strategies open positions at same time

                Comment


                  #9
                  Hi Bill, I explained why this happens in Post # 3 The strategy needs access to PositionAccount instead, unfortunately, this is not available in the builder it would need to be unlocked to read the PositionAccount object:

                  https://ninjatrader.com/support/help...onaccount_quan tity.htm

                  Kind regards,
                  -ChrisL​
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello ,
                    I set PositionAccount.Quantity == 0 , still have the issue.
                    one more question : how to use multiple time frame strategy ? when I click strategies tab then open new multiple time frame strategy , you can only select 1 time frame , how to select 2 or more time frame ?
                    Last edited by bill2023; 03-10-2023, 02:42 AM.

                    Comment


                      #11
                      Hi, thanks for the follow up. You may use Print() on these values to debug your script:

                      Print(PositionAccount.MarketPosition);
                      Print(PositionAccount.Quantity);

                      To add another data series to your script you can do this through the Additional Data screen. We also have a guide on multi time frame scripts here:

                      Chris L.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by llanqui, Today, 03:53 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post llanqui
                      by llanqui
                       
                      Started by burtoninlondon, Today, 12:38 AM
                      0 responses
                      10 views
                      0 likes
                      Last Post burtoninlondon  
                      Started by AaronKoRn, Yesterday, 09:49 PM
                      0 responses
                      15 views
                      0 likes
                      Last Post AaronKoRn  
                      Started by carnitron, Yesterday, 08:42 PM
                      0 responses
                      11 views
                      0 likes
                      Last Post carnitron  
                      Started by strategist007, Yesterday, 07:51 PM
                      0 responses
                      14 views
                      0 likes
                      Last Post strategist007  
                      Working...
                      X