RVI MainDivgCloud w/Alerts

Chuck

Moderator
Staff member
obHXk4v.png
Code:
declare lower;

input length = 14;
input ob  = 80;
input ob2 = 0;
input os = 20;
input os2 = 0;

def highPrice = stDev(high, 10);
def lowPrice = stDev(low, 10);

def highAvgUp = ExpAverage(if high > high[1] then highPrice else 0, length);
def highAvgDown = ExpAverage(if high < high[1] then highPrice else 0, length);

def lowAvgUp = ExpAverage(if low > low[1] then lowPrice else 0, length);
def lowAvgDown = ExpAverage(if low < low[1] then lowPrice else 0, length);

def highRVI = 100 - 100 / (1 + highAvgUp / highAvgDown);
def lowRVI = 100 - 100 / (1 + lowAvgUp / lowAvgDown);

plot RVI = (highRVI + lowRVI) / 2;
plot OverBought = ob;
plot OverBoughtmore = ob2;
plot OverSold = os;
plot OverSoldmore = os2;

RVI.DefineColor("OverBought", GetColor(5));
RVI.DefineColor("Normal", GetColor(7));
RVI.DefineColor("OverSold", GetColor(1));
RVI.AssignValueColor(if RVI > overBought then RVI.color("OverBought") else if RVI < overSold then RVI.color("OverSold") else RVI.color("Normal"));

OverBought.setDefaultColor(createColor(175, 5, 25));
overSold.setDefaultColor(createColor(5, 175, 25));



input over_bought = 80.0;
input over_sold = 20.0;
input percentDLength = 3;
input percentKLength = 14;
input AudibleAlert = yes;



def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;
def avgrel = Average(Average(rel_diff, percentDLength), percentDLength);
def avgdiff = Average(Average(diff, percentDLength), percentDLength);
def SMIData = (avgrel / (avgdiff / 2) + 1) * 50;

def isLow = If (SMIData < SMIData[-1] and SMIData < SMIData[1], 1, 0);
def isHigh =   If (SMIData > SMIData[-1] and SMIData > SMIData[1], 1, 0);

rec prevLowSMI = CompoundValue(1, If(isLow[1], SMIData[1], prevLowSMI[1]), 0);
rec prevHighSMI = CompoundValue(1, If(isHigh[1], SMIData[1], prevHighSMI[1]), 0);

rec prevLow =  CompoundValue(1, If(isLow[1], low, prevLow[1]), low);
rec prevHigh =  CompoundValue(1, If(isHigh[1], high, prevHigh[1]), high);

def positiveDivergenceReg = If (SMIData > prevLowSMI and low < prevLow, 1, 0);
def positiveDivergenceHid = If (SMIData < prevLowSMI and low > prevLow, 1, 0);

plot posDiv = If(isLow and (positiveDivergenceReg or positiveDivergenceHid), SMIData, Double.NaN);
posDiv.AssignValueColor(if positiveDivergenceReg then Color.GREEN else Color.gray);
posDiv.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
posDiv.SetLineWeight(2);


def negativeDivergenceReg =  If (SMIData < prevHighSMI and high > prevHigh, 1, 0);
def negativeDivergenceHid = If (SMIData > prevHighSMI and high < prevHigh, 1, 0);

plot negDiv = If(isHigh and ( negativeDivergenceReg or negativeDivergenceHid), SMIData, Double.NaN);
negDiv.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
negDiv.AssignValueColor(if negativeDivergenceReg then Color.RED else Color.gray);
negDiv.SetLineWeight(2);



#plot AvgSMI = Average(SMIData, percentDLength);
#AvgSMI.SetDefaultColor(Color.GRAY);


#plot SMI = SMIData;
#SMI.AssignValueColor(if SMI > SMI[1] then Color.GREEN else Color.RED);
#SMI.SetLineWeight(2);



# Sound alerts

Alert(AudibleAlert and posdiv[1], "Green Arrow", Alert.BAR, Sound.Chimes);
Alert(AudibleAlert and negdiv[1], "Red Arrow", Alert.BAR, Sound.Bell);

#=============================================================#
#========== Additional Modifications by Syracusepro ==========#
#=============================================================#

#plot centerline = 50;
#centerline.setstyle(curve.LONG_DASH);

#plot topLine = 80;
#topline.setStyle(curve.sHORT_DASH);
#topline.setDefaultColor(color.red);

#plot bottomline = 20;
#bottomline.setStyle(curve.sHORT_DASH);


RVI.AssignvalueColor(if RVI > overBought
    then color.red
    else if RVI < oversold
        then color.cyAN
        else Color.light_GRAY);


#addcloud(overbought, bottomline, color.green);
#addcloud(overSold, topLine, color.red);
 
Top