MOD NOTE: This indicator will show the dots but the divergence lines are INFREQUENT..
Posts complaining that the INFREQUENT divergence lines are not appearing will be deleted.
I wanted to share this since I received it from Mobius. In order to have RSI divergence lines on the chart here is the upper study script. I added the aggregation period to both the upper and lower studies.
Upper Study
Lower Study
Posts complaining that the INFREQUENT divergence lines are not appearing will be deleted.
I wanted to share this since I received it from Mobius. In order to have RSI divergence lines on the chart here is the upper study script. I added the aggregation period to both the upper and lower studies.
Upper Study
Ruby:
# RSI Divergence Upper Study Plots
# Mobius
# V01
# Note: Peak and trough points will always be painted on last 2 RSI low values and on last 2 RSI high values. The bridge will only plot when there is divergence.
input agg = AggregationPeriod.fifteen_min;
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input averageType = AverageType.WILDERS;
def h = high(period = agg);
def l = low(period = agg);
def c = close(period = agg);
#def h = high;
#def l = low;
#def c = close;
def bar = barNumber();
def NetChgAvg = MovingAverage(averageType, c - c[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(c - c[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;
# Divergence Sub-Routine
def indicator = RSI; # indicator to diverge
def upper = OverBought;# crossing above begins routine on the rising side.
def lower = OverSold; # crossing below begins routine on the falling side.
def h_ind_val = if indicator < upper
then h_ind_val[1]
else if indicator crosses above upper
then indicator
else if indicator > upper and indicator > h_ind_val[1]
then indicator
else h_ind_val[1];
def h_ind_bar = if indicator == h_ind_val
then bar
else h_ind_bar[1];
def h_ind_price = if bar == h_ind_bar
then h
else h_ind_price[1];
def prev_h_ind_bar = if indicator crosses above upper
then h_ind_bar[1]
else prev_h_ind_bar[1];
def prev_h_ind_val = if bar == highestAll(prev_h_ind_bar)
then indicator
else prev_h_ind_val[1];
def prev_h_price = if bar == highestAll(prev_h_ind_bar)
then h
else prev_h_price[1];
def high_div_true = h_ind_val < prev_h_ind_val and
h_ind_price > prev_h_price;
plot high_div_line = if high_div_true and bar == highestAll(h_ind_bar)
then h_ind_price
else if bar == highestAll(prev_h_ind_bar)
then prev_h_price
else double.nan;
high_div_line.EnableApproximation();
high_div_line.HideBubble();
high_div_line.HideTitle();
plot h_point = if bar == highestAll(h_ind_bar)
then h_ind_price
else double.nan;
h_point.SetStyle(Curve.Points);
h_point.SetLineWeight(2);
h_point.SetDefaultColor(Color.yellow);
h_point.HideBubble();
h_point.HideTitle();
plot prev_h_point = if bar == highestAll(prev_h_ind_bar)
then prev_h_price
else double.nan;
prev_h_point.SetStyle(Curve.Points);
prev_h_point.SetLineWeight(2);
prev_h_point.SetDefaultColor(Color.yellow);
prev_h_point.HideBubble();
prev_h_point.HideTitle();
addLabel(0, "bar = " + bar +
" h_ind_bar = " + highestAll(h_ind_bar) +
" h_ind_value = " + h_ind_val +
" h_ind_price = " + h_ind_price +
" prev_h_ind_bar = " + highestAll(prev_h_ind_bar) +
" prev_h_ind = " + prev_h_ind_val +
" prev_h_price = " + prev_h_price);
def l_ind_val = if indicator > lower
then l_ind_val[1]
else if indicator crosses below lower
then indicator
else if indicator < lower and indicator < l_ind_val[1]
then indicator
else l_ind_val[1];
def l_ind_bar = if indicator == l_ind_val
then bar
else l_ind_bar[1];
def l_ind_price = if bar == l_ind_bar
then l
else l_ind_price[1];
def prev_l_ind_bar = if indicator crosses below lower
then l_ind_bar[1]
else prev_l_ind_bar[1];
def prev_l_ind_val = if bar == highestAll(prev_l_ind_bar)
then indicator
else prev_l_ind_val[1];
def prev_l_price = if bar == highestAll(prev_l_ind_bar)
then l
else prev_l_price[1];
def low_div_true = l_ind_val > prev_l_ind_val and
l_ind_price < prev_l_price;
plot low_div_line = if low_div_true and bar == highestAll(l_ind_bar)
then l_ind_price
else if bar == highestAll(prev_l_ind_bar)
then prev_l_price
else double.nan;
low_div_line.EnableApproximation();
low_div_line.HideBubble();
low_div_line.HideTitle();
plot l_point = if bar == highestAll(l_ind_bar)
then l_ind_price
else double.nan;
l_point.SetStyle(Curve.Points);
l_point.SetLineWeight(2);
l_point.SetDefaultColor(Color.yellow);
l_point.HideBubble();
l_point.HideTitle();
plot prev_l_point = if bar == highestAll(prev_l_ind_bar)
then prev_l_Price
else double.nan;
prev_l_point.SetStyle(Curve.Points);
prev_l_point.SetLineWeight(2);
prev_l_point.SetDefaultColor(Color.yellow);
prev_l_point.HideBubble();
prev_l_point.HideTitle();
addLabel(0, "bar = " + bar +
" l_ind_bar = " + highestAll(l_ind_bar) +
" l_ind_value = " + l_ind_val +
" l_ind_price = " + l_ind_price +
" prev_l_ind_bar = " + highestAll(prev_l_ind_bar) +
" prev_l_ind = " + prev_l_ind_val +
" prev_l_price = " + prev_l_price);
# End Code
Lower Study
Ruby:
# Divergence Sub-Routine
declare lower;
input agg = AggregationPeriod.FOUR_HOURS;
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input averageType = AverageType.WILDERS;
def h = high(period = agg);
def l = low(period = agg);
def c = close(period = agg);
def bar = BarNumber();
def NetChgAvg = MovingAverage(averageType, c - c[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(c - c[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def indicator = RSI; # indicator to diverge
def upper = over_Bought;# crossing above begins routine on the rising side.
def lower = over_Sold; # crossing below begins routine on the falling side.
def h_ind_val = if indicator < upper
then h_ind_val[1]
else if indicator crosses above upper
then indicator
else if indicator > upper and indicator > h_ind_val[1]
then indicator
else h_ind_val[1];
def h_ind_bar = if indicator == h_ind_val
then bar
else h_ind_bar[1];
def h_ind_price = if bar == h_ind_bar
then h
else h_ind_price[1];
def prev_h_ind_bar = if indicator crosses above upper
then h_ind_bar[1]
else prev_h_ind_bar[1];
def prev_h_ind_val = if bar == HighestAll(prev_h_ind_bar)
then indicator
else prev_h_ind_val[1];
def prev_h_price = if bar == HighestAll(prev_h_ind_bar)
then h
else prev_h_price[1];
def high_div_true = h_ind_val < prev_h_ind_val and
h_ind_price > prev_h_price;
plot high_div_line = if high_div_true and bar == HighestAll(h_ind_bar)
then indicator
else if bar == HighestAll(prev_h_ind_bar)
then indicator
else Double.NaN;
high_div_line.EnableApproximation();
high_div_line.HideBubble();
high_div_line.HideTitle();
plot h_point = if bar == HighestAll(h_ind_bar)
then indicator
else Double.NaN;
h_point.SetStyle(Curve.POINTS);
h_point.SetLineWeight(2);
h_point.SetDefaultColor(Color.YELLOW);
h_point.HideBubble();
h_point.HideTitle();
plot prev_h_point = if bar == HighestAll(prev_h_ind_bar)
then indicator
else Double.NaN;
prev_h_point.SetStyle(Curve.POINTS);
prev_h_point.SetLineWeight(2);
prev_h_point.SetDefaultColor(Color.YELLOW);
prev_h_point.HideBubble();
prev_h_point.HideTitle();
AddLabel(0, "bar = " + bar +
" h_ind_bar = " + HighestAll(h_ind_bar) +
" h_ind_value = " + h_ind_val +
" h_ind_price = " + h_ind_price +
" prev_h_ind_bar = " + HighestAll(prev_h_ind_bar) +
" prev_h_ind = " + prev_h_ind_val +
" prev_h_price = " + prev_h_price);
def l_ind_val = if indicator > lower
then l_ind_val[1]
else if indicator crosses below lower
then indicator
else if indicator < lower and indicator < l_ind_val[1]
then indicator
else l_ind_val[1];
def l_ind_bar = if indicator == l_ind_val
then bar
else l_ind_bar[1];
def l_ind_price = if bar == l_ind_bar
then l
else l_ind_price[1];
def prev_l_ind_bar = if indicator crosses below lower
then l_ind_bar[1]
else prev_l_ind_bar[1];
def prev_l_ind_val = if bar == HighestAll(prev_l_ind_bar)
then indicator
else prev_l_ind_val[1];
def prev_l_price = if bar == HighestAll(prev_l_ind_bar)
then l
else prev_l_price[1];
def low_div_true = l_ind_val > prev_l_ind_val and
l_ind_price < prev_l_price;
plot low_div_line = if low_div_true and bar == HighestAll(l_ind_bar)
then indicator
else if bar == HighestAll(prev_l_ind_bar)
then indicator
else Double.NaN;
low_div_line.EnableApproximation();
low_div_line.HideBubble();
low_div_line.HideTitle();
plot l_point = if bar == HighestAll(l_ind_bar)
then indicator
else Double.NaN;
l_point.SetStyle(Curve.POINTS);
l_point.SetLineWeight(2);
l_point.SetDefaultColor(Color.YELLOW);
l_point.HideBubble();
l_point.HideTitle();
plot prev_l_point = if bar == HighestAll(prev_l_ind_bar)
then indicator
else Double.NaN;
prev_l_point.SetStyle(Curve.POINTS);
prev_l_point.SetLineWeight(2);
prev_l_point.SetDefaultColor(Color.YELLOW);
prev_l_point.HideBubble();
prev_l_point.HideTitle();
AddLabel(0, "bar = " + bar +
" l_ind_bar = " + HighestAll(l_ind_bar) +
" l_ind_value = " + l_ind_val +
" l_ind_price = " + l_ind_price +
" prev_l_ind_bar = " + HighestAll(prev_l_ind_bar) +
" prev_l_ind = " + prev_l_ind_val +
" prev_l_price = " + prev_l_price);
# End Code
Last edited by a moderator: