@BenTen: I notice that the script also shows a false divergence where price makes higher, and RSI also makes higher high as you can see in picture #4. Is there a way to modify the script so that it only plots the dotted divergence where the price and RSI indicator moves the opposite direction?@KhanhNguyen it will only display the newest divergence. It doesn’t show all.
I have the same problem. Can you figure out how to get it within 3 bars??Oh, sorry, it's really ordinary: daily time frame, scanning all stocks. With no other conditions. I thought maybe there's something in the code preventing using this condition for less than "within 7 bars"? It seems strange that there would be hundreds of hits for "within 7 bars" and zero for "within 6 bars".
# Divergence Updown Points
# tomsk (modfied further by [USER=2184]@venus360[/USER])
# 1.17.2020
# Plots the ratio of Up/Down points relative to the prior candle
input period = 14;
declare lower;
def upPoints = fold i = 0 to period
with p
do p + GetValue(if close > close[1] then close - close[1] else 0, i);
def downPoints = fold j = 0 to period
with r
do r + GetValue(if close < close[1] then close - close[1] else 0, j);
def au = upPoints / period;
def ad = AbsValue(downPoints) / period;
def ratio = au / ad;
def step0 = 1 + ratio;
def step1 = 100 / step0;
plot final = 100 - step1;
# End UpDown Points Divergence
#RSI_DIVERGENCE_POINTS
#DeusMecanicus
declare upper;
input Length = 14;
input Price = close;
input AverageType = AverageType.WILDERS;
input Lookback1 = 20;
input Lookback2 = 50;
input Lookback3 = 100;
input PaintBars = No;
input HidePoints = No;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def futurebar = rsi > rsi[-1];
def futurebar1 = RSI < RSI[-1];
plot RSI_Div_Down1 = if rsi != Highest(rsi, Lookback1) and close == Highest(close, Lookback1) and futurebar then midbodyval() else Double.NaN;
RSI_Div_Down1.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI_Div_Down1.AssignValueColor(Color.PINK);
RSI_Div_Down1.SetLineWeight(3);
plot RSI_Div_Down2 = if rsi != Highest(rsi, Lookback2) and close == Highest(close, Lookback2) and futurebar then midbodyval() else Double.NaN;
RSI_Div_Down2.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI_Div_Down2.AssignValueColor(Color.RED);
RSI_Div_Down2.SetLineWeight(3);
plot RSI_Div_Down3 = if rsi != Highest(rsi, Lookback3) and close == Highest(close, Lookback3) and futurebar then midbodyval() else Double.NaN;
RSI_Div_Down3.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI_Div_Down3.AssignValueColor(Color.DARK_RED);
RSI_Div_Down3.SetLineWeight(3);
plot RSI_Div_Up1 = if rsi != Lowest(rsi, Lookback1) and close == Lowest(close, Lookback1) and futurebar1 then midbodyval() else Double.NaN;
RSI_Div_Up1.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI_Div_Up1.AssignValueColor(Color.GREEN);
RSI_Div_Up1.SetLineWeight(3);
plot RSI_Div_Up2 = if rsi != Lowest(rsi, Lookback2) and close == Lowest(close, Lookback2) and futurebar1 then midbodyval() else Double.NaN;
RSI_Div_Up2.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI_Div_Up2.AssignValueColor(Color.DARK_GREEN);
RSI_Div_Up2.SetLineWeight(3);
plot RSI_Div_Up3 = if rsi != Lowest(rsi, Lookback3) and close == Lowest(close, Lookback3) and futurebar1 then midbodyval() else Double.NaN;
RSI_Div_Up3.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI_Div_Up3.AssignValueColor(Color.CYAN);
RSI_Div_Up3.SetLineWeight(3);
RSI_DIV_Up1.sethiding(HidePoints);
RSI_DIV_Up2.sethiding(HidePoints);
RSI_DIV_Up3.sethiding(HidePoints);
RSI_DIV_Down1.sethiding(HidePoints);
RSI_DIV_Down2.sethiding(HidePoints);
RSI_DIV_Down3.sethiding(HidePoints);
AssignPriceColor(if !paintBars then Color.CURRENT else
if rsi != Highest(rsi, Lookback1) and close == Highest(close, Lookback1) and futurebar then Color.PINK else
if rsi != Highest(rsi, Lookback2) and close == Highest(close, Lookback2) and futurebar then Color.RED else
if rsi != Highest(rsi, Lookback3) and close == Highest(close, Lookback3) and futurebar then Color.DARK_RED else
if rsi != Lowest(rsi, Lookback1) and close == Lowest(close, Lookback1) and futurebar1 then Color.GREEN else
if rsi != Lowest(rsi, Lookback2) and close == Lowest(close, Lookback2) and futurebar1 then Color.DARK_GREEN else
if rsi != Lowest(rsi, Lookback3) and close == Lowest(close, Lookback3) and futurebar1 then Color.CYAN else Color.BLACK );
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Archived: TMO True Momentum Oscillator | Indicators | 346 | ||
Archived: Opening Range Breakout | Indicators | 340 | ||
Archived: Supertrend Indicator by Mobius for ThinkorSwim | Indicators | 312 | ||
Ultimate RSI [LuxAlgo] for ThinkOrSwim | Indicators | 12 | ||
Super 6x: RSI, MACD, Stoch, Loxxer, CCI, & Velocity [Loxx] for ThinkOrSwim | Indicators | 52 |
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.