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

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 Christopher_R, Today, 12:29 AM
          0 responses
          6 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,235 views
          0 likes
          Last Post sidlercom80  
          Started by thread, Yesterday, 11:58 PM
          0 responses
          3 views
          0 likes
          Last Post thread
          by thread
           
          Started by jclose, Yesterday, 09:37 PM
          0 responses
          7 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,415 views
          0 likes
          Last Post Traderontheroad  
          Working...
          X