I am writing a simple divergence indicator with following logic:
Issue I am facing is how to get the MACD value for the highest high price bar? I don't think the current code logic is right. MACD[1] will give value for the 1 bar ago and not the highest high price bar.
Appreciate all the help. Thanks
- Search for highest high in price in last 3 months (this can be any period)
- Compare with current price and ensure current price is equal or above the highest high
- Compare MACD between the two points and ensure MACD value for current bar is less than the highest bar.
Code:
input length = 30;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
def highestHigh = highest(high, length);
def MACD = MACD(fastLength, slowLength, MACDLength).Diff;
def MACDHist = MACD(fastLength, slowLength, MACDLength).Hist;
plot Scan = high > highestHigh and MACD - MACD[1] < 0 and MACDHist - MACDHist[1] < 0;
Issue I am facing is how to get the MACD value for the highest high price bar? I don't think the current code logic is right. MACD[1] will give value for the 1 bar ago and not the highest high price bar.
Appreciate all the help. Thanks
Last edited by a moderator: