Why i keep getting a error when im try to change the draw Draw.HorizontalLine to a Dray Ray

I’m trying to change the Draw.HorizontalLine(this, tag, high, Brushes.Red); to a Draw Ray
But im getting an error

public class MelSwing : Indicator
{
	private int				constant;
	private double			currentSwingHigh;
	private double			currentSwingLow;
	private ArrayList		lastHighCache;
	private double			lastSwingHighValue;
	private ArrayList		lastLowCache;
	private double			lastSwingLowValue;
	private int				saveCurrentBar;

	private Series<double> swingHighSeries;
	private Series<double> swingHighSwings;
	private Series<double> swingLowSeries;
	private Series<double> swingLowSwings;
	
	//add on
	
	private List<double> swingHighs = new List<double>();
    private List<double> swingLows = new List<double>();

    private List<string> highTags = new List<string>();
    private List<string> lowTags = new List<string>();

    // Track if level has already been crossed once
    private List<bool> highBroken = new List<bool>();
    private List<bool> lowBroken = new List<bool>();

	protected override void OnStateChange()
	{
		if (State == State.SetDefaults)
		{
			Description					= Custom.Resource.NinjaScriptIndicatorDescriptionSwing;
			Name						= "MelSwing";
			DisplayInDataBox			= false;
			PaintPriceMarkers			= false;
			IsSuspendedWhileInactive	= true;
			IsOverlay					= true;
			Strength					=7;

			AddPlot(new Stroke(Brushes.DarkCyan,	2), PlotStyle.Dot, "Swing");
		
		}

		
	
	
		{
        if (State == State.SetDefaults)
        {
            Name = "SwingBreakLevels";
            Description = "Swing levels stay until price crosses back through them.";
            IsOverlay = true;
        }
    }
	}

	protected override void OnBarUpdate()
	{
	//add on
	
		 {
        if (CurrentBar < Strength * 2)
            return;

        int idx = Strength;

        bool isSwingHigh = true;
        bool isSwingLow = true;

        double high = High[idx];
        double low = Low[idx];

        for (int i = 1; i <= Strength; i++)
   {
            if (high <= High[idx - i] || high <= High[idx + i])
                isSwingHigh = false;

            if (low >= Low[idx - i] || low >= Low[idx + i])
                isSwingLow = false;
     }
		
        // Draw swing high
        if (isSwingHigh)
    {
            string tag = "SwingHigh_" + CurrentBar;

           Draw.HorizontalLine(this, tag, high, Brushes.Red);

            swingHighs.Add(high);
            highTags.Add(tag);
            highBroken.Add(false);
     }

        // Draw swing low
        if (isSwingLow)
      {
            string tag = "SwingLow_" + CurrentBar;

            Draw.HorizontalLine(this, tag, low, Brushes.Green);

            swingLows.Add(low);
            lowTags.Add(tag);
            lowBroken.Add(false);
        }

       // Process swing highs
		for (int i = swingHighs.Count - 1; i >= 0; i--)
		{
		double level = swingHighs[i];

		// First cross above swing high
		if (!highBroken[i] && Close[0] > level)
		{
  		  highBroken[i] = true;

  		  // Redraw the same line as dashed
 		   Draw.HorizontalLine(this, highTags[i], level,
	        Brushes.Red );
			   }

		 // Second cross back below → remove line
		  else if (highBroken[i] && Close[0] < level)
		 {
	    RemoveDrawObject(highTags[i]);

		    swingHighs.RemoveAt(i);
		    highTags.RemoveAt(i);
		    highBroken.RemoveAt(i);
		  }
		}

        // Process swing lows
		for (int i = swingLows.Count - 1; i >= 0; i--)
		{
		 double level = swingLows[i];

		 // First cross below swing low
		 if (!lowBroken[i] && Close[0] < level)
			 {
	     lowBroken[i] = true;

 	   // Redraw dashed
 		   Draw.HorizontalLine(this, lowTags[i], level,Brushes.Green);
		 }

// Second cross back above → remove line
else if (lowBroken[i] && Close[0] > level)
{
    RemoveDrawObject(lowTags[i]);

    swingLows.RemoveAt(i);
    lowTags.RemoveAt(i);
    lowBroken.RemoveAt(i);
}

}

The issue is likely:
Draw.HorizontalLine(this, lowTags[i], level,Brushes.Green);

According to the guide, the syntax is as follows:

Draw.HorizontalLine(NinjaScriptBase owner, string tag, double y, Brush brush)

Draw.HorizontalLine(NinjaScriptBase owner, string tag, bool isAutoScale, double y, Brush brush, DashStyleHelper dashStyle, int width)

Draw.HorizontalLine(NinjaScriptBase owner, string tag, bool isAutoscale, double y, Brush brush, bool drawOnPricePanel)

Draw.HorizontalLine(NinjaScriptBase owner, string tag, double y, Brush brush, DashStyleHelper dashStyle, int width, bool drawOnPricePanel)

Draw.HorizontalLine(NinjaScriptBase owner, string tag, double y, bool isGlobal, string templateName)

Yours does not seem to be meeting any of these. The closest might be the third one, in which case you need to add the tag in the second parameter and the bool for DrawPricePanel for the last parameter.

If that does not help, what is the error state? and when is the error triggering?

Dray Ray requires a start and End X. Draw.HorizontalLine does not. Check the document.

1 Like

Im getting the error( The Name DashStyleHelper does not exist in the current context)

You can’t just put the pixel width in like this.

What you need is this:

		AddPlot(new Stroke(Brushes.DarkCyan, DashStyleHelper.Dot, 2, 100), PlotStyle.HLine, "Swing");
2 Likes