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

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 bmartz, 03-12-2024, 06:12 AM
      4 responses
      31 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by Aviram Y, Today, 05:29 AM
      4 responses
      12 views
      0 likes
      Last Post Aviram Y  
      Started by algospoke, 04-17-2024, 06:40 PM
      3 responses
      28 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by gentlebenthebear, Today, 01:30 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by cls71, Today, 04:45 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X