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

Purpose of Plot.Reset() in MultiColor MAs

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

    Purpose of Plot.Reset() in MultiColor MAs

    In the reference library I found SampleMultiColoredPlot.cs. An excerpt of the code is below. Other multicolored MAs that I've found recently are coded pretty much the same way, but they don't have Plot.Reset() in the code. Visually, I don't see much if any difference.

    What is the purpose of Plot.Reset()?

    Does it correct a drawing overlap or does it help to conserve resourses or prevent a memory leak or something else important?

    I've put some transparent plots in my multicolor MAs so I can grab the values in my strategy. I do not have a Plot.Reset() included for the transparent ones, but I do for the colors. I guess I'm wanting to know if Plot.Reset() needs to be included for both color and transparent plots or for one or the other or not at all, and why...

    Thanks.

    Excerpted Code:

    protected override void OnBarUpdate()
    {
    // Checks to make sure we have at least 1 bar before continuing
    if (CurrentBar < 1)
    return;

    // Plot green if the SMA is rising
    // Rising() returns true when the current value is greater than the value of the previous bar.
    if (Rising(SMA(Period)))
    {
    // Connects the rising plot segment with the other plots
    RisingPlot.Set(1, SMA(Period)[1]);

    // Adds the new rising plot line segment to the line
    RisingPlot.Set(SMA(Period)[0]);
    NeutralPlot.Reset();
    FallingPlot.Reset();
    }

    // Plot red if the SMA is falling
    // Falling() returns true when the current value is less than the value of the previous bar.
    else if (Falling(SMA(Period)))
    {
    // Connects the new falling plot segment with the rest of the line
    FallingPlot.Set(1, SMA(Period)[1]);

    // Adds the new falling plot line segment to the line
    FallingPlot.Set(SMA(Period)[0]);
    RisingPlot.Reset();
    NeutralPlot.Reset();
    }

    // Plot yellow if the SMA is neutral
    else
    {
    // Connects the neutral plot segment with the rest of the line
    NeutralPlot.Set(1, SMA(Period)[1]);

    // Adds the new neutral plot line segment to the line
    NeutralPlot.Set(SMA(Period)[0]);
    RisingPlot.Reset();
    FallingPlot.Reset();
    }
    }

    #2
    This is a way of cleaning up the display. You're not likely to see much of a difference, but reset forces the plot to reset. This is so the plot that is not supposed to display won't display.

    Below is a description for DataSeries reset, which works pretty similar to the Plot reset:


    Calling the Reset() method is unique and can be very powerful for custom indicator development. DataSeries objects can hold null values which simply means that you do not want to store a value for the current bar. Mathematically, you can correctly assign a value of zero however if the DataSeries was the primary DataSeries of an indicator whose values would be used for plotting, you may NOT want a zero value plotted. Meaning, you want a zero value for proper calculations but not a zero value for chart visualization. The Reset() method allows you to reset the current bar's DataSeries value to a zero for calculation purposes but NinjaScript would ignore this value when it plotted it on a chart.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by gentlebenthebear, Today, 01:30 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Aviram Y, Today, 05:29 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by cls71, Today, 04:45 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by TradeForge, Today, 02:09 AM
      1 response
      22 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by elirion, Today, 01:36 AM
      2 responses
      14 views
      0 likes
      Last Post elirion
      by elirion
       
      Working...
      X