Login Page - Create Account

Support Board


Date/Time: Wed, 12 Mar 2025 15:39:56 +0000



Post From: trade alert

[2022-05-10 03:19:29]
Sawtooth - Posts: 4182
Example 8 works if there are no segments of equal value.
Example 9 works if there is no more than one segment of equal value.
This spreadsheet syntax formula works if there are any number of segments of equal value:
Spreadsheet Example Formulas and Usage: Formula that Matches the Slope Coloring of a Study Subgraph Line
(This formula can be converted to Alert syntax, and then used in the Spreadsheet Formula study.)

Try this (this uses a variation of Example 9):
- Add the Spreadsheet Formula study, check Hide Study, and use a formula like this in its Formula field:
=IF(AND(ID1.SG1[0] > ID1.SG1[-1] , ID1.SG1[-1] <= ID1.SG1[-2]) , 1, IF(AND(ID1.SG1[0] < ID1.SG1[-1], ID1.SG1[-1] >= ID1.SG1[-2]) ,-1, ID3.SG1[-1]))
where ID1 is one MA, and ID3 is this Spreadsheet Formula study.
- Duplicate the above Spreadsheet Formula study and edit the formula to this:
=IF(AND(ID2.SG1[0] > ID2.SG1[-1] , ID2.SG1[-1] <= ID2.SG1[-2]) , 1, IF(AND(ID2.SG1[0] < ID2.SG1[-1], ID2.SG1[-1] >= ID2.SG1[-2]) ,-1, ID4.SG1[-1]))
where ID2 is the other MA and ID4 is this Spreadsheet Formula study.

These formulas create a persistent variable where 1 is upsloped and -1 is downsloped.

Buy signal:
=OR(AND(ID3.SG1[-1] = -1 , ID3.SG1 = 1 , ID4.SG1 = 1),AND(ID4.SG1[-1] = -1 , ID4.SG1 = 1 , ID3.SG1 = 1))
Sell signal:
=OR(AND(ID3.SG1[-1] = -1 , ID3.SG1 = 1 , ID4.SG1 = 1),AND(ID4.SG1[-1] = -1 , ID4.SG1 = 1 , ID3.SG1 = 1))