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

how to test for position flat in OnBarUpdate

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

    how to test for position flat in OnBarUpdate

    the help system has this snippet

    protected override void OnBarUpdate()
    {
    // If not flat print our open PnL
    if (PositionAccount.MarketPosition != MarketPosition.Flat)
    Print("Open PnL: " + PositionAccount.GetUnrealizedProfitLoss(Performanc eUnit.Points, Close[0]));
    }

    but I get a compile error...
    The name 'PositionAccount' does not exist in the current context

    how to fix?

    thx
    ​​

    #2
    Hello llanqui,

    Thank you for your post.

    Is this an indicator? If so, please note that PositionAccount is not available. This is something only available to strategies.

    To get position info from an indicator, you can use the Account class using Add On.

    Account - https://ninjatrader.com/support/help...ount_class.htm

    Positions - https://ninjatrader.com/support/help...ns_account.htm

    Please let me know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      yes, an indicator...thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by KonAdams, Today, 10:53 PM
      0 responses
      4 views
      0 likes
      Last Post KonAdams  
      Started by JGriff5646, Today, 10:02 PM
      0 responses
      11 views
      0 likes
      Last Post JGriff5646  
      Started by AdamDJ8, Today, 09:18 PM
      0 responses
      5 views
      0 likes
      Last Post AdamDJ8
      by AdamDJ8
       
      Started by knowmad, Today, 03:52 AM
      2 responses
      34 views
      0 likes
      Last Post knowmad
      by knowmad
       
      Started by ETFVoyageur, Today, 07:05 PM
      0 responses
      11 views
      0 likes
      Last Post ETFVoyageur  
      Working...
      X