#### Chuck

##### Well-known member

Code:

```
declare upper;
input ArrowLimit = 124;
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 barlimit = If(IsNaN(open[-ArrowLimit]) && !IsNaN(open), yes, no);
def positiveDivergenceReg = If (SMIData > prevLowSMI and low < prevLow, 1, 0);
def positiveDivergenceHid = If (SMIData < prevLowSMI and low > prevLow, 1, 0);
plot posDiv = If(barlimit and isLow and (positiveDivergenceReg or positiveDivergenceHid), low, Double.NaN);
posDiv.AssignValueColor(if positiveDivergenceReg then Color.GREEN else Color.GREEN);
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(barlimit and isHigh and ( negativeDivergenceReg or negativeDivergenceHid), high, Double.NaN);
negDiv.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
negDiv.AssignValueColor(if negativeDivergenceReg then Color.RED else Color.LIGHT_RED);
negDiv.SetLineWeight(2);
plot AvgSMI = Average(SMIData, percentDLength);
AvgSMI.SetDefaultColor(Color.GRAY);
plot SMI = SMIData;
SMI.AssignValueColor(if SMI > SMI[1] then Color.BLUE else Color.RED);
SMI.SetLineWeight(2);
plot highdots = if RVI >= over_bought then high else Double.NaN;
plot lowdots = if RVI <= over_sold then low else Double.NaN;
highdots.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
highdots.SetDefaultColor(Color.RED);
highdots.SetLineWeight(1);
lowdots.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
lowdots.SetDefaultColor(Color.GREEN);
lowdots.SetLineWeight(1);
# Sound alerts
Alert(AudibleAlert and posDiv[1], "Pressure Bullish", Alert.BAR, Sound.Chimes);
Alert(AudibleAlert and negDiv[1], "Pressure Bearish", Alert.BAR, Sound.Bell);
```