Hi, I'm working on creating an indicator that looks for a crossover of W% from below to above -80 as well as an increasing value of MACD, within a preset # of bars of one another. I have the code below pretty close to working, but I notice some errors in the indicator and I can't figure out what is going wrong with the logic. For example, if I look at AAPL, the indicator seems to be working correctly on the WEEK chart, but not on the DAY chart. It has triggered on the DAY despite a steadily decreasing MACD value around the same time as the W% crossover occurs. What am I missing? Thanks in advance!
Code:
declare lower;
input LookBack = 7;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;
def Value = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
input length = 10;
input overBought = -20;
input overSold = -80;
def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);
def WR = if result > 0 then 0 else result;
def WRcheck = fold n = 0 to LookBack
with p = 0
do p + ((GetValue(WR, n) > -80) and (GetValue(WR, n + 1) < -80));
def MACDCheck = fold i = 0 to LookBack
with q = 0
do q + (GetValue(Value, i + 1) < GetValue(Value, i));
plot Data = (WRcheck >= 1 and MACDCheck >= 1);