This indicator paints your candlesticks when a bullish divergence is found on both the RSI and the Awesome Oscillator and red when bearish divergence is found.
thinkScript Code
Code:
# Confirmed Divergence
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/PFsMAjcQ-Confirmed-Divergence/
input rsiprd = 14;
input source = close;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, source - source[1], rsiprd);
def TotChgAvg = MovingAverage(averageType, AbsValue(source - source[1]), rsiprd);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
input length = 30;
input mult = 2.0;
input src = close;
input ob = 70;
input os = 30;
input lengthAO1 = 5;
input lengthAO2 = 34;
def rv = RSI;
def AO = simpleMovingAvg((high + low) / 2, lengthAO1) - simpleMovingAvg((high + low) / 2, lengthAO2);
input x = 5;
input z = 25;
def srcLL = src > lowest(src, x) and lowest(src, x)<lowest(src, z)[x];
def rsiHL = rv > lowest(rv, x) and lowest(rv, x) > lowest(rv, z)[x] and lowest(rv, z)<os;
def aoHL = AO > lowest(AO, x) and lowest(AO, x) > lowest(AO, z)[x] and lowest(AO, x) < 0;
def BullishDiv = srcLL and rsiHL and aoHL;
def srcHH = src < highest(src, x) and highest(src, x)>highest(src, z)[x];
def rsiLH = rv < highest(rv, x) and highest(rv, x) < highest(rv, z)[x] and highest(rv, z)>ob;
def aoLH = AO < highest(AO, x) and highest(AO, x) < highest(AO, z)[x] and highest(AO, x) > 0;
def BearishDiv = srcHH and rsiLH and aoLH;
def basis = simpleMovingAvg(source, length);
def dev = mult * stdev(source, length);
def upper = basis + dev;
def lower = basis - dev;
assignPriceColor(if BullishDiv then color.green else if BearishDiv then color.red else Color.white);