Stochastic Oscillator
The stochastic oscillator is a popular technical analysis tool used to assess momentum and overbought or oversold conditions.
It compares the current closing price to its price range over a specific period, typically 14 periods.
This comparison helps identify potential trend reversals or continuation points.
When the oscillator indicates overbought, it suggests that the price may soon decline.
When it indicates oversold conditions, it suggests that the price may soon rise.
Basic Stochastic Chart with Arrows, Alerts, Labels
Basic Stochastic Watchlist
Lower Chart Script:
Upper Chart Code:
Watchlist column script code:
The stochastic oscillator is a popular technical analysis tool used to assess momentum and overbought or oversold conditions.
It compares the current closing price to its price range over a specific period, typically 14 periods.
This comparison helps identify potential trend reversals or continuation points.
When the oscillator indicates overbought, it suggests that the price may soon decline.
When it indicates oversold conditions, it suggests that the price may soon rise.
Basic Stochastic Chart with Arrows, Alerts, Labels

Basic Stochastic Watchlist

Lower Chart Script:
Ruby:
# ########################################
# TOS Stochastic Lower Chart
input show_label = yes ;
input OB = 80 ;
input OS = 20 ;
input fast = 3;
input slow = 14 ;
def stoch = reference StochasticFull(OB, OS, slow, fast, high, low, close, fast, AverageType.SIMPLE);
# ########################################
# Charting & Formatting
declare lower;
declare real_size;
DefineGlobalColor("maxxed", CreateColor(50, 200, 255)) ;
DefineGlobalColor("rising", CreateColor(0, 165, 0)) ;
DefineGlobalColor("bear", CreateColor(225, 0, 0)) ;
DefineGlobalColor("pretrend", CreateColor (200, 125, 255)) ;
plot overbought = OB ;
plot oversold = OS ;
plot pStoch = stoch ;
pStoch .AssignValueColor(
if Stoch > OB then GlobalColor("maxxed") else
if Stoch < OS then GlobalColor("pretrend") else
if Stoch > Stoch [1] then GlobalColor("rising")
else GlobalColor("bear"));
pStoch .SetLineWeight(3);
plot UpArrow = if stoch crosses above OS then OS else double.NaN ;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_up);
UpArrow.SetLineWeight(1);
UpArrow.SetDefaultColor(color.lime) ;
plot DownArrow = if stoch crosses below OB then OB else double.NaN ;
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_down);
DownArrow.SetLineWeight(1);
DownArrow.SetDefaultColor(color.light_orange) ;
AddCloud(if Stoch >= OB then Stoch else Double.NaN, OB,GlobalColor("maxxed"),GlobalColor("maxxed"));
AddCloud(if Stoch <= OS then Stoch else Double.NaN, OS,GlobalColor("pretrend"),GlobalColor("pretrend"));
# ########################################################
# The same logic that was used in coloring the plot can be used in labels
AddLabel(show_label,
if Stoch > OB then "stochastic maxxed " +round(Stoch ,1) else
if Stoch < OS and Stoch >Stoch [1] then "stochastic pre-trend " +round(Stoch ,1) else
if Stoch < OS and Stoch <=Stoch [1] then "stochastic bottomed " +round(Stoch ,1) else
if Stoch > Stoch [1] then "stochastic Trending " +round(Stoch ,1)
else "stochastic Bear " +round(Stoch ,1),
if Stoch > OB then GlobalColor("maxxed") else
if Stoch < OS then GlobalColor("pretrend") else
if Stoch > Stoch [1] then GlobalColor("rising")
else GlobalColor("bear"));
Alert(stoch crosses OB, "stoch crosses OB", Alert.Bar, Sound.Bell);
Alert(stoch crosses OS, "stoch crosses OS", Alert.Bar, Sound.Bell);
Upper Chart Code:
Ruby:
# ########################################
# TOS Stochastic Upper Chart Arrows
input show_label = yes ;
input OB = 80 ;
input OS = 20 ;
input fast = 3;
input slow = 14 ;
def stoch = reference StochasticFull(OB, OS, slow, fast, high, low, close, fast, AverageType.SIMPLE);
# ########################################
# Charting & Formatting
plot UpArrow = stoch crosses above OS ;
UpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpArrow.SetLineWeight(1);
UpArrow.SetDefaultColor(color.lime) ;
plot DownArrow = stoch crosses below OB;
DownArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownArrow.SetLineWeight(1);
DownArrow.SetDefaultColor(color.light_orange) ;
Alert(stoch crosses ob, "stoch crosses ob", Alert.Bar, Sound.Bell);
Alert(stoch crosses os, "stoch crosses os", Alert.Bar, Sound.Bell);
Watchlist column script code:
Ruby:
# ########################################
# TOS Stochastic Watchlist
input OB = 80 ;
input OS = 20 ;
input fast = 3;
input slow = 14 ;
def stoch = reference StochasticFull(OB, OS, slow, fast, high, low, close, fast, AverageType.SIMPLE);
AddLabel(yes,
if Stoch > OB then "maxxed " +round(Stoch ,1) else
if Stoch < OS and Stoch >Stoch [1] then "pre-trend " +round(Stoch ,1) else
if Stoch < OS and Stoch <=Stoch [1] then "bottomed " +round(Stoch ,1) else
if Stoch > Stoch [1] then "Trending " +round(Stoch ,1)
else "Bear " +round(Stoch ,1));
AssignBackgroundColor(
if Stoch > OB then CreateColor(50, 200, 255) else
if Stoch < OS then CreateColor (200, 125, 255) else
if Stoch > Stoch [1] then CreateColor(0, 165, 0)
else CreateColor(225, 0, 0));
Last edited: