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];
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?
Yes sir, that’s exactly what I’m hoping for!