Login Page - Create Account

Support Board


Date/Time: Thu, 13 Nov 2025 08:00:14 +0000



Question on Zig Zag codes for alert conditions

View Count: 275

[2025-09-25 18:49:06]
LongShortz - Posts: 26
Let me see if I can articulate this......

What I am trying to do is use two zig zags for structural analysis. Basically I'm using a smaller range zig zag to confirm trends on the higher range zig zag. I'm not a great coder so for this I am just using a 'Color Bar Based on Alert Condition' indicator to find structural entries with strong delta confirmation. Those structural entries would be identified wherever the higher range has already set a lower high and the lower range is confirming with its own lower high (or vice versa for longs). The problem I'm running into is that the confirmation on the lower range is almost never going to be in the same place as the higher ranges structural swing. Is there a way to configure a statement in the indicator that looks at whatever the last swing value was on the higher range?

Below is an example line of code that I might use for something like this. ID14 and ID35 are the low and high range zig zags respectively. The code value 3 represents higher low. However, this statement would require both zig zags to throw a value of 3 on the same candle. What I need is a way to say "ID35.SG2's last know value was 3" no matter how far back that value was thrown.

If what I've written above makes sense (LOL), is there a way to do this?

AND(ID5.SG1 > 500 , ID14.SG2 = 3 , ID35.SG2 = 3 , C > O)
[2025-09-25 19:55:07]
John - SC Support - Posts: 42965
You need to use the "Spreadsheet Study" to bring the most recent value of the Zig Zag Text Labels forward in time. To do this enter the following formula into one of the calculation columns row 3:
=MOSTRECENTNONZEROVALUE(ID1.SG2@3:ID1.SG2@2000)

This will look through the last 2000 bars and copy the value of the Text Label into each cell where it was previously zero.

Then you can use this in your formula by checking the current bar to see if it has the text value you want.

Refer to the following:
https://www.sierrachart.com/index.php?page=doc/SpreadsheetFunctions.html#MOSTRECENTNONZEROVALUE_Function
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2025-09-28 17:01:05]
LongShortz - Posts: 26
Thanks John this definitely helps. But still in a jam. What happens is this:

Let's say I have a threshold of 75 point movement in order to lock in a swing. This is calc mode 2. I'm in the middle of an upswing off of a HL and price moved up 80 points locking in that upswing. Then the market pulls back 25 points. While it is pulling back, the ZZ is marking the top of that 80 point upswing as a LH even though we haven't moved 75 points back down off of that level. So I'm temporarily receiving a LH code even though technically I'm still working off of a HL.

At this point, on the low range I have set a new HL to confirm the high range structure. But since I'm temporarily receiving a LH code from the high range, my logic is busted and it doesn't fire the signal.

So my question is this, instead of getting the MOSTRECENTNONZEROVALUE, is it possible to get what the value was before the most recent? I tried finding a way to do this but couldn't figure it out. Thanks for the help.
[2025-09-29 01:55:23]
Sawtooth - Posts: 4287
is it possible to get what the value was before the most recent?
Here's an example:
Spreadsheet Example Formulas and Usage: Return Last Two Zig Zag Reversal Values
[2025-09-29 12:20:30]
LongShortz - Posts: 26
Thanks. I found that after I submitted the ticket and was able to get that working. But still having trouble. It seems that current calculations change the calculus for the entire sheet. I'm looking to be able to keep my signals on the screen indefinitely once they've triggered for more effective back testing. Basically, I want the sheet and the chart to reflect what was real at that point in time. But what I'm finding is: (assume bullish for example)

** I have two zig zags. One is a higher range than the other. I'm looking for the lower range to confirm the higher range with confluences to fire a signal **

1. Price moves up off of a higher low and exceeds the higher range threshold which locks in that we're going to have a new HH
2. From there we get a pullback that does NOT exceed the threshold but is now throwing a 'temporary' HH code even though it isn't confirmed. So if I want to confirm the HL, I have to look back to the second most recent value.
3. At this point the lower range is confirming a HL which matches the higher range HL. With confluence, the signal fires.
4. Now price moves up breaking the previous 'temporary' HH which moves the HH to a point later in time than my signal candle. In doing so, the second most recent value I was basing the signal on is now the most recent value which completely breaks the logic and the signal is erased. But that wasn't the condition in real time.

So therein lies the question. Is there a setting or formula modification or something else that could prevent this from happening?
[2025-09-29 12:59:53]
LongShortz - Posts: 26
Not only does it cause signals to disappear, but it also causes signal to appear in historical locations that don't make any sense.
[2025-09-29 15:50:03]
LongShortz - Posts: 26
I might have it. I think the solution is to basically change the logic to include EITHER the most recent value OR the second most recent value. Only one can ever be true so by enabling them both I can eliminate the shifting structure from impacting past results. I'll have to test forward and backward but I believe that should resolve it. I'm not much of a coder so it is laborious for me to get this far, LOL. I'll ping this post again if I run into anything else.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account