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

DataSeries.Reset() for indicator plot

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

    DataSeries.Reset() for indicator plot

    Hi,

    Based on this thread



    I am trying to implement the .Reset() method but the code used in post #4 & post #5 doesn't seem to be working for my indicator.

    When I use the .Reset() method on a prior bar, the entire indicator disappears. Without the call to .Reset(), the indicator plots as expected but without the functionality I am trying to achieve.

    Ideally, the indicator would "forget" that it was plotting at the bar being reset and, instead, plot at the value of PlotLine[0] on the current bar (which in this case is High[0]).

    Code:
                // Initialize
                Add(new Plot(Color.Orange, PlotStyle.Line, "PlotLine"));
    
                // OnBarUpdate
                if (Close[0] > Close[1])
                {
                    if (High[0] >= High[2])
                        PlotLine.Set(High[0]);
                    if (PlotLine.ContainsValue(2))
                        PlotLine.Reset(2);               // skip over value of 2 bars ago
                }
    Can someone point me in the right direction?

    Many thanks

    #2
    Hi dave01,

    Thanks for your post.

    When you mention
    Ideally, the indicator would "forget" that it was plotting at the bar being reset and, instead, plot at the value of PlotLine[0] on the current bar (which in this case is High[0]).
    Are you asking how to remove the plot from 2 bars ago?

    Currently, the remove call is working as intended.

    Your code has the following logic:

    First if the close of the current bar must be greater than the close of the previous bar and the current high must be greater than or equal to the high of 2 bars ago, then set the plot to the current high.

    Separately, the close of the current bar must be greater than the close of the previous bar and if there is a plot set 2 bars ago, hide this bar.

    This means that if the close is greater than the close of the previous bar, the plot of 2 bars ago will always be hidden. Moving forward this will erase your line as you go along and you will only have a plot between the most recent bar and the previous bar.

    This means you will only see a plot where the close is less than the previous close, because the code will not hide the plot from 2 bars ago when the price starts going down.

    This is what I am seeing when running this code. Screenshot attached.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      Nice catch...

      This in-progress indicator is being applied to a point and figure chart. I can't test it at the moment but I believe the code should be:
      Code:
                  // OnBarUpdate
                  if (Close[0] > Close[1])    // up bar
                  {
                      if (High[0] >= High[2])
                      {                                                << add bracket
                          PlotLine.Set(High[0]);
                          if (PlotLine.ContainsValue(2))
                              PlotLine.Reset(2);
                      }                                                << add bracket
                  }
      If the current bar's close is higher than the previous bar's close (this gets me an up bar)
      & if the current bar's high is equal to or higher than the high 2 bars ago (equal or greater upward progress)
      & if there's a value for the plot 2 bars ago,
      > plot the value of the current bar instead of the value from 2 bars ago

      Here's the other side to complete the zigzag:

      Code:
       else if (Close[0] < Close[1])    // down bar
                  {
                      if (Low[0] <= Low[2])
                      {
                          PlotLine.Set(Low[0]);
                          if (PlotLine.ContainsValue(2))
                              PlotLine.Reset(2);
                      }
                  }
      Many thanks!

      Dave

      Comment


        #4
        Hi dave01,

        I'm still not quite sure about what you are trying to do.

        When you mention "plot the value of the current bar instead of the value from 2 bars ago" it sounds like you want to plot the value of the current bar instead of the value of 2 bars ago on the current bar.

        Are you actually wanting to remove the value from 2 bars ago?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi ChelseaB,

          Thank you for following up. I've attached a pic of my intended final result.

          Looking at the pic, and imagining real-time from bar 10:
          > the line rising from the low of bar 10 will be drawn to the high of bar 11 (cyan)
          > when the high of bar 13 meets or exceeds the high of 11 then
          >> the cyan line will be replaced with a new line that will be drawn from the low of 10 to the high of 13...and so on.

          I want the current leg of the wave to update when the market has either reached or exceeded the previous same column type's extreme value...if that makes any sense.

          Originally, I thought that if I could set a past value in the series to a null value, it wouldn't plot. After reading through some more posts, I got the impression that the way to implement this was to use DataSeries.Reset(int BarsAgo).

          Am I on the right track?
          Attached Files

          Comment


            #6
            Hi dave01,

            If you are trying to draw the line from the low of 10 where it is already starting to the high of bar 13, why would you try and remove the line?

            Instead, I think you want to historically change the values of the plot (instead of hiding it).

            Am I not understanding what you are trying to do correctly?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi ChelseaB,

              Correct, I do not want to hide the plot. I only want to change the end point of the last line.

              My thinking was that I needed 2 sets of (x,y) coordinates to plot a line. Due to the structure of the DataSeries object -- that is, one value per bar -- the 'x' coordinates are a given. The values inside the DataSeries are the 'y' coordinates.

              When a "more appropriate" end point appeared (the high of bar 13 for example), I would remove/reset/hide/change(semantics?) the 'y' value for bar 11. The result would be a smooth line drawn from the low of 10 to the high of 13 (as if there had never been a line drawn from the low of 10 to the high of 11).

              DataSeries.Set(int barsAgo, double value) will allow me to change an historical value for bar 11...but I don't know what the magical value should be...?

              Comment


                #8
                Hi dave01,

                The Reset() hides the plot from the chart.

                I think you are looking to use DataSeries.Set(barsAgo, value);

                You will need to calculate the new point for every bar in-between these points and the last point and then loop through and set the plot on each bar again with the new calculated value.


                However, if you are just drawing a line and not needing a plot, it may be far easier to just draw the line using DrawLine().

                This would mean that you do not need to set the historical value for each bar in-between the two points.

                By re-using the tag name, this would overwrite the bar instead of adding another.

                http://www.ninjatrader.com/support/h...7/drawline.htm
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi ChelseaB,

                  Great, that clears it up for me. Thanks a lot for sticking with this.

                  Dave

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by gravdigaz6, Today, 11:40 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by MarianApalaghiei, Today, 10:49 PM
                  3 responses
                  10 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by XXtrader, Today, 11:30 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post XXtrader  
                  Started by love2code2trade, Yesterday, 01:45 PM
                  4 responses
                  28 views
                  0 likes
                  Last Post love2code2trade  
                  Started by funk10101, Today, 09:43 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post funk10101  
                  Working...
                  X