Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to connect Plot values between empty values

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

    How to connect Plot values between empty values

    Hello, I am trying to do a zig zag like Plot, where most candles have no value, but some do, and as such connect the points that do have value
    as in instead of me calculating the slope between Plot[0] and Plot[10] and manually putting the value for each candle in between, it will connect them automatically

    #2
    Hello LuxSpuzy,

    To do a zigzag like plot would require custom rendering. You can see the zigzag for an example of that. You need to use OnRender to find valid data points and render your own lines between points.

    Comment


      #3
      okay, thank you very much, I managed to get the OnRender working with just changing the Series variable name to my plot name
      is OnRender faster/better than drawing a line between points using Draw.Line()?

      Comment


        #4
        Hello LuxSpuzy,

        Yes OnRender is the most efficient way to render. Each drawing object takes resources where OnRender just renders what's on the visible bars based on the logic you supply in OnRender.

        Comment


          #5
          SOLVED: double.IsNaN();

          Okay thank you very much. one more question, why can't I compare my plot to a double.NaN
          if I do PlotMe[5] == double.NaN I get false, even tho it was set to double.NaN
          but if I compare != High which gets assigned if a pivot point is found, it works

          Code:
                  protected override void OnBarUpdate()
                  {
                      if(CurrentBar >= 5)
                      {
                          PlotMe[5] = pivothigh(High,5,5);
                          if(PlotMe[5] != High[5]) PlotMe.Reset(5); // works
                          if(PlotMe[5] == double.NaN) PlotMe.Reset(5); // doesn't work
                      }
                  }
          
                  protected double pivothigh(ISeries<double> c_array,int c_left, int c_right)
                  {
                      if(CurrentBar < c_left+c_right) return double.NaN;
                      double c_high = c_array[c_right];
                      double c_max  = c_array[0];
                      for(int o = 0; o <= 0+(c_left+c_right); o++)
                         c_max = Math.Max(c_max,c_array[o]);
                      return (c_max==c_high? c_high : double.NaN);
                  }​
          also thank you very much for the extremely fast replies, I am coming from Pine/MQL/TOS to Ninja and might have a few more questions in time, is it okay if I just post them on this post here?
          Last edited by LuxSpuzy; 02-09-2023, 03:13 PM.

          Comment


            #6
            Hello LuxSpuzy,

            In this case I would suggest making the following syntax:

            Code:
            PlotMe[5] = pivothigh(High,5,5);
            into:

            Code:
            pivothigh(High,5,5);
            Then make your method like the following. You can either set a value or don't set a value, do not set double.NaN.

            Code:
            private void pivothigh(ISeries<double> c_array,int c_left, int c_right)
            {
            if(CurrentBar < c_left+c_right) return;
            double c_high = c_array[c_right];
            double c_max = c_array[0];
            for(int o = 0; o <= 0+(c_left+c_right); o++)
            c_max = Math.Max(c_max,c_array[o]);
            if(c_max==c_high)
              PlotMe[5] = c_high;
            }​


            That lets you use the existing IsValidDataPointAt method on the series.

            https://ninjatrader.com/support/help...validdatapoint

            PlotMe[5] != High[5]
            Also keep in mind checking if two doubles are equal or not equal will fail in most cases. You should use math instead to check if there is a difference: https://ninjatrader.com/support/help...arithmetic.htm

            For unrelated questions you can post as many new threads as you like.
            Last edited by NinjaTrader_Jesse; 02-09-2023, 03:17 PM.

            Comment


              #7
              in that case the function needs to be modified for each next indicator
              I used
              Code:
              double ph = pivothigh(High,5,5);
              if(!double.IsNaN(ph)) PlotMe[5] = ph;​
              instead.

              Thank you for the comparing doubles tip!! much appreciated.
              one more question related to OnRender, can I dynamically set the color of the render then?

              Code:
              Plots[0].Brush = (CurrentBar % 2 == 0) ? Brushes.Lime : Brushes.Red;
              makes the whole line Red

              Code:
              PlotBrushes[0][0] = (CurrentBar % 2 == 0) ? Brushes.Lime : Brushes.Red;​
              does nothing

              I see inside OnRender this function
              Code:
              RenderTarget.DrawGeometry(g, Plots[0].BrushDX, Plots[0].Width, Plots[0].StrokeStyle);​
              but I can't use Brush here, and BrushDX is read only

              EDIT: Okay I've noticed OnRender is called differently and I can't change the color inside OnBarUpdate, but still is it possible for the line to be colored dynamically between points, so 1 connection is red, and the other is green
              Last edited by LuxSpuzy; 02-09-2023, 03:48 PM.

              Comment


                #8
                Hello LuxSpuzy,

                You would generally use anything with a BarsAgo in OnBarUpdate, those items cant be used from OnRender because [0] BarsAgo is irrelevant there. OnRender only knows about the current bars that are visible by using the FromIndex and ToIndex properties, that gives direct bar indexes.

                BarsAgo are a number of bars from now in processing in relation to OnBarUpdate. For example on bar 10 a BarsAgo of 5 means you get data from bar 5. In OnRender you get data based on indexes, if we assume you are looking at bars 1 through 10 the index of bar 5 would be 4, indexing starts at 0 and goes left to right.

                When you use Brush in OnRender you need to convert them to a BrushDX object. You an use the ToDxBrush() method on any Brush object. https://ninjatrader.com/support/help...BrushResources

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                646 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                367 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X