I need to draw horizontal lines on an chart using an indicator. The line last drawn is the line that is displayed at the top. I need to control at what level the line draws so I thought I could the .ZOrder property of the HorizontalLine to ajdust the Zorder level.
Find attached an indicator I built to test this. Also, below find the relevant segment of the code to review. I need the first line drawn to be on top and the last drawn line under the other two. I use the ZOrder property as follows:
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
Print("-------" + CurrentBar);
{
//This line should be on top
NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e hzlSwingL = Draw.HorizontalLine(this, "Line1", Close[0], true, "");
hzlSwingL.Stroke = new Stroke(Brushes.Aqua , 10.0f);
hzlSwingL.ZOrder = int.MaxValue;
//This Line in the middle
hzlSwingL = Draw.HorizontalLine(this, "Line2" , Close[0], true, "");
hzlSwingL.Stroke = new Stroke(Brushes.Green , 20.0f );
hzlSwingL.ZOrder = 29000 ;
//This line should be below the first two
hzlSwingL = Draw.HorizontalLine(this, "Line3" , Close[0], true, "");
hzlSwingL.Stroke = new Stroke(Brushes.Red , 30.0f );
hzlSwingL.ZOrder = 1 ;
}
foreach (IDrawingTool hLine in DrawObjects)
{
if(hLine is NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e)
{
DrawingTools.HorizontalLine myLine = hLine as HorizontalLine;
Print(">>>>HorizontalLine: " +myLine.Tag + " zOrder:" + myLine.ZOrder);
}
}
Here is a sample from the Output window placed on a ES 12-19 5 minute chart:
-------1128
>>>>HorizontalLine: line1 zOrder:20273
>>>>HorizontalLine: @Line2 zOrder:20274
>>>>HorizontalLine: @Line3 zOrder:20275
-------1129
>>>>HorizontalLine: line1 zOrder:20273
>>>>HorizontalLine: @Line2 zOrder:20274
>>>>HorizontalLine: @Line3 zOrder:20275
-------1130
>>>>HorizontalLine: line1 zOrder:20273
>>>>HorizontalLine: @Line2 zOrder:20274
>>>>HorizontalLine: @Line3 zOrder:20275
-------1131
>>>>HorizontalLine: line1 zOrder:20273
>>>>HorizontalLine: @Line2 zOrder:20274
>>>>HorizontalLine: @Line3 zOrder:20275
The lines are displayed in the order that they are drawn with the last line on top of the other two. The ZOrders are not being set.
What am I doing incorrectly?
How can I get the order of the lines to be drawn on the levels I need.
Thank you
ReorderZorder.zip
Comment