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

Plotting values that change in the past

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

    Plotting values that change in the past

    Hi,

    Had a quick question. Let's say I have an indicator that looks for reversals measured from prior highs and lows. A reversal won't be known for some n bars after the relevant high or low, however, once the reversal is identified I'd like to repaint the bars between the relevant high or low and the bar where the reversal was confirmed. Effectively redraw historical marks on the chart. The question is, how does NinjaTrader paint marks (lines, dots - whatever it is you're charting)? Does it repaint the visible screen with each tick, or, would I have to/how would I force the repaint of prior bars?

    Regards,

    Gordon

    #2
    Hi Gordon,

    Thanks for your post.

    Drawing objects such as lines, rays, etc will only be redrawn when they are called with the same tag name. If the call in inside on OnBarUpdate then they will be redrawn when the bar closes. Really, though, they are updated whenever they are called again.

    By using the same tag name you can overwrite the drawing object and have it redrawn where ever you would like. By using unique tag names you will not overwrite the older object and will have a new additional one.

    When it comes to plots, these will be on each bar. It is possible to update an old value of a plot. Lets say that I wanted to change the value of a plot from 5 bars ago.
    To do this I can use:
    Value.Set(5, 100.01);

    This would set the value of the first added plot to 100.01 5 bars ago.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      That's very helpful. What I'm trying to emulate is really just the @VolumeUpDown, except I have other criteria for which volume bars should be red and which green. I see that that indicator uses Reset(), which the help seems to indicate makes the current value null. Is it correct to say that if it is null - as opposed to zero - then nothing will plot? If it is, then is there a way to "reset" a prior element in a dataseries so that where it once plotted it no longer does (and does changing a prior plotted dataseries value, as in your example, automatically trigger a replot to reflect the updated value, or do you have to cause that to happen manually)?

      Thanks,

      Gordon

      Comment


        #4
        Hi grose,

        The Reset() does not cause a null value to be stored and instead makes the plot no longer visible for that bar.

        Simply not setting a value will cause that bar to be null.

        From the help guide on DataSeries: "Reset() method allows you to effectively ignore the value of the current bar for plotting purposes."
        http://www.ninjatrader.com/support/h...ries_class.htm

        There is a post from RyanM that carefully explains how the Reset() works.
        http://www.ninjatrader.com/support/f....php?t=32238#2

        It would be possible to hide an old value by supplying a bars ago value to the Reset().

        For example:
        Value.Reset(5);

        This would hide the plot 5 bars ago.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          I've made a lot of progress - thanks for the help.

          I am left with a question, a fairly basic plotting question.

          In the Initialize method for the indicator I have the following, where plotAsHistogram is a boolean input parameter:

          if (plotAsHistogram)
          {
          Add(new Plot(new Pen(Color.Lime, 2), PlotStyle.Bar, "UpCalc"));
          Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Bar, "DnCalc"));
          }

          and then elsewhere in the OnBarUpdate method I have code like
          ...

          if (plotAsHistogram)
          {
          Values[0].Set(...);
          Values[1].Reset();
          }

          The code executes, but the plot is a line and not a bar. Also, the colors look like the defaults and are not the colors specified in the code. I've uploaded a small screen shot to show what I'm referring to - the orange line at the bottom should be a series of lime-colored bars.

          Do you see anything that would make the difference?

          Regards,

          Gordon
          Attached Files

          Comment


            #6
            You won't want to have a conditional check in your Initialize() for this. While doing this would likely work the first time you run the script, by modifying the value of plotAsHistogram you could run into cases where you get errors.

            Instead I would suggest defining all possible plots in your Initialize() regardless of input.

            Then you could use OnBarUpdate to plot them accordingly.

            To change the potStyle

            Plots[0].PlotStyle = PlotStyle.Bar;

            In regards to the colors it's hard for me to say without seeing the entire script.
            After removing the conditional from the initialize let me know if the issue persists.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by traderqz, Today, 12:06 AM
            2 responses
            3 views
            0 likes
            Last Post traderqz  
            Started by RideMe, 04-07-2024, 04:54 PM
            5 responses
            28 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by f.saeidi, Today, 08:13 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by DavidHP, Today, 07:56 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by kujista, Today, 06:23 AM
            3 responses
            11 views
            0 likes
            Last Post kujista
            by kujista
             
            Working...
            X