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 Hwop38, 05-04-2026, 07:02 PM
|
0 responses
160 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|
||
|
Started by CaptainJack, 04-24-2026, 11:07 PM
|
0 responses
308 views
0 likes
|
Last Post
by CaptainJack
04-24-2026, 11:07 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
245 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
349 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
179 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
Comment