Message & Sound alert when BollingerPercentB Crosses Above or Below


Category:
0
0

Hi Pete

Do you have a script for Message & Sound alert when BollingerPercentB Crosses Above or Below the 100 or 0 lines – Please see screenshot

PS – I am a past and future Paypal donor and happy to support your great work 🙂

Many thanks

Matthew Therrien

Attachments:
RESOLVED
Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on November 14, 2018 9:39 am
96 views
0

Thank you so much for the fast reply and script. I duly note your comments about my screenshot not being complete enough
My first screenshot on your forum was actually SPX on a Today 30 minute timeframe
Your script works perfect for my needs – being used in conjunction with the TOS standard BollingerBands study.

Hopefully others find it useful

Just sent you a PayPal donation

Best Wishes, Matthew Therrien

( at November 14, 2018 1:06 pm)
0
Private answer

I really appreciate when viewers provide screenshots. So I don’t mean to discourage that practice when I provide some constructive feedback.

  1. Your screenshot lacks any drawings or comments indicating the exact places where you want the alerts to be triggered.
  2. When providing any screenshots, they should include the entire chart and only those studies which fit the context of the question.
  3. Why? Because I will use the screenshot you provide to duplicate that exact view on my side. Then when I write the code I can be very precise in trying to meet your specifications.
  4. For example, look at your screenshot and see if you can tell what ticker symbol has been plotted and what time frame was selected….

Ok, having provided that helpful information I will do my best with what you gave me. I’ll give you an example of why a full chart screenshot is essential. You ask for alerts when the line crosses above or below the 100 or the 0 lines. Now for the zero line that is pretty simple. Cross above or cross below, either one should trigger an alert.

But the 100 line.  Is that any cross of the 100 line? Or is it only a cross above the 100 line? For this solution, I will apply the later.

I will copy/paste the code from the original built-in version so we get all the plots it includes. Then I will add the several lines of code to handle the conditions which trigger the alerts. Since this is a custom chart study, I will be moving this post out of the “Alerts and Notifications” topic and into the “Chart Studies” topic.

Here is full code. Full sized screenshot below shows the result.

declare lower;
input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).LowerBand;
plot PercentB = (price - lowerBand) / (upperBand - lowerBand) * 100;
plot ZeroLine = 0;
plot HalfLine = 50;
plot UnitLine = 100;
PercentB.SetDefaultColor(GetColor(1));
PercentB.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PercentB.SetLineWeight(3);
ZeroLine.SetDefaultColor(GetColor(8));
HalfLine.SetDefaultColor(GetColor(8));
UnitLine.SetDefaultColor(GetColor(8));
#---------- Signals
plot crossingAbove100 = if PercentB[1] < 100 and PercentB > 100 then 100 else Double.NaN;
crossingAbove100.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
crossingAbove100.SetDefaultColor(Color.GREEN);
crossingAbove100.SetLineWeight(3);
plot crossingAboveZero = if PercentB[1] < 0 and PercentB > 0 then 0 else Double.NaN;
crossingAboveZero.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
crossingAboveZero.SetDefaultColor(Color.GREEN);
crossingAboveZero.SetLineWeight(3);
plot crossingBelowZero = if PercentB[1] > 0 and PercentB < 0 then 0 else Double.NaN;
crossingBelowZero.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
crossingBelowZero.SetDefaultColor(Color.RED);
crossingBelowZero.SetLineWeight(3);
#---------- Alerts
Alert(crossingAbove100, "BB% Cross Above 100", Alert.BAR, Sound.RING);
Alert(crossingAboveZero, "BB% Cross Above Zero", Alert.BAR, Sound.RING);
Alert(crossingBelowZero, "BB% Cross Below Zero", Alert.BAR, Sound.RING);

 

 

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on November 14, 2018 11:42 am