Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
check if draw object exists
Collapse
X
-
Hello ballboy11,
Thanks for the note.
There exists the DrawObjects[] collection to get all of the draw objects applied to the chart:
https://ninjatrader.com/support/help...rawobjects.htm
That is a good way to find a drawing object by tag name.
Alternatively, please see this example where I loop through all of the drawing objects on the chart by searching through the ChartPanel.ChartObjects collection on line 154 in OnRender(). This example finds the draw object by its type.
This indicator will read the horizontal lines that you have applied to a chart and display the price at which that line sits.
Please let us know if we may be of any further assistance.Last edited by NinjaTrader_ChrisL; 05-15-2019, 08:22 AM.
-
Hello,
from the link with looping to find specific draw object I got help for what I need and I use as name for the drawingobjects the price where it is drawn so that I can refer later to this drawobject by price. But I work round many hours and can´t fix one problem: how can one work with the tagname/price to compare with current price like if(High[0]>"drawobjectname/tagname/price") then Remove(....) If High[0]> ???
Thank you!
Tony
Comment
-
Hello Tony,
You can reference a Drawing object by name with DrawObjects["YOURTAG"] and you can access the Anchors of the Drawing Object to see where it is drawn.
From there you could use the tag with RemoveDrawObject to remove that object from the chart.
Below is an example showing how to access Anchors of a DrawObject.
We look forward to assisting.Code:if (DrawObjects["Dot"] != null) { foreach (ChartAnchor anchor in DrawObjects["Dot"].Anchors) Print(anchor.Price); }
Comment
-
Hi,
I have created a simple indicator to detect a horizontal line. The original value of the line is set to 1000. When a line is drawn or moved, the anchor price of the horizontal is shown and updated. However, when I delete the line, how do I get it to reset to 1000? Thanks your assistance. Code below.
public class HorizontalLineDetector : Indicator
{
// Declare variables
HorizontalLine HL;
private double HLValue = 1000 ;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "HorizontalLineDetector";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = false;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = false;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
}
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects)
{
if(thisObject is NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e)
{
HL = thisObject as NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e;
HLValue = HL.StartAnchor.Price;
}
}
Print ("HLValue : ");
Print (HLValue);
}
}
My code is highlighted in purple. I just copied and pasted here. I would also appreciate it if you could share with me the way to share a code so it shows up as properly formatted as above post #6.
Comment
-
Hi Jim, thanks so much
Can you share how to paste a code so it is properly formatted like in post #6 above?
Comment
-
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
563 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
329 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
547 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
548 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment