Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

public override void Plot

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

    public override void Plot

    I need to make a ZigZag Plot and I was directed by NT to use the ZigZag Indicator as an example to work from. The problem is that in the ZigZag indicator included in NT it does not allow you to pass in the DataSeries as a parameter in the override function. I'm trying to have multiple ZigZag Plots in a single indicator and I'm hoping there's a way to do this without duplicating code.

    If you look at the code below you can see that it has several references to zigZagSeries1 but I need to pass the DataSeries in as an argument somehow so I can use the same code again without having to duplicate code. The problem is any time I change the parameters in 'public override void Plot' I get an error that reads:
    'NinjaTrader.Indicator.aaaMyZigZag2.Plot(NinjaTrad er.Data.DataSeries, System.Drawing.Graphics, System.Drawing.Rectangle, double, double)': no suitable method found to override,

    Here's the code:
    Code:
    public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
    		{
    			if (Bars == null || ChartControl == null) return;
    
    			// make sure indicator is calculated until last (existing) bar
    			IsValidPlot(Bars.Count - 1 + (CalculateOnBarClose ? -1 : 0));
    
    			int preDiff = 1;
    			for (int i = FirstBarIndexPainted - 1; i >= BarsRequired; i--)
    			{
    				if (i < 0 || (zigZagSeries1.IsValidPlot(i) && zigZagSeries1.Get(i) > 0)) break;
    				preDiff++;
    			}
    
    			int postDiff = 0;
    			for (int i = LastBarIndexPainted; i <= zigZagSeries1.Count; i++)
    			{
    				if (i < 0 || (zigZagSeries1.IsValidPlot(i) && zigZagSeries1.Get(i) > 0)) break;
    				postDiff++;
    			}
    			
    			bool linePlotted = false;
    			using (GraphicsPath path = new GraphicsPath())
    			{
    				int lastIdx = -1;
    				double lastValue = -1;
    
    				for (int idx = this.FirstBarIndexPainted - preDiff; idx <= this.LastBarIndexPainted + postDiff; idx++)
    				{
    					if (idx - Displacement < 0 || idx - Displacement >= Bars.Count || (!ChartControl.ShowBarsRequired && idx - Displacement < BarsRequired)) continue;
    					if (!(zigZagSeries1.IsValidPlot(idx) && zigZagSeries1.Get(idx) > 0)) continue;
    
    					if (lastValue >= 0)
    					{
    						int x0 = ChartControl.GetXByBarIdx(BarsArray[0], lastIdx);
    						int x1 = ChartControl.GetXByBarIdx(BarsArray[0], idx);
    						int y0 = ChartControl.GetYByValue(this, lastValue);
    						int y1 = ChartControl.GetYByValue(this, zigZagSeries1.Get(idx));
    
    						path.AddLine(x0, y0, x1, y1);
    						linePlotted = true;
    					}
    
    					// save as previous point
    					lastIdx = idx;
    					lastValue = zigZagSeries1.Get(idx);
    				}
    
    				SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
    				graphics.SmoothingMode = SmoothingMode.AntiAlias;
    				graphics.DrawPath(Plots[0].Pen, path);
    				graphics.SmoothingMode = oldSmoothingMode;
    			}
    
    			if (!linePlotted)
    				DrawTextFixed("ZigZagErrorMsg", "aaaNiedZigZag can't plot any values since the deviation value is too large. Please reduce it.", TextPosition.BottomRight);
    		}

    #2
    Hello LorneCash,

    Thank you for your post.

    You cannot change the signature of the overridden method, meaning you cannot pass the DataSeries through. What are the new values you wish to have plotted like the ZigZag lines?

    Comment


      #3
      I was kinda thinking that was the case so I just added it in the long way by doubling the code inside the function. Thanks anyways.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X