Login Page - Create Account

Support Board


Date/Time: Mon, 08 Sep 2025 21:02:14 +0000



[Programming Help] - Issue using AVERAGE function to compare delta to previous values

View Count: 135

[2025-08-12 12:06:15]
LongShortz - Posts: 21
Okay hopefully I can ask this clearly. I'm having trouble writing an alert using the AVERAGE function. I'm not using a spreadsheet for this. Just using logic in the 'Color Bar By Alert Condition' study. What I'm looking for is to run a comparison of the delta on the current candle (SG1 on the Numbers Bars Calculated Values) to the average delta on the previous 4 candles. The goal is to identify where strong opposition is entering the market for a reversal setup. So for the portion of the logic pertaining to this, I used the below.

=AND(ID5.SG1 < (=AVERAGE(ID5.SG1[-1:-4]) * -2)

I believe this says: The current delta must be less than the average of the previous 4 candles delta times negative 2.

There are other criteria in the overall formula but I've proven those to work already. But just to be safe, I removed all other portions of the formula leaving only the above and it still did not work. To be clear, if the alert fired successfully, it would be highlighted in a white outline.

Image uploaded. https://www.sierrachart.com/image.php?Image=1755000120869.png
[2025-08-12 13:23:15]
User431178 - Posts: 772
=AND(ID5.SG1 < (=AVERAGE(ID5.SG1[-1:-4]) * -2)
This errors due to the extra = prior to the average

=ID5.SG1<(AVERAGE(ID5.SG1[-1:-4])*-2)
This seems to work as expected, see image.
- Grey bar = condition met
- value on high = delta
- value on low = delta[-1:-4] * 2
imagealert.png / V - Attached On 2025-08-12 13:19:55 UTC - Size: 127.9 KB - 22 views
[2025-08-12 14:55:17]
LongShortz - Posts: 21
So I thought the same thing but when I had the = in there, it did not give me a syntax error so it led me to believe it was acceptable. Before you wrote back, I had taken the = and it didn't light up but I must've done something wrong because now that I've read your post, I went back, verified everything, and it is now working. So seems like user error. Thanks a lot for lab'ing it up for me. Cheers!
[2025-08-12 15:27:45]
LongShortz - Posts: 21
I gotta ask tho.... how did you get those values to appear like that?
[2025-08-12 15:45:29]
User431178 - Posts: 772
Assuming that calc values study is ID5, as in your earlier post.

For average:
Spreadsheet Formula

Where formula input is set to this.
=AVERAGE(ID5.SG1[-1:-4])

Display in region 1, and set draw style to Value on Low


For delta:
Study Subgraph Reference

Where referenced subgraph is set to ID5.SG1.
Display in region 1, and set draw style to Value on High


There are other ways too, but that it what was in the image I showed.
Date Time Of Last Edit: 2025-08-12 15:45:43

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

Login

Login Page - Create Account