Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Does current bar touch or cross my trendline?
Collapse
X
-
Seems like for me to calculate runrate, I'd have to know the bar number of the anchors. However, the DrawOnBar of the trend anchors always returns -2147483648
-
Sometimes the trend channel anchors are in an area where no bars exists. Is there a way around this?
Comment
-
Seems like even on channels where it is on bars, it still doesn't return the bar. However, I'll need to be able to do the projection without it having to touch bars, since not all channels will be touching bars, like in the pic above.
Comment
-
Hello shildebrand324,
There would be no way around this. NinjaTrader cannot provide bar number or times of bars that do not exist.
I recommend that you move the anchors to all be within the bars on the chart.
As a heads up, you will also see approximations when restoring manually drawn objects from workspace. The price and time of the anchor may change when restored.Chelsea B.NinjaTrader Customer Service
Comment
-
That would be impossible on some channels, especially on ranges, like above. Is there not another way I can tell if I have a bar touching a line, except through projection?
Comment
-
Hello shildebrand324,
I am not aware of any other way other than by looking at the bar information, price and time, of the drawing object anchors (which move with the bars as you adjust the chart).
Drawing objects in the blank space to the right of the chart is basically unsupported through ninjascript.
Below is a link to a forum thread where this is discussed.
Chelsea B.NinjaTrader Customer Service
Comment
-
Yeah, I'm not really concerned about the blank space to the right of the chart. I just need to know if a drawing object is touching the current bar. I know this is possible, because I've seen indicators do it before.
So, you're telling me there's no way for me to know if the current bar is touching a line that NT has on the chart?
Comment
-
Hello shildebrand324,
Only if the drawing object has the anchors within the chart bars.
They can project out into the blank space with the Extend lines right option, but the anchors must be within the chart bars we can get numbers for.
If the drawing object is within the chart bars the formula is:
slope between anchors = (anchor2price - anchor1price) / (anchor2bar - anchor1bar)
(slope = (y2 - y1)/(x2 - x1))
yintercept = slope * (CurrentBar - anchor1bar)
(yintercept = slope * (x2 - x1))
Then you can check if the yintercept is equal to the current bar close, or within a tick or within the high and low, or whatever you would like.
Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
Even when I have a channel start/end, my drawonbar still comes up with -2147483648. What could be the issue?
Comment
-
Hello shildebrand324,
May I have a reduced copy of the script? Remove everything except the DrawObjects loop, the condition for draw type, the cast, and the print for the anchor .DrawnOnBar.
To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:- Click Tools -> Export -> NinjaScript...
- Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
- Click the 'Export' button
- Enter a unique name for the file in the value for 'File name:'
- Choose a save location -> click Save
- Click OK to clear the export location message
- (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
http://ninjatrader.com/support/helpG...-us/export.htm
Once exported, please attach the file as an attachment to your reply.Chelsea B.NinjaTrader Customer Service
Comment
-
This is the loop in OnBarUpdate(). Is that all you need?
foreach (DrawingTool draw in DrawObjects)
{
if (draw is DrawingTools.TrendChannel)
{
TrendChannel channel = draw as DrawingTools.TrendChannel;
double parallelEndAnchorPrice = channel.ParallelStartAnchor.Price + (channel.TrendEndAnchor.Price - channel.TrendStartAnchor.Price);
Print("Tag: " + draw.Tag + " Start Price: " + channel.TrendStartAnchor.Price + " End Price " + channel.TrendEndAnchor.Price + " Start Bars Ago: " + channel.TrendStartAnchor.DrawnOnBar + " End Bars Ago: " + channel.TrendEndAnchor.DrawnOnBar);
Print("Tag: " + draw.Tag + " Parallel Start Price: " + channel.ParallelStartAnchor.Price + " End Price " + parallelEndAnchorPrice + " Start Bars Ago: " + channel.ParallelStartAnchor.DrawnOnBar);
}
}
- Likes 1
Comment
-
-
Hello shildebrand324,
So DrawnOnBar 'Gets the absolute bar index value that a NinjaScript object drew the chart anchor.
Meaning, this only applies to NinjaScript drawn anchors.
(As a heads up, DrawnOnBar is not a bars ago value and is a bar number.)
But the TrendStartAnchor.SlotIndex will work instead.
(or Bars.GetBar(channel.TrendStartAnchor.Time))Chelsea B.NinjaTrader Customer Service
Comment
-
Very good. How would I get Bars.GetBar(channel.TrendStartAnchor.Time) for ParallelEndAnchor.Time, since ParallelEndAnchor doesn't exist?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
603 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
349 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
104 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
560 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment