Define the highest high before MACD value crosses below average


Category:
0
0

I’m trying to define the highest point (indicated with the two red arrows) before the MACD cross. Ultimately I will add the ATR value to that point to determine my stop loss. Just not sure how to define that point. Thanks!

Ive worked on a couple of ideas but cant seem to wrap my head around it.

def PreviousHigh = if high from 1 bars ago is greater than high
then 1
else if high from 2 bars ago is greater than high
then 2
else if high from 3 bars ago is greater than high
then 3
else 0;

 

Attachments:
RESOLVED
Marked as spam
Posted by (Questions: 2, Answers: 3)
Asked on November 27, 2020 1:22 pm
115 views
0
Private answer

The following solution tracks the highest since since the last time value crossed above average. After the value crosses below the average it retains the previous highest high until the next reset. The line resets each time the value crosses back above the average.

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);
def crossAbove = value[1] < average[1] and value > average;
def crossBelow = value[1] > average[1] and value < average; rec trackHigh = if crossAbove then high else if value > average and high > trackHigh[1] then high else trackHigh[1];
plot highestSinceCross = trackHigh;
highestSinceCross.SetDefaultColor(Color.DARK_GREEN);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 28, 2020 9:12 am
0
Thank you Mr. Hahn. Your help is greatly appreciated and I think this will work perfectly!
( at November 29, 2020 10:44 am)