Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
ZigZag Indicator (how to get the number of Peaks and Troughs)
Collapse
X
-
Hello boreland,
Thanks for your post.
The help guide for the ZigAag indicator shows how to specify the ZigZag indicator parameters in Ninjascript and also how to obtain the High Values and the bars ago of those as well as the low values and the low bars ago of those. reference: https://ninjatrader.com/support/help...t8/?zigzag.htm
When you specify the look back period, you can iterate through the number of high or low bar parameter "instances" counting them until you reach a -1 value indicating no more Highs or Lows.
Here is a short example to get your started:
At the class level: private ZigZag myZZ; // create a private instance to use.
In OnStateChange():
else if (State == State.DataLoaded)
{
myZZ = ZigZag(DeviationType.Points, 0.5, false); // initialize the private instance of the indicator
}
In OnBarUpdate():
protected override void OnBarUpdate()
{
if (CurrentBar < 100) // wait for 100 bars before checking 100 bar look back
return;
int highCount = 0; // reset the counter
if (CurrentBar % 100 == 0) // check every 100 bars
{
if (myZZ.HighBar(0, 1, 100) != -1) // if we have Highs (this is a sanity check)
{
for (int i = 1; i < 100; i++) // process the instances, will always be less than 100
{
if (myZZ.HighBar(0, i, 100) == -1) // if this instance is -1 we are done
break;
highCount++; // otherwise increment the counter
}
}
Print (Time[0] +" Last 100 bars Peaks = "+highCount); // report the number of highs found in 100 bar sections
}
Example of output (ES 06-20, 1 minute bars):
4/9/2020 5:56:00 AM Last 100 bars Peaks = 18
4/9/2020 7:36:00 AM Last 100 bars Peaks = 21
4/9/2020 9:16:00 AM Last 100 bars Peaks = 21
4/9/2020 10:56:00 AM Last 100 bars Peaks = 21
4/9/2020 12:36:00 PM Last 100 bars Peaks = 20
4/9/2020 2:31:00 PM Last 100 bars Peaks = 22
4/12/2020 5:11:00 PM Last 100 bars Peaks = 14
4/12/2020 6:51:00 PM Last 100 bars Peaks = 19
4/12/2020 8:31:00 PM Last 100 bars Peaks = 14
4/12/2020 10:11:00 PM Last 100 bars Peaks = 14
4/12/2020 11:51:00 PM Last 100 bars Peaks = 16
4/13/2020 1:31:00 AM Last 100 bars Peaks = 10
4/13/2020 3:11:00 AM Last 100 bars Peaks = 14
4/13/2020 4:51:00 AM Last 100 bars Peaks = 14
4/13/2020 6:31:00 AM Last 100 bars Peaks = 17
- Likes 1
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
560 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