if (Count - 2 == CurrentBar)
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Help with modifying the Stock ZigZag indicator.
Collapse
X
-
Thanks Ryan. But the above doesn't seem to plot anything to the output window? The problem is the statement I've attached, it is never evaluated as true, so the loop is never executed. I'm not sure I understand it's function either?Code:
-
It's designed to run only on the last bar of the chart, and works only when CalculateOnBarClose is true.
You don't have to use it necessarily. It's there mainly to show that the best way to get meaningful historical swing/zig zag values is with those functions .HighBar and .SwingHighBar.
Since the actual values of the indicator change as new bars develop, these dedicated methods are critical to capture values of specific swing/zig zag instances.Ryan M.NinjaTrader Customer Service
Comment
-
I appreciate the help Ryan!
But I am still having a hard time capturing the values that store the swing points.
What would be nice, is that anytime the zz confirms a swing, i.e. if it moves off of a low by more than the deviation value set, that low is in place.
Would it be difficult to then store that swing value and timestamp in an ArrayList for example?
Comment
-
That is exactly how you do it. Create a struct to hold the bar time/number, the swing value, and type (high or low). After each swing point is established, populate the struct, and store it in an Arraylist.Originally posted by forrestang View PostI appreciate the help Ryan!
But I am still having a hard time capturing the values that store the swing points.
What would be nice, is that anytime the zz confirms a swing, i.e. if it moves off of a low by more than the deviation value set, that low is in place.
Would it be difficult to then store that swing value and timestamp in an ArrayList for example?
Comment
-
I am working on that. Problem is I am having a difficult time understanding how this script works, and actually getting those swing values/timestamps.Originally posted by koganam View PostThat is exactly how you do it. Create a struct to hold the bar time/number, the swing value, and type (high or low). After each swing point is established, populate the struct, and store it in an Arraylist.
Comment
-
What technique are you using currently? I would try to get a basic example working, where you access 1 historical instance of a zig zag high using .HighBar method.
These indicators change values as new bars develop, so you'll only get meaningful results using these dedicated methods. If you try to access the current value of these using the general indicator functions, this won't match what you see on your chart.
Maybe it will help if you think of it like this: Pick a point on your chart where you want to get instances of zig zag high. The function .HighBar only looks to the left of this point. Use the instance field of .HighBar to return a meaningful "barsAgo" value that identifies how many bars ago (from the point on the chart you select) that the zig zag high occurred. The 1st instance is the one closest to the point you select.Last edited by NinjaTrader_RyanM1; 11-11-2011, 12:13 PM.Ryan M.NinjaTrader Customer Service
Comment
-
Ok, will work on that. As is now, I have a script gathering a bunch of other info about the day. I only tell it to run on the last bar of the session. So yes, for now I just need to figure out how to make it go back and find a swing point/time.Originally posted by NinjaTrader_RyanM View PostWhat technique are you using currently? I would try to get a basic example working, where you access 1 historical instance of a zig zag high using .HighBar method.
These indicators change values as new bars develop, so you'll only get meaningful results using these dedicated methods. If you try to access the current value of these using the general indicator functions, this won't match what you see on your chart.
Maybe it will help if you think of it like this: Pick a point on your chart where you want to get instances of zig zag high. The function .HighBar only looks to the left of this point. Use the instance field of .HighBar to return a meaningful "barsAgo" value that identifies how many bars ago (from the point on the chart you select) that the zig zag high occurred. The 1st instance is the one closest to the point you select.
Comment
-
Ok, I got it to print the swing level and the time of ONE INSTANCE of a swing with:
Now need to come up with a loop to print or store all these starting at the end of day, as each day could have a different number of swings.Code:int zzHigh1 = Math.Max(0, HighBar(0, 2, Bars.BarsSinceSession)); Print(Time[0].ToString() + " " + High[zzHigh1] + " " + Time[zzHigh1]);
Last edited by forrestang; 11-11-2011, 12:34 PM.
Comment
-
So this loop will count backwards and plot swing highs.
Only problem is that it will count only the input number. Anything over that, and it just starts printing useless values.
So this loop somehow needs to say stop counting when I get to a point. In my case the begining of the session.
Code:for (int x = 5; x > 0; x--) //Prints the last 10 instances of swing. runs on last bar. { int zzHigh1 = Math.Max(0, HighBar(0, x, Bars.BarsSinceSession)); Print(Time[0].ToString() + " " + High[zzHigh1] + " " + Time[zzHigh1]); }
Comment
-
For that you may be better off using a while loop.Originally posted by forrestang View PostSo this loop will count backwards and plot swing highs.
Only problem is that it will count only the input number. Anything over that, and it just starts printing useless values.
So this loop somehow needs to say stop counting when I get to a point. In my case the begining of the session.
Code:for (int x = 5; x > 0; x--) //Prints the last 10 instances of swing. runs on last bar. { int zzHigh1 = Math.Max(0, HighBar(0, x, Bars.BarsSinceSession)); Print(Time[0].ToString() + " " + High[zzHigh1] + " " + Time[zzHigh1]); }
Comment
-
Great you're making progress. Looks like the next step is counting the number of occurrences in a session. Bars.BarsSinceSession makes a suitable lookback for this, and can work with return value of -1 at the point no ZigZag highs are found. Since you don't know the number of zig zags there will end up being, it makes more sense to start the loop at 1 and increment rather than the other way around. Once you have the values could work with them any way you like though.
I was able to come up with this which seems to work pretty well. LastBarOfSession is not supported but I don't see any issues with it here.
Code:#region Variables private int myBarsAgo; #endregion if (Bars.LastBarOfSession) { DrawTriangleDown("lastBarOfSession" + CurrentBar, true, 0, High[0], Color.Green); int numberOfZigs = 0; for (int x = 1; x != 0; x++) { numberOfZigs++; if( x >= 1) myBarsAgo = ZigZag(DeviationType.Points, 0.5, false).HighBar(0, x, Bars.BarsSinceSession + 1); Print("Instance " + x + " " + myBarsAgo); Print("numZigs " + numberOfZigs); if(myBarsAgo == -1) x = -1; } }Ryan M.NinjaTrader Customer Service
Comment
-
Thanks for all the advice guys.
I think I've mostly got the things I need to see on the chart working.
I spent some time going over the script and understanding what it was doing. I managed to find the portion that controls the reversal, and used the HighBar() to look at the prior instance.
So I am able to calculate the swings as they appear. Woot!
Now I just need to learn about Storing in an ArrayList, as I will need some custom outputting to fit the format of an excel sheet. Now I'm pretty much using Print() commands, manually saving that to a text file, then importing into excel.
Is exporting to excel supported in some way?
Comment
-
You could write to a file using stream writer like in this sample:Originally posted by forrestang View PostThanks for all the advice guys.
Is exporting to excel supported in some way?
Could also see this thread for some ideas on Excel dde link:
Ryan M.NinjaTrader Customer Service
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