Login Page - Create Account

Support Board


Date/Time: Fri, 07 Feb 2025 17:46:01 +0000



[Programming Help] - Help with a simple alert

View Count: 634

[2021-05-26 11:42:55]
jsmanuse - Posts: 32
I am seeking help with an alert that can measure 2 bars - comparing the current to the previous bar:

If the current bar has a higher high AND a higher low AND the close is farther from the high than the previous bar AND the range of the current bar is greater than the previous bar - then this is true.

OR

If the current bar has a lower low AND a lower high AND the close is farther from the low than the previous bar AND the range is greater than the previous bar - then this is true.

I know this is like kindergarten coding for some of you... but I am just not talented in that stuff.. thanks in advance!
[2021-05-26 12:02:30]
Sawtooth - Posts: 4173
Here is the formula for the first half:
AND( H > H[-1] , L > L[-1] , H-C > H[-1]-C[-1] , H-L > H[-1]-L[-1] )

Here's the documentation for Simple Alerts:
Study/Chart Alerts And Scanning: Alert Condition Formula Format

I'm challenging you to create the second half by yourself.

Then combine both halves with OR(AND(...),AND(...))

Let me know if you need more help.
Date Time Of Last Edit: 2021-05-26 12:11:28
[2021-05-27 00:46:52]
jsmanuse - Posts: 32
Thanks Tom. I'm going to give it a go - and I'll post my final results here. Hope I don't sprain my brain..
[2021-05-27 01:00:26]
jsmanuse - Posts: 32
...your part works...

mine, not so much:

AND( H > H[-1] , L > L[-1] , H-C > H[-1]-C[-1] , H-L > H[-1]-L[-1] )
OR(AND( L < L[-1] , H < H[-1] , L-C > L[-1] - C[-1] , H-L > H[-1]-L[-1])

.. not sure where I'm wrong.
[2021-05-27 03:48:40]
Sawtooth - Posts: 4173
You are almost there.

- You have correctly reversed the operators in the first two segments. (You didn't need to swap the Ls and the Hs, but it works both ways.)

- You correctly made no changes to the fourth segment, since H-L always returns the bar's range.

- Regarding the third segment: The C is always greater, or equal, to the L, so you need to subtract L from C.
(You'll get a negative number result with L-C.)
So swap the Ls and Cs in the third segment of the formula.

- Put the OR first, then each AND separated with a comma, like this: OR(AND(...),AND(...))
IOW, the OR surrounds both ANDs.
[2021-05-27 10:26:56]
jsmanuse - Posts: 32
OR(AND(H > H[-1] , L > L[-1] , H-C > H[-1]-C[-1] , H-L > H[-1]-L[-1] ),AND( L < L[-1] , H < H[-1] , C-L > C[-1]-L[-1] , H-L > H[-1]-L[-1]))


With your help... I got it! I think this works. I'll be checking... thank you so much for your consideration and help. !
[2021-05-27 12:04:39]
Sawtooth - Posts: 4173
Yes, that's it.

You can use the Color Bar Based On Alert Condition study to visually see where the alerts are true.

You could use two instances of the color bar study to separately see each alert, using each AND formula.
(You wouldn't need the OR when separating them.)

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

Login

Login Page - Create Account