Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PositionAccount showing 2 values

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

    PositionAccount showing 2 values

    Hi All,
    Im trying to get the unrealized profit from a position with the below code.
    From my understanding in the help guide this should only show the position for the instrument and account the strategy is run on.
    However when running the below i see 2 values, so the end result is its always zero so cant use this, i thought i would only see one value of the current position?
    Where am i going wrong?

    Code:
    unRealizedPnL = PositionAccount.GetUnrealizedProfitLoss(Performanc eUnit.Currency, marketDataUpdate.Last);
    Print("unRealizedPnL: " + unRealizedPnL);
    Thankyou
    Attached Files

    #2
    Hello mr_trade,

    Do you have two instances of the script running? (this would be shown on the Strategies tab of the Control Center)

    Do you have multiple print calls in the script?

    Do you have multiple data series added to the script?

    How do you know there are two values if there is no Time[0] or time included with the print?
    Could this not be the unrealized changing as the price is changing?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thankyou for quick response.
      1. I only have 1 script running in strategies tab.
      2. Multiple prints = no, i have checked and commented out everything so it is only this print now.
      3. I do have multiple data series yes, 1 for tickdata. Is this the problem?
      4. Ive added time for you see new screenshot.
      5. And i have let the trade run a little more so you can see its not fluctuating between profit and zero.
      Thanks again.
      Attached Files

      Comment


        #4
        Hello mr_trade,

        Multiple data series will cause OnBarUpdate() to run for every series added, and Positions will be populated for each series.

        If there are multiple series, there is likely a series using the same instrument as another series, and does not populate with information.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ok thanks. yes so how do i isolate the position to just the primary series where the profit/loss is held for the position?
          Oh wait, you mean just run it on BarsInProgress == 0? Yep that worked lol thankyou!
          Last edited by mr_trade; 04-20-2021, 09:05 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          49 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          67 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X