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 use Performance function in an indicator?

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

    How to use Performance function in an indicator?

    Is there a way or work around to use the Performance function in an indicator. I want to be able to plot the daily points accumulated for the charts instrument.
    I'm getting error code 103 - The name 'Performance' does not exist in the current context
    Here's my code:

    protected override void OnBarUpdate()
    {
    if (Bars.SessionBreak)
    {
    priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Points.Cum Profit;
    }
    double dailyPoints = Performance.AllTrades.TradesPerformance.Points.Cum Profit - priorTradesCumProfit;

    // PLOTTING
    if (dailyPoints >= 0)
    {
    Profit.Set(dailyPoints); //[0]
    Loss.Set(0); //[1]
    }
    else
    {
    Profit.Set(0); //[0]
    Loss.Set(dailyPoints); //[1]
    }
    } // END OnBarUpdate

    Thanks.

    #2
    Hello Zacharydw00,

    Performance is only available within a strategy. However you can add plots within a strategy. See here for the reference sample on plotting from within a Strategy.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Really neat stuff.

      Does anyone know how to plot during backtesting ? I mean plotting strategy variables.

      I know that the alternative is to use some .NET (I hate that dot before NET, never figured out why is there ... ) library but I was hoping that NT7 could do that with some other way.

      Thanks in advance !

      Comment


        #4
        TakisTakis, please see the reference sample for plotting within a strategy.

        Actually, I just noticed this is for real-time only, sorry.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Here's a code snippet from the purple indicator shown in the screen shot below.

          if ( BarNumSwHiAP0 < BarNumSwLo[0] //Need Sw Low occurs after Sw High
          && Indicator[2] < Ind1 && Ind1 > Indicator[0]) //Need Ind 1 bar high
          {
          if (IndSwHiAP0 > Ind1) DrawText("Txt"+CurrentBar,true,Math.Round((Ind1/IndSwHiAP0)*100,4).ToString(),1,Ind1+(TickSize*MDF),Color.Black,textFont,StringAlignment.Near,Color.T ransparent,Color.Transparent,0);
          if (IndSwHiAP0*deltaInd >= Ind1 && PriceSwHiAP0+deltaPrice <= C1) //Checks Ind up & Price down (Divergence) 1 Hi back
          {
          int BarAgo0 = CurrentBar-BarNumSwHiAP0;
          DrawLine("PHline1"+CurrentBar.ToString(), BarAgo0, PriceSwHiAP0+(TickSize*MDF), 1, C1+(TickSize*MDF), DLC, DSD, DLW);
          DrawLine("IHline1"+CurrentBar.ToString(), BarAgo0, IndSwHiAP0+(TickSize*MDF), 1, Ind1+(TickSize*MDF), DLC, DSD, DLW);
          if (activatealertsound) PlaySound(shortwavfilename);
          }
          if ( IndSwHiAP1 > IndSwHiAP0
          && IndSwHiAP1*deltaInd >= Ind1 && PriceSwHiAP1+deltaPrice <= C1) //Checks Divergence 2nd Sw Hi back
          {
          int BarAgo1 = CurrentBar-BarNumSwHiAP1;
          DrawLine("PHline2"+CurrentBar.ToString(), BarAgo1, PriceSwHiAP1+(TickSize*MDF), 1, C1+(TickSize*MDF), DLC, DSD, DLW);
          DrawLine("IHline2"+CurrentBar.ToString(), BarAgo1, IndSwHiAP1+(TickSize*MDF), 1, Ind1+(TickSize*MDF), DLC, DSD, DLW);
          DrawArrowDown("ArrDn"+CurrentBar, true, 0, Ind1+TickSize+(TickSize*MDF),Color.GreenYellow);
          if (activatealertsound) PlaySound(shortwavfilename);
          }
          }

          Put this in the variables section;
          private Font textFont = new Font("Arial", 10);

          The command of interest is DrawText. Replace the bold text with your variable, and the italic text with a variable correlated to the Y axis(ie Low[0] or High[0]). I used the indicator's value.

          Please don't ask me to explain the extra code. I included it to put the DrawText command in context with the image I posted. The numbers next to the purple dotted line is drawn from this code when the if conditions are met.
          Attached Files

          Comment


            #6
            Thanks a lot, I really appreciate it!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,229 views
            0 likes
            Last Post xiinteractive  
            Started by andrewtrades, Today, 04:57 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            7 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            441 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            12 views
            0 likes
            Last Post FAQtrader  
            Working...
            X