MACD Crossover zero line alert with arrows


0
1

Hello Pete, I found your “MACD Crossover Alert with Boolean Arrows” very helpful however, I want to add a condition to only show Arrows on chart and send Alert when the MACD crosses the zero line to the positive? Appreciate any feedback you can provide.

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);

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on January 25, 2023 1:02 pm
368 views
0
Private answer

I'm surprised this hasn't already been posted. Thanks.

The modifications are extremely minor. Only two lines of code need to be changed and those changes are listed here for those trying to learn:

plot crossAbove = value[1] < 0 and value > 0;

plot crossBelow = value[1] > 0 and value < 0;

Here is the complete solution after those changes have been applied:

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] < 0 and value > 0;
crossAbove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot crossBelow = value[1] > 0 and value < 0;
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);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 25, 2023 1:56 pm
0
Hello Pete, thanks for taking your time to respond, I have one follow up question if I may. I was hoping the arrow is added on the chart anytime MACD crosses to positive not only at zero line but anytime it's above it as well. So say for instant it crosses at .20 or anything positive really. The current setup will not alert in this example since it's only alerting when it crosses the zero line. Thanks again!
( at January 26, 2023 10:43 am)
0
Sorry but I really don't think I understand what you are asking. There are three plots on the MACD and they are named as follows: "Value", "Avg" and "Diff". When describing what you need, it's best to use the proper terms. Especially when we have an indicator which includes three separate plots. If you can't describe it using those terms, then you will have to post a new question and this time include a screenshot showing exactly what you mean.
( at January 26, 2023 10:51 am)