Login Page - Create Account

Support Board


Date/Time: Thu, 25 Apr 2024 08:05:33 +0000



[Programming Help] - Help with Alert Formula on Engulfing Candle Crossing Horizontal Line or w/in 1% of line

View Count: 834

[2021-07-26 22:02:25]
Midas003 - Posts: 9
Could someone please help with this alert formula, I keep trying different things but i am stuck.

I have Horizontal lines (drawn Manually on my chart), i would like an alert for when:

1.) A Bearish Engulfing candle appears at Less than or Equal to 1% of where the horizontal line is (basically Within 1% of the Horizontal line), or when the bearish engulfing candle crosses and closes below the horizontal line

2.) A Bullish engulfing candle appears at Less than or Equal to 1% of where the horizontal line is (basically Within 1% of the Horizontal line), or when the Bullish engulfing candle crosses and closes above the horizontal line

Edit: I realize I have to use the Horizontal Line Indicator , rather than manual Horizontal line. Currently, I applied the Horizontal Line Indicator to my chart and set my alert there. My candle patter Bullish (ID6.sg1), Bearish (ID6, Sg2), so, this is what i have so far, is this correct or am i missing somthing:

=OR(ID6.SG1<=0.01, CROSSOVER(C, ID6.SG1), ID6.SG2<=0.01, CROSSOVER(C, ID6.SG2))

I attached a pic to give a visual Idea for the Bullish Engulfing Scenario (I hope it is clear enough)
I'd really appreciate any help i can get, Thank you
Date Time Of Last Edit: 2021-07-26 23:24:33
imageScreenshot (4).png / V - Attached On 2021-07-26 21:47:59 UTC - Size: 3.86 KB - 216 views
imageScreenshot (5).png / V - Attached On 2021-07-26 21:48:07 UTC - Size: 4.7 KB - 188 views
[2021-07-27 12:23:43]
Sawtooth - Posts: 3976
What is the ID# of the Horizontal Lines study you are using?

Are you using SG1 of that study for the line?
[2021-07-27 14:56:35]
Midas003 - Posts: 9
the ID# for the Horizontal Line study is ID7

No, i didnt use the SG1 of the Line study.

I thought by adding the alert in the Horizontal line study alert I wouldn't have to reference the SG#'s for the line nor ID7 when referencing the horizontal line. Also, i use multiple lines which would mean multiple SG#'s?

I am completely new at this
[2021-07-27 19:45:32]
Sawtooth - Posts: 3976
I thought by adding the alert in the Horizontal line study alert I wouldn't have to reference the SG#'s for the line
If the alert formula is on the Alerts tab of the Horizontal line study, you can optionally omit its ID#, but not the SG#.
It is a good practice to always include the ID#, even if you don't need to.
You must always include the ID#.SG# of other studies.

Also, I use multiple lines which would mean multiple SG#'s?
Yes. Each SG# needs to be referenced.

Neither of your example pics show engulfing candles.

It's not clear exactly what alerts you want.
- Are your alerts intrabar or only at close of bar?
- Must the Last price be within +/- 1% of the horizontal line?
- Can the Close be outside the +/- 1% band if it crossed the horizontal line?
[2021-07-27 22:29:01]
Sawtooth - Posts: 3976
I think this is what you want:

=OR(
AND(H>=ID7.SG1*0.99,L<=ID7.SG1*1.01,ID6.SG1=3,CROSSFROMBELOW(C,ID7.SG1)),
AND(H>=ID7.SG1*0.99,L<=ID7.SG1*1.01,ID6.SG2=4,CROSSFROMABOVE(C,ID7.SG1)))

This will alert when any part of the bar is within the 1% +/- band of the Horizontal Lines SG1 line,
and the Close has crossed above or below the Horizontal Lines SG1 line,
and the Candlestick Pattern is either Bullish Engulfing or Bearish Engulfing.

You would need to replicate this formula for each horizontal line, combining them with another OR(
There is a character limit to Simple Alert formulas, which you would probably exceed with multiple lines.

Since you have multiple lines, this would be much easier to do with the Spreadsheet System/Alert study.
Date Time Of Last Edit: 2021-07-27 23:39:46
[2021-07-27 22:34:28]
Midas003 - Posts: 9
With the picture i was trying to show more of what i meant in terms of the candle position in relation to the horizontal line (the pink line in the picture), so in the case where the candle opens within 1% of the horizontal line & when the candle close crosses above the horizontal line.

- I would like to be alerted only at the close of bar
- In relation to the bar, sorry, i should have originally specified that i would like for the Opening price of the said engulfing candle to be what is within within 1% of the horizontal line and not the close of the candle.
- Yes, the candle close can be outside +/-1% if it crosses the horizontal line
[2021-07-27 22:44:04]
Midas003 - Posts: 9
Thank you!!!!

I have a few questions
1) I see there is no reference to ID6.SG2, which references my bearish engulfing. does it not matter?
2)To reference my other horizontal lines for instance ID7.SG2 would this format be correct?
=OR(
AND(H>=ID7.SG1*0.99,L<=ID7.SG1*1.01,ID6.SG1=3,CROSSFROMBELOW(C,ID7.SG1)),
AND(H>=ID7.SG1*0.99,L<=ID7.SG1*1.01,ID6.SG1=4,CROSSFROMABOVE(C,ID7.SG1))),
OR(
AND(H>=ID7.SG2*0.99,L<=ID7.SG2*1.01,ID6.SG1=3,CROSSFROMBELOW(C,ID7.SG2)),
AND(H>=ID7.SG2*0.99,L<=ID7.SG2*1.01,ID6.SG1=4,CROSSFROMABOVE(C,ID7.SG2)))

I am new on sierra chart, so i have to go look up how to do this with the Spreadsheet System/Alert study as you recommended.

Thank you so much for your patience and help :)
[2021-07-28 00:04:33]
Sawtooth - Posts: 3976
I see there is no reference to ID6.SG2, which references my bearish engulfing. does it not matter?

1) You found a typo I made, sorry about that.
I corrected the formula in post #6 to this:
=OR(
AND(H>=ID7.SG1*0.99,L<=ID7.SG1*1.01,ID6.SG1=3,CROSSFROMBELOW(C,ID7.SG1)),
AND(H>=ID7.SG1*0.99,L<=ID7.SG1*1.01,ID6.SG2=4,CROSSFROMABOVE(C,ID7.SG1)))

2) To do two lines:
=OR(
OR(
AND(H>=ID7.SG1*0.99,L<=ID7.SG1*1.01,ID6.SG1=3,CROSSFROMBELOW(C,ID7.SG1)),
AND(H>=ID7.SG1*0.99,L<=ID7.SG1*1.01,ID6.SG2=4,CROSSFROMABOVE(C,ID7.SG1))),
OR(
AND(H>=ID7.SG2*0.99,L<=ID7.SG2*1.01,ID6.SG1=3,CROSSFROMBELOW(C,ID7.SG2)),
AND(H>=ID7.SG2*0.99,L<=ID7.SG2*1.01,ID6.SG2=4,CROSSFROMABOVE(C,ID7.SG2))))

You can see that multiple lines will make this formula lengthy and unwieldy.
With the Spreadsheet System/Alert study, you would put each line's formula in its own column (O-BR), then combine them with an OR(...) in another column (K).
You could have up to 56 line formulas, or you could split the alerts between buy and sell and have up to 28 each.
If you want me to build this for you for a fee, contact me here:
https://www.sawtoothtrade.com/contact.html
[2021-07-28 00:20:37]
Sawtooth - Posts: 3976
i would like for the Opening price of the said engulfing candle to be what is within within 1% of the horizontal line
In this case, edit the formula, replacing every H and L with O.
Date Time Of Last Edit: 2021-07-28 00:25:32
[2021-07-28 03:19:25]
Midas003 - Posts: 9
Thank you for taking out time to respond!!!!

Ill try this out and see how it works, if it works well for what i had in mind ill probably contact you through your link to help out with the spread sheet.

I have a question regarding the formula you wrote, you have "ID6.SG1=3" & "ID6.SG2=4" which both refer to the Candlestick pattern finder, why 3&4?
I ask just in case i need to tweak the formula a bit, so for instance if i want to add one more Candle stick finder with ID6.SG3 would it be ID6.SG3=5???
[2021-07-28 11:53:30]
Sawtooth - Posts: 3976
you have "ID6.SG1=3" & "ID6.SG2=4" which both refer to the Candlestick pattern finder, why 3&4?
Those are what the study outputs for Bullish Engulfing and Bearish Engulfing.
They are the 3rd and 4th choices listed when you choose the pattern.
Using the specific output instead of >0 allows the formula to differentiate between patterns.

so for instance if i want to add one more Candle stick finder with ID6.SG3 would it be ID6.SG3=5?
5 is Dark Cloud Cover because it is the 5th in the list, but the value might not always correspond.
If you set 'Use Numeric Values Instead Of Letter Codes' to Yes, you can see the number at the bar where the pattern occurs.

Refer to:
CandleStick Patterns Finder
[2021-07-28 16:07:35]
Midas003 - Posts: 9
Got it!!
Once again, thanks for all your help :)
[2021-07-30 02:34:17]
Midas003 - Posts: 9
Hello,
So sorry, but i have got another question. If i want to tweak the percentage in the formula, for example from within 1% to say 5%, would this be the right numbers to tweak:

=OR(
AND(H>=ID7.SG1*0.95,L<=ID7.SG1*1.05,ID6.SG1=3,CROSSFROMBELOW(C,ID7.SG1)),
AND(H>=ID7.SG1*0.95,L<=ID7.SG1*1.05,ID6.SG2=4,CROSSFROMABOVE(C,ID7.SG1)))

Again i Appreciate all your help :)
[2021-07-30 02:40:23]
Sawtooth - Posts: 3976
Yes.

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

Login

Login Page - Create Account