Plot percent difference between fastLength and slowLength (MACD)


Tags:
Category:
0
1

I’m looking to create an indicator for MACD that tells me when the numerical value for the fastLength is around 10% from the slowLength; both +10% (when trending positive to negative) and -10% (trending negative to positive)

In short, I want to create an indicator that shows me the following circled points:

Thanks!

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on June 15, 2017 10:53 pm
218 views
0

Very good that you provided the screenshot, thanks. I see that in addition to your +/-10%, you are only wanting to pick when that value occurs BEFORE a cross and not after. Is this correct?

( at June 16, 2017 8:00 am)
0

Yes sir, that’s exactly what I’m hoping for!

( at June 16, 2017 8:20 am)
0
Private answer

Ok after clarifying one small piece of the specifications we have what we need in order to complete the code. I see from the question that an indicator is being requested. However this has been posted in the Stock Scanner topic so I will present here the Scan version of the solution. Screenshot included to show how the Scan is able to identify signals.

input percentDiff = 10.0;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
def Diff = Value - Avg;
def tenPercentLower = Avg * (1 - percentDiff * .01);
def tenPercentHigher = Avg * (1 + percentDiff * .01);
def withinTenPercent = (Value >= tenPercentLower and Value < Avg) or (Value <= tenPercentHigher and Value > Avg);
plot scan = withinTenPercent and !withinTenPercent[1];

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 17, 2017 1:18 pm
0

Thank you very much, I really appreciate it!

( at June 17, 2017 2:05 pm)
0

Hey Pete, what would I need to do if I wanted to extend the scanner to include items BELOW? Since this only covers above.

Thank you!

( at June 19, 2017 6:20 pm)
0

I think when you say Below, you are talking about the zeroline? If so, there is nothing in the code that references the zeroline. These signals are picked up regardless of their position above or below the zero line.

( at June 19, 2017 6:23 pm)