Login Page - Create Account

Support Board


Date/Time: Sat, 11 May 2024 21:30:45 +0000



[Programming Help] - How to look back x number of bars

View Count: 1008

[2020-10-12 01:51:28]
User561641 - Posts: 4
I've done extensive searching and can't seem to figure out the right syntax to do something like this:

Let's say I have 2 indicator studies on a chart and both always produce positive numbers.
ID1.SG1
ID2.SG1
Now if I want to get the value of say ID1.SG1 from three bars back, I'd reference it like this: ID1.SG1[-3].
But, if I want to get the value of ID1.SG1 from the number of bars back based on the current value of ID2.SG1 I'd logically do it like this: ID1.SG1[-ID2.SG1]. This produces a syntax error. How do I achieve this?
[2020-10-12 02:59:35]
Sawtooth - Posts: 3995
if I want to get the value of ID1.SG1 from the number of bars back based on the current value of ID2.SG1 I'd logically do it like this: ID1.SG1[-ID2.SG1]. This produces a syntax error. How do I achieve this?
What you want to do is not supported in Simple Alerts. You would need to use one of the 3 spreadsheet studies, with a formula like this in row 3 of a Formula Column (K-Z):
=OFFSET(ID1.SG1@3,ID2.SG1@3,0)
[2020-10-13 20:55:02]
User561641 - Posts: 4
Thanks for the response, what you suggested, did indeed work. I created several similar formulas in the Formula Columns. But, when I create an "color background on alert condition" and reference these formulas via spreadsheet columns (K3, L3, M3, etc), the alert doesn't trigger (meaning it doesn't decorate the price bar) even though the values evaluate to true. I do something super simple like an alert on "=AND(K3 > L3, L3 > M3)" for example, and even though the values in those columns on record 3 do result in a true return, the chart doesn't decorate because the alert doesn't return true. I literally have to add a constant like this for the alert to decorate: "3 > 1". I don't get it... is there caching going on or something?
[2020-10-13 23:28:53]
Sawtooth - Posts: 3995
I do something super simple like an alert on "=AND(K3 > L3, L3 > M3)"
If you want an alert from a spreadsheet's Formula Column, which is a subgraph, use the Spreadsheet System/Alert study.
Then put that formula in another Formula Column, and then set its Draw Style to Background.
No need to use the color background study.

But if you want to use the Color Background Based On Alert Condition study, you'll need to reference the spreadsheet's ID# and its Formula Column subgraph:
=AND(ID1.SG1 > ID1.SG2, ID1.SG2 > ID1.SG3)
-where ID1 is the spreadsheet study.

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

Login

Login Page - Create Account