Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is the difference?

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

    What is the difference?

    if(account.Positions[0].MarketPosition == MarketPosition.Long)
    if(Position.MarketPosition == MarketPosition.Long)

    I get that one uses Position Info and the other uses Account position info but I am using them when pressing buttons and the bottom line gives an obj instance error which I don't understand as it merely determines whether or not we have a long position.

    Can someone explain what I am missing here?
    Edit - I should add that I am instantiating an order on the press of this button.

    #2
    Hello Mindset,

    Thank you for your post.

    The difference is that with account.Positions you are checking a collection of positions on the account, while Postion.MarketPosition is specifically checking the strategy's position. Strategy and account positions are separate.

    Are you submitting orders directly to the account (i.e. using account.Submit), or are you submitting orders via managed or unmanaged approach methods?

    What is the full error message you are getting? Which line specifically is throwing the error?
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hi Gaby
      Excuse me for asking a dumb question but even in the Positions.Collection surely the condition am I long is true?
      I am using the managed approach for orders and the situation is resolved by using line 1 instead of line 2.
      Let me use try catch and see if I can get the line that is throwing the error

      Comment


        #4
        Hello Mindset,

        Excuse me for asking a dumb question but even in the Positions.Collection surely the condition am I long is true?
        This may or may not be the case. Since strategy and account positions are not the same, it is possible for your strategy to be long but your account to be short or flat. If you are running other strategies on the same account, or placing manual orders to the account, then this would cause the positions to not match.

        Please let me know when you identify which line in particular is triggering the error.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Thanks for that clarification. Running the strategy last couple of days and all is currently working fine. Still a little unclear if with a single strategy running ( it's actually just an entry order and trade management system for discretionary trading in reality) if I should use
          if(account.Positions[0].MarketPosition == MarketPosition.Long)
          or
          if(Position.MarketPosition == MarketPosition.Long)

          I have come across situations where I get object instance errors with one but not the other - which doesn't make sense to me as the account and the strategy must by definition be in the same marketposition??

          Comment


            #6
            Hello Mindset,

            If you are just wanting to track the account position of your particular strategy instance then I would recommend use Position.MarketPosition.

            " the account and the strategy must by definition be in the same marketposition??"

            This is not true, as mentioned before strategy position and account position are not the same.



            If you're hitting an object reference error, I recommend debugging the script using prints and providing the output so we can analyze why you're hitting that error.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              Thanks Gaby.
              Not beating a dead horse but I am only wanting to simply question if I am long or short - doesn't matter if it's 1 contract or 5. So again how can account position and strategy position be different in that respect? Could you give me the scenario where account and strategy would be different??
              But moving on - I am not getting any obj instance errors now I have changed to your above suggestion but I will keep an eye on it of course ;-).
              But thank you for the discourse and I am only trying to understand this rather than being difficult.

              Comment


                #8
                Hello Mindset,

                No worries. The link I provided in my last reply contains an example of when your account position would not match your strategy's position.

                Gaby V.NinjaTrader Customer Service

                Comment


                  #9
                  Ah thank you - I get it now. :-)

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Pointtoni, Yesterday, 11:41 PM
                  3 responses
                  23 views
                  0 likes
                  Last Post jenacie.com  
                  Started by DayTradingDEMON, Yesterday, 02:10 PM
                  5 responses
                  29 views
                  0 likes
                  Last Post DayTradingDEMON  
                  Started by Nate G, 03-17-2025, 02:53 PM
                  4 responses
                  59 views
                  1 like
                  Last Post timko
                  by timko
                   
                  Started by several, 03-18-2025, 03:53 AM
                  11 responses
                  175 views
                  1 like
                  Last Post timko
                  by timko
                   
                  Started by Amelie4262, Today, 10:45 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post Amelie4262  
                  Working...
                  X