MACD Crossover Alert with Boolean Arrows


0
0

Finding a Macd Crossover below the zero line

Hi Pete,

Referencing the above chart study you wrote. I would like to modify this study and add an alert. In the above study, the request is to have Boolean arrows appear only when the MacD crossover is going from positive to negative below the zero line or when the MaCD crossover occurs above the zero line going from positive to negative. What I would like to do is have Boolean arrows appear for all crosses whether they be above or below the zero line. Along with that I would like an alert to sound at that point the Boolean arrow is true.

Could you modify this code and include the alerts please?

Thank you in advance for all the work you do.

Marked as spam
Posted by (Questions: 6, Answers: 11)
Asked on December 3, 2020 10:50 am
893 views
0
Private answer

For this I will just write a new solution from scratch. Much easier than trying modify a previous solution to fit this request.

Something very important to note about this request. The crossing of the MACD Value plot with the MACD Average plot is the same exact thing as the MACD Histogram crossing above and below zero. That's just the way the MACD is constructed.

Here is the code you requested. "Boolean Arrows" can only be plotted on the upper price graph. So when you requested those it automatically means you want the arrows plotted on the upper price graph as opposed to plotting on the lower MACD study. In the screenshot below I have included two lowers studies of the MACD only so that you can see the arrows on the upper price graph line up with the crossover points you requested.

input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input macdAverageType = AverageType.EXPONENTIAL;
def value = MovingAverage(macdAverageType, close, fastLength) - MovingAverage(macdAverageType, close, slowLength);
def average = MovingAverage(macdAverageType, value, macdLength);
plot crossAbove = value[1] < average[1] and value > average;
crossAbove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot crossBelow = value[1] > average[1] and value < average;
crossBelow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(crossAbove, "MACD Value Cross Above Average", Alert.BAR, Sound.RING);
Alert(crossBelow, "MACD Value Cross Below Average", Alert.BAR, Sound.RING);

Edit: In the comments section below we have a request to convert this code to display on the lower subgraph. I hope this does not break the alerts. Check it out and let us know.

declare lower;
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input macdAverageType = AverageType.EXPONENTIAL;
plot value = MovingAverage(macdAverageType, close, fastLength) - MovingAverage(macdAverageType, close, slowLength);
plot average = MovingAverage(macdAverageType, value, macdLength);
plot zeroLine = 0;
plot crossAbove = if value[1] < average[1] and value > average then value else Double.NaN;
crossAbove.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
plot crossBelow = if value[1] > average[1] and value < average then value else Double.NaN;
crossBelow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Alert(!IsNaN(crossAbove), "MACD Value Cross Above Average", Alert.BAR, Sound.RING);
Alert(!IsNaN(crossBelow), "MACD Value Cross Below Average", Alert.BAR, Sound.RING);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on December 3, 2020 12:47 pm
0
Thank you this is great. My mistake on the "boolean arrows". I hate to ask but could we move the arrows to the MACD from the price graph? Sorry for the irritation.
( at December 3, 2020 1:16 pm)
0
I have updated my answer to provide a version that plots on the lower subgraph.
( at December 3, 2020 5:02 pm)
0
Thank you for the update. Sorry for the initial confusion. I have implemented it and it appears to be working as intended.
( at December 4, 2020 11:37 am)