Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting unrealized P&L

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

    Plotting unrealized P&L

    Code:
    Plot0(
    if (Position.MarketPosition != MarketPosition.Flat)
             Print("Open PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Points)));
    doesn't plot. How else can I plot unrealized P&L on chart as an indicator? I tried making an indicator, still no luck. I also tried close[0] avg.position price. still no luck

    #2
    Hello,

    Thank you for the question.

    For doing this from an indicator there is no supported way as this is a strategy base variable. the only way to use the code you have provided would be from a strategy.

    This would not be able to be plotted directly from the strategy though as the plots are an indicator base item.

    Although this is not supported, you can take a look at the code from the @UnrealizedProfitLoss.cs which is in the Documents\NinjaTrader 7\bin\Custom\MarketAnalyzer folder.

    This shows the syntax needed to accomplish what you are after.

    What needs to happen in an indicator would be you have to loop through the accounts to get the values you are after, this market analyzer column, although laid out slightly different holds the code you would need to use to get this working from an indicator.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Code:
                  double a,b,c;
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
                  a= (((Closes[1][0]-Opens[1][0])/.25)*5);
                  b= (((Closes[0][0]-Opens[0][0])/.25)*12.5);    
                  c= a+b;
                  Plot3.Set(c);
      guys there has to be an easier way to plot the unrealized P&L. the above is an indicator that plots the dollar move of two instruments... minute by minute. isn't there a way to input Position.AvgPrice in the above code?? How can I access strategy info in an indicator w/o breaking my back lol??

      Comment


        #4
        Hello,

        Thank you for the question.

        There is not currently a supported way to access strategy metrics from an indicator as the indicator base does not support these methods and a strategy is a separate instance from an indicator meaning they can not see each other.

        Strategies are like a bubble, they contain all the strategy related information for that running instance but can not be accessed from outside.

        you could look into using the Strategy Plots example we have in the references section on the forum http://www.ninjatrader.com/support/f...ead.php?t=6651

        This shows how to pass values from a strategy to a template indicator, if the strategy is adding the indicator it would have access to the instance, if you add the indicator manually it would not have access.

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, Today, 03:20 PM
        0 responses
        2 views
        0 likes
        Last Post cre8able  
        Started by Fran888, 02-16-2024, 10:48 AM
        3 responses
        46 views
        0 likes
        Last Post Sam2515
        by Sam2515
         
        Started by martin70, 03-24-2023, 04:58 AM
        15 responses
        114 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by The_Sec, Today, 02:29 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by jeronymite, 04-12-2024, 04:26 PM
        2 responses
        31 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X