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

Position.MarketPosition == MarketPosition.Flat not working

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

    Position.MarketPosition == MarketPosition.Flat not working


    I would like to place orders only when my current position is flat.
    I am using the below condition for that.
    Position.MarketPosition == MarketPosition.Flat

    I am using the ATMstrategy template names to place the orders within my strategy.

    The strategy places the trade even though I am currently in a position.
    Please help.




    #2
    Have you studied the SampleAtmStrategy provided as an example by Ninjatrader? It is all there.

    Comment


      #3
      Hello pvincent,

      When using ATM's you cannot use any of the strategy based properties or methods like strategy position. you can use the methods shown here with ATM's: https://ninjatrader.com/support/help...gy_methods.htm

      You can use the SampleATMStrategy as a starting point, that shows how you can limit to a single entry at a time.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Can I use PositionAccount.MarketPosition == MarketPosition.Flat

        Comment


          #5
          Hello pvincent,

          No, that is for a strategy based position. ATM's are external to a NinjaScript strategy so it can only use the methods in the link I had provided.

          JesseNinjaTrader Customer Service

          Comment


            #6
            Thank you.

            Comment


              #7
              Originally posted by trendisyourfriend View Post
              Have you studied the SampleAtmStrategy provided as an example by Ninjatrader? It is all there.
              Can you send me the screenshot where in the SampleAtmStrategy is checking for current position as flat before placing the order?
              Last edited by pvincent; 03-25-2022, 03:11 PM.

              Comment


                #8
                Hello pvincent,

                The sample does not check the position at all, it uses the ID variable for the strategy to check if that is populated or not. That would be lines 59 and 76 in the sample. The sample sets the order ID back to empty when the atm is not present: orderId = string.Empty;

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello pvincent,

                  No, that is for a strategy based position. ATM's are external to a NinjaScript strategy so it can only use the methods in the link I had provided.
                  Hi Jesse,

                  I would like to check whether my current position is flat before placing an order using the ATMstrategy.
                  For example, I have a trigger and order was placed for a buy.
                  Now, I get a second trigger but I am already long, so I don't want to place the new trade.


                  Comment


                    #10
                    Hello pvincent,

                    You would need to use the order id variable for that, the ATM does not work like a strategy which has a position variable. The ATM is an external strategy so you need to use the means shown in the sample if you mean to limit the atm to be submitted once. It does not matter if the position is long or short, the order id variable being populated means there is an active ATM so the entry logic is ignored.

                    The alternative is to use GetAtmStrategyPositionQuantity() or GetAtmStrategyEntryOrderStatus() to check if the entry was filled however you still need the exact same code from the sample to do that and to prevent any other entries from being submitted before you can check. The sample logic is really the besst way to handle submitting a single ATM until its complete and then resetting.
                    JesseNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by mishhh, 05-25-2010, 08:54 AM
                    19 responses
                    6,189 views
                    0 likes
                    Last Post rene69851  
                    Started by gwenael, Today, 09:29 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post gwenael
                    by gwenael
                     
                    Started by Karado58, 11-26-2012, 02:57 PM
                    8 responses
                    14,830 views
                    0 likes
                    Last Post Option Whisperer  
                    Started by Option Whisperer, Today, 09:05 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post Option Whisperer  
                    Started by cre8able, Yesterday, 01:16 PM
                    3 responses
                    11 views
                    0 likes
                    Last Post cre8able  
                    Working...
                    X