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);
}
}