Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.Chris L.NinjaTrader Customer Service
-
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.
Code:if (DrawObjects["Dot"] != null) { foreach (ChartAnchor anchor in DrawObjects["Dot"].Anchors) Print(anchor.Price); }
JimNinjaTrader Customer Service
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 GLFX005, Today, 03:23 AM
|
0 responses
2 views
0 likes
|
Last Post
by GLFX005
Today, 03:23 AM
|
||
Started by XXtrader, Yesterday, 11:30 PM
|
2 responses
11 views
0 likes
|
Last Post
by XXtrader
Today, 03:07 AM
|
||
Started by Waxavi, Today, 02:10 AM
|
0 responses
7 views
0 likes
|
Last Post
by Waxavi
Today, 02:10 AM
|
||
Started by TradeForge, Today, 02:09 AM
|
0 responses
14 views
0 likes
|
Last Post
by TradeForge
Today, 02:09 AM
|
||
Started by Waxavi, Today, 02:00 AM
|
0 responses
3 views
0 likes
|
Last Post
by Waxavi
Today, 02:00 AM
|
Comment