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

Unrealized PnL calculation...

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

    Unrealized PnL calculation...

    I'm attempting to shorten up the unrealized profit calculation script. There will be a lot of indexes but just for example's sake...

    If I am wanting to use...

    for (int i = 0; i < 2; i++)
    {
    unrlzdPnl += Positions[i].GetProfitLoss(Closes[i][0],PerformanceUnit.Points);
    }

    is this equivalent to my old way of..

    unrlzdPnl = ((Positions[0].GetProfitLoss(Closes[0][0],PerformanceUnit.Points)) + (Positions[1].GetProfitLoss(Closes[1][0],PerformanceUnit.Points)));

    It doesn't seem to be from the print statements. Any idea how I can use the first way to replicate the second?
    Last edited by Delta007; 03-12-2014, 09:07 PM.

    #2
    Delta007, for the first you would need to reset the tracker on each bar update for example, otherwise it would just continue to cumulate across all trades seen which is not what you seek...
    BertrandNinjaTrader Customer Service

    Comment


      #3
      How would the tracker be reset, would this be something with BIP or a bool, or simply just putting the statement within the OBU method?

      Comment


        #4
        Would just set it to 0.0 at your OBU update start, so it only builds the sum of the positions across the indices and would not cumulate.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kevinenergy, 02-17-2023, 12:42 PM
        115 responses
        2,699 views
        1 like
        Last Post kevinenergy  
        Started by prdecast, Today, 06:07 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Christopher_R, Today, 12:29 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by chartchart, 05-19-2021, 04:14 PM
        3 responses
        577 views
        1 like
        Last Post NinjaTrader_Gaby  
        Started by bsbisme, Yesterday, 02:08 PM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X