Highest value since MACD crossed 0


Category:
0
0

Hi there,

I was interested in sourcing the highest MACD value, since the signal line crosses the zero line.  My approach was to count the number of bars since the value was over zero, then use the highest function, with the count as the length.  While this approach makes sense to me, it seems the ‘Highest’ function requires a constant, so the count variable doesn’t work.  Is there another approach that works?   Thanks so much. David

def count = if MACD(3, 6, 9, AverageType.EXPONENTIAL).Value is less than 0 then 0 else count[1] + 1;

def highestMACD = Highest(MACD(3, 6, 9, AverageType.EXPONENTIAL).Value[-1], count);

Marked as spam
Posted by (Questions: 8, Answers: 3)
Asked on July 3, 2019 9:07 am
87 views
0
Private answer

Here you go:

declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
rec highestSinceCrossAbove = if value[1] < 0 and value > 0 then value else if value > 0 and value > highestSinceCrossAbove[1] then value else highestSinceCrossAbove[1];
plot data = highestSinceCrossAbove;

Screenshot below shows the result.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 3, 2019 1:07 pm
0
Thank you!
( at July 3, 2019 8:22 pm)