Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position.MarketPosition == MarketPosition.Flat

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

    Position.MarketPosition == MarketPosition.Flat

    I am switching code from atms to unmanaged and the new code works fine except for the following:

    if the code puts me in a position with a stop in place and I manually exit the position by placing a market order... then manually cancel the stop order...I am flat

    however, Position.MarketPosition == MarketPosition.Flat code does not pick up the fact that the account is flat.

    what am I missing?

    does Position.MarketPosition == MarketPosition.Flat not refer to the account status and not just order status?

    #2
    Hello ATI user,

    Thanks for your note.

    The Position.MarketPosition reflects the orders particular to that instance of that strategy. It does not reflect all positions across the account, or other instances of the same strategy using the same account.


    Please let me know if I can be of any further assistance.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ok thanks....so... to confirm the account is flat I would use ??

      how about

      protected override void OnPositionUpdate(IPosition position)
      {
      if (position.MarketPosition == MarketPosition.Flat)
      {
      // Do something like reset some variables here
      }
      }

      no that does not work either...

      what does code confirm acct is flat unrelated to orders or strategy?
      Last edited by ATI user; 03-05-2013, 12:01 PM.

      Comment


        #4
        Hi ATI user,

        An unsupported way would be to use the following:

        Code:
        Cbi.Position myPosition = Account.Positions.FindByInstrument(Instrument);
        if (myPosition == null)
        return;
        Print(myPosition.MarketPosition.ToString());
        This will print the MarketPosition of the account.
        If there are no positions in the account myPosition will be null.

        Below is a link to a similar forum post where this is discussed.
        http://www.ninjatrader.com/support/f...ad.php?t=28306


        Please let me know if I can be of further assistance.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          could not get that code to compile

          Comment


            #6
            Hello ATI user,

            This code will only compile in a strategy as this usage of Account.Positions is available to strategies.

            If you have this code in a strategy file and are still getting compile errors, please take a screenshot of the compile errors and send them to our support address.

            Please ensure the errors column is fully expanded so that I can see the full error message. You can expand the error column by clicking and dragging on the small line separating the column labels at the top of the errors area.

            Once you have the screenshot, please send it as an attachment to support[at]ninjatrader[dot]com.


            Let me know if I can still be of assistance.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            673 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            577 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X