Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Does current bar touch or cross my trendline?
Collapse
X
-
Does current bar touch or cross my trendline?
I'm currently writing a ninjascript strategy and need the ability to see if the current bar is touching or crossed a manually drawn trend channel line. Is this possible?Tags: None
-
So, I'll need to loop through all the trendlines on the chart and determine if the current bar is using one of them?
Comment
-
I guess I'm a little confused with the example. It appears to be drawing a line then looking five bars back. Do you have any example of looping through drawn objects and finding it's projection?
Comment
-
Hello shildebrand324,
If you are wanting to loop through manually drawing objects this will be in the DrawObjects collection.
There is sample code in the help guide.
And links to a few other forum posts.
I've drawn a textbox manually and I would like to update it's position via my strategy. Basically I want to be able to edit the text on the chart so I can pass
Once you have the object the code would be similar to what is shown in the example linked in post #2.Chelsea B.NinjaTrader Customer Service
Comment
-
I've got the looping part down, but don't I need to get the start/end anchors for both sides of the trendchannel?
foreach (DrawingTool draw in DrawObjects)
{
if (draw is DrawingTools.TrendChannel)
{
}
}
Comment
-
ParallelEndAnchor doesn't appear to be a property as the guide states? ParallelStartAnchor is there.
Comment
-
Yes, but ParallelEndAnchor isn't available.
foreach (DrawingTool draw in DrawObjects)
{
if (draw is DrawingTools.TrendChannel)
{
TrendChannel channel = draw as DrawingTools.TrendChannel;
Print("Tag: " + draw.Tag + " Start Price: " + channel.TrendStartAnchor.Price + " End Price " + channel.TrendEndAnchor.Price);
Print("Tag: " + draw.Tag + " Parallel Start Price: " + channel.ParallelStartAnchor.Price + " End Price " );
}
}
Comment
-
Chelsea B.NinjaTrader Customer Service
Comment
-
-
-
So, did some digging and figured out how to calculate the parallelEndAnchor price
double parallelEndAnchorPrice = channel.ParallelStartAnchor.Price + (channel.TrendEndAnchor.Price - channel.TrendStartAnchor.Price);
Now if I can get some help plugging in the values for projecty, I'll be golden.
// First calculate slope of line
double runrate = (x2 - x1) / 5;
// Now project the slope to new bar
double projecty = runrate * (CurrentBar - y1bbar);
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
605 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
351 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
561 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment