Lane's Stochastic Divergence Indicator for ThinkorSwim

Has anyone else had trouble with the audible alerts giving false positives? I've checked and verified that this is happening across multiple time frames. Haven't adjusted any of the code outside of deleting the line in the code to alert for bearish divergence.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@gibbsa08 In TOS, an indicator/alert/scan can be triggered, disappear, signal and then not actually be there during the formation of a candle because the conditions are only temporarily met. You would need to wait until the close of the candle to determine if the conditions hold true.
 
@MerryDay that makes sense, thank you. As far as setting up the scanner goes, I've set up the conditions to be:

close is less than LaneDivergence()."oversold"

Is there a better way to scan for stocks that have recently seen a divergence?
 
@gibbsa08 "close is less than LaneDivergence()."oversold"" looks for a reversal not for the divergence.
The divergence calculation is done and plotted with the field name: posDIV which is plotted w/ an arrow on the chart.
To scan, it would be posDiv is true
 
@fungus12 I have not used this study personally but a review of the code would suggest that the recursive statement for lowest low and highest highs will continually repaint.
 
Last edited:
Here is one of the momentum oscillators for ThinkorSwim called Lane Divergence. It shows bullish and bearish signals on the lower study of your chart. The overbought area is set to 80 while the oversold area is set to 20, similar to RSI parameters.

The indicator also comes with an alert system.

rSEyrwr.png


thinkScript Code

Rich (BB code):
declare lower;

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.white);
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.white);
negDiv.SetLineWeight(2);

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

plot overbought = over_bought;
overbought.SetDefaultColor(Color.WHITE);
overbought.SetStyle(Curve.SHORT_DASH);

plot oversold = over_sold;
oversold.SetDefaultColor(Color.WHITE);
oversold.SetStyle(Curve.SHORT_DASH);

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

# Sound alerts
Alert(AudibleAlert and positiveDivergenceReg, "Time TO Buy", Alert.BAR,
Sound.Ring);
Alert(AudibleAlert and negativeDivergenceReg, "Time TO Sell", Alert.BAR,
Sound.Ring);

Shareable Link

https://tos.mx/Wcmk2L
Hi Ben, I am very new to ToS and trading. I was looking for your indicator. If i understood, this gives a signal of Short when red arrow arrives and Call on White arrow. Could you please let me know if this is how it works? is there any other things i shall notice while looking at it... Any suggestion on what time frame it works best?

Thanks in advance.
 
Hi Ben, I am very new to ToS and trading. I was looking for your indicator. If i understood, this gives a signal of Short when red arrow arrives and Call on White arrow. Could you please let me know if this is how it works? is there any other things i shall notice while looking at it... Any suggestion on what time frame it works best?

Thanks in advance.
I am not sure what your question is? How what works? How do oscillators work?
https://www.investopedia.com/terms/o/oscillator.asp#:~:text=Oscillators are momentum indicators used,or oversold signals to traders.

Why would you choose the Lane?
  1. There are several posts from members stating that it might repaint
  2. It is a divergence indicator. Which is an advance concept, you need to be able to eyeball the divergence patterns.
Most oscillators are trend / momentum indicators.
The most traditional one is the RSI which is a built-in ToS oscillator (the forum has scripts that create labels, scans, and watchlists for it)
There is the TMO Oscillator. It is a forum favorite.
 
Last edited:
@Ronin13 In this version the arrow colors are now global colors. The colors can be modified under settings. HTH
4Ag8UNx.png

IdMxw2A.png

Ruby:
# Lane's Stochastic Divergence Indicator for ThinkorSwim
# BenTen 3/19/19

declare lower;

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);

DefineGlobalColor("ArrowUp", CreateColor(0, 200, 255)) ;
DefineGlobalColor("ArrowDn",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("neutral",  color.gray) ;

plot posDiv = If(isLow and (positiveDivergenceReg or positiveDivergenceHid), SMIData, Double.NaN);
posDiv.AssignValueColor(if positiveDivergenceReg then GlobalColor("ArrowUp") else
GlobalColor("neutral"));
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 GlobalColor("ArrowDn") else
GlobalColor("neutral"));
negDiv.SetLineWeight(2);

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

plot overbought = over_bought;
overbought.SetDefaultColor(Color.WHITE);
overbought.SetStyle(Curve.SHORT_DASH);

plot oversold = over_sold;
oversold.SetDefaultColor(Color.WHITE);
oversold.SetStyle(Curve.SHORT_DASH);

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


Share Link: http://tos.mx/NRHDTWE

In post #20 of this thread there is a chart where it looks like the Stochastics study is coloring the price bars to match the stochastics colors, but the study with share link, NRHDTWE, on this page, does not color the price bars. What am I missing? - Thanks.
 
In post #20 of this thread there is a chart where it looks like the Stochastics study is coloring the price bars to match the stochastics colors, but the study with share link, NRHDTWE, on this page, does not color the price bars. What am I missing? - Thanks.
It does appear so. But no. Just a coincidence.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
517 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top