I would like to know if there are any examples you can point me to where a script can theoretically keep adding/drawing lines on a chart if certain conditions are met. Say for instance, if 3 bars back to back have Higher Highs and Lows, draw a line form Low[3] to High[1]. Then if 3 more bars pass and they are consecutive Lower Highs and Lows, draw a line from High[3] to Low[1]. The drawings will keep being added onto the screen every time those conditions are met.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Having script theoretically add infinite lines if certain conditions are met.
Collapse
X
-
Having script theoretically add infinite lines if certain conditions are met.
Hello,
I would like to know if there are any examples you can point me to where a script can theoretically keep adding/drawing lines on a chart if certain conditions are met. Say for instance, if 3 bars back to back have Higher Highs and Lows, draw a line form Low[3] to High[1]. Then if 3 more bars pass and they are consecutive Lower Highs and Lows, draw a line from High[3] to Low[1]. The drawings will keep being added onto the screen every time those conditions are met.Tags: None
-
Hello Don22Trader1,
Thank you for your post.
I would like to start out by warning that a script that adds and accumulates drawing objects would become more resource-intensive over time and could lead to performance issues. Depending on the scenario, rendering lines with custom graphics in OnRender() may be a more performance-friendly option. For more information, please see the section "Using DrawObjects vs custom graphics in OnRender()" on the best practices page here:
https://ninjatrader.com/support/help...s.htm#Performa nce
In order to create new draw objects of the same type, a unique tag is needed in the Draw() method. If you use the same tag, the script will just modify the same draw object. The following snippet uses a unique tag each time so that each time the condition is true, a new line is drawn rather than modifying an existing line:
For more information on the Draw.Line() method:Code:protected override void OnBarUpdate() { if (CurrentBar < 3) return; // if the last two completed bars have higher highs and lows than the preceding bar, draw a line from Low[3] to High[1] if (High[1] > High[2] && Low[1] > Low[2] && High[2] > High[3] && Low[2] > Low[3]) Draw.Line(this, "higherLine" + CurrentBar.ToString(), 3, Low[3], 1, High[1], Brushes.Blue); // if the last two completed bars have lower highs and lows than the preceding bar, draw a line from High[3] to Low[1] if (High[1] < High[2] && Low[1] < Low[2] && High[2] < High[3] && Low[2] < Low[3]) Draw.Line(this, "lowerLine" + CurrentBar.ToString(), 3, High[3], 1, Low[1], Brushes.Blue); }
This example could also be achieved in the Strategy Builder, and then you could click the "View Code" button to see what it would look like if it were coded manually in an unlocked script. You would set up a condition that makes price data comparisons, then an action to draw the line. For examples of those types of conditions and actions (and more) in the Strategy Builder:
Please let us know if we may be of further assistance.
- Likes 1
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
561 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
325 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
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment