I am getting unwanted lines on my chart. If i comment out the draw.lines lines of code i still get the lines drawn. I am having an issue with another part of the script and i think this is the reason. Any help would be appreciated!
private void CalculateStructure()
{
if (CurrentBar < 1) return; // Ensure there is at least one bar
for (int i = 0; i <= CurrentBar; i++)
{
if (CurrentBar < 10)
{
// For the first 10 bars, find the highest high and lowest low
if (i == 0)
{
HighLevel = High[i];
LowLevel = Low[i];
}
else
{
if (High[i] > HighLevel)
{
HighLevel = High[i];
LastHHBar = HighLevel;
}
if (Low[i] < LowLevel)
{
LowLevel = Low[i];
LastLLBar = LowLevel;
}
}
}
else
{
// For bars after the first 10 bars, update HighLevel and LowLevel based on closing price
if (Close[0] > HighLevel)
{
HighLevel = High[0];
LowLevel = LastLLBar;
Draw.Line(this, "High Level" + CurrentBar, false, CurrentBar, HighLevel, CurrentBar, HighLevel, HighLvlColor, DashStyleHelper.Solid, 4);
Draw.Line(this, "Low Level" + CurrentBar, false, CurrentBar, LastLLBar, CurrentBar, LastLLBar, LowLvlColor, DashStyleHelper.Solid, 4);
Print($"New HH HighLevel at bar {CurrentBar}, price: {HighLevel}");
Print($"New HH LowLevel at bar {CurrentBar}, price: {LowLevel}");
}
else if (Close[0] < LowLevel)
{
LowLevel = Low[0];
HighLevel = LastHHBar;
Draw.Line(this, "High Level" + CurrentBar, false, CurrentBar, LastHHBar, CurrentBar, LastHHBar, HighLvlColor, DashStyleHelper.Solid, 4);
Draw.Line(this, "Low Level" + CurrentBar, false, CurrentBar, LowLevel, CurrentBar, LowLevel, LowLvlColor, DashStyleHelper.Solid, 4);
Print($"New LL HighLevel at bar {CurrentBar}, price: {HighLevel}");
Print($"New LL LowLevel at bar {CurrentBar}, price: {LowLevel}");
}
else
{
Draw.Line(this, "High Level" + CurrentBar, false, CurrentBar, HighLevel, CurrentBar, HighLevel, HighLvlColor, DashStyleHelper.Solid, 4);
Draw.Line(this, "Low Level" + CurrentBar, false, CurrentBar, LowLevel, CurrentBar, LowLevel, LowLvlColor, DashStyleHelper.Solid, 4);
Print($"Old HighLevel at bar {CurrentBar}, price: {HighLevel}");
Print($"Old LowLevel at bar {CurrentBar}, price: {LowLevel}");
}
}
}
}
region Properties
[NinjaScriptProperty]
[Display(Name = "Strength", Order = 1, GroupName = "Parameters")]
public int Strength { get; set; }
[NinjaScriptProperty]
[Display(Name = "TextOffset", Order = 2, GroupName = "Parameters")]
public int TextOffset { get; set; }
[NinjaScriptProperty]
[Display(Name = "LookBack", Order = 3, GroupName = "Parameters")]
public int LookBack { get; set; }
[NinjaScriptProperty]
[Display(Name = "DTBStrength", Order = 4, GroupName = "Parameters")]
public int DTBStrength { get; set; }
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name = "HHcolor", Order = 5, GroupName = "Colors")]
public Brush HHcolor { get; set; }
[Browsable(false)]
public string HHcolorSerializable
{
get { return Serialize.BrushToString(HHcolor); }
set { HHcolor = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name = "HLcolor", Order = 6, GroupName = "Colors")]
public Brush HLcolor { get; set; }
[Browsable(false)]
public string HLcolorSerializable
{
get { return Serialize.BrushToString(HLcolor); }
set { HLcolor = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name = "LLcolor", Order = 7, GroupName = "Colors")]
public Brush LLcolor { get; set; }
[Browsable(false)]
public string LLcolorSerializable
{
get { return Serialize.BrushToString(LLcolor); }
set { LLcolor = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name = "LHcolor", Order = 8, GroupName = "Colors")]
public Brush LHcolor { get; set; }
[Browsable(false)]
public string LHcolorSerializable
{
get { return Serialize.BrushToString(LHcolor); }
set { LHcolor = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name = "DBcolor", Order = 9, GroupName = "Colors")]
public Brush DBcolor { get; set; }
[Browsable(false)]
public string DBcolorSerializable
{
get { return Serialize.BrushToString(DBcolor); }
set { DBcolor = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name = "DTcolor", Order = 10, GroupName = "Colors")]
public Brush DTcolor { get; set; }
[Browsable(false)]
public string DTcolorSerializable
{
get { return Serialize.BrushToString(DTcolor); }
set { DTcolor = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name = "HighLvlColor", Order = 11, GroupName = "Colors")]
public Brush HighLvlColor { get; set; }
[Browsable(false)]
public string HighLvlColorSerializable
{
get { return Serialize.BrushToString(HighLvlColor); }
set { HighLvlColor = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[XmlIgnore]
[Display(Name = "LowLvlColor", Order = 12, GroupName = "Colors")]
public Brush LowLvlColor { get; set; }
[Browsable(false)]
public string LowLvlColorSerializable
{
get { return Serialize.BrushToString(LowLvlColor); }
set { LowLvlColor = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[Display(Name = "TextFont", Order = 13, GroupName = "Fonts")]
public SimpleFont TextFont { get; set; }
#endregion
}
}
Comment