Elastic Stochastic for ThinkorSwim -Upper and Lower indicator

chewie76

chewie76

Active member
VIP
VIP Enthusiast
Are you looking for reversals? The Elastic Stochastic may be a good fit for your trading strategy. This is a twist on the StochasticFull indicator. This does not repaint. This is an elastic indicator because it acts like a rubber band that gets stretched and snaps back. There is a stretching and then a pull back. Typically the longer the stretch goes, the stronger the pull back. This indicator provides both weak and strong signals. The white arrows are weak signals and the magenta arrows are strong signals for reversals. The yellow wedges are indicators that the stock is currently going through a stretch. When you see yellow wedges, expect to see it end with a magenta arrow followed by the snap back. Yellow wedge signals are caution signs. It's letting you know to be prepared for a pull back or correction coming. Be cautious because it can stretch for many candles before you finally get the magenta snap back arrow. This works on any timeframe, but I would suggest you trade longer than the one minute.

The magenta snap back arrows and yellow caution wedges can be adjusted in the settings. So I highly suggest you look at this on many time frames and adjust the sensitivity based on your own preferences. By default, both are set at 80 overbought and 20 oversold. The higher you make the overbought, the less signals you will see. The lower you make the oversold, the less signals you will see. So adjust it to your own preferences.

In the settings, you can also turn off the yellow caution wedges and weak white arrow signals by selecting "No".

Here are some examples followed by a watchlist column. You can use this indicator to create your own scan.

Example of SPY on the 2 min chart. Yellow wedges are stretching and magenta arrow is the snap back. The white arrows are weak reversals.



Example of /ES on the 2 min chart.



Example of /NQ on the 4 hour chart.




Here is the Watchlist Column. When there is a yellow wedge up, you see the word "Up" in yellow. A wedge down, you'll see "Down". When there is a magenta up arrow, you'll see "BUY" in magenta, and a down arrow is a magenta "SELL". Weak buy and sell white arrows will say "WBUY" or "WSELL" in white lettering. Below is an example.



WATCHLIST COLUMN:
http://tos.mx/s6P8ipm

Code:
#Elastic Stochastic Watchlist Column
#Assembled by Chewie on usethinkscript.com

input over_bought = 80;
input over_sold = 20;
input caution_high = 80.0;
input caution_low = 20.0;
input caution = yes;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 2;
input smoothingType = {default SMA, EMA};

def priceH = high;
def priceL = low;
def priceC = close;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def fullk;
def FullD;

switch (smoothingType) {
case SMA:
    fullk = Average(FastK, slowing_period);
    FullD = Average(fullk, DPeriod);
case EMA:
    fullk = ExpAverage(FastK, slowing_period);
    FullD = ExpAverage(fullk, DPeriod);
}

def OverBought = over_bought;
def OverSold = over_sold;
def crossedb = Crosses(FullD, overbought, CrossingDirection.BELOW);
def crossbelow =  if crossedb is true then 1 else 0;
def crosseda = Crosses(FullD, oversold, CrossingDirection.above);
def crossabove = if crosseda is true then 1 else 0;
def Caution_UP = FullD > caution_high;
def CautionUP = if caution and Caution_UP is true then 1 else 0;
def Caution_DOWN = FullD < caution_low;
def CautionDOWN = if caution and Caution_DOWN is true then 1 else 0;
def Weak1 = if FullD < 48  and FullD  > 25 and FullD[1] < 48 and FullD[1] < FullD[2] and FullD[2] < 48 and FullD[2] > 25 and FullD  > FullD[1] then FullD else Double.NaN;
plot WeakBUY = if Weak1 is true then 1 else 0;
def Weak2 = if FullD > 52  and FullD  < 75 and FullD[1] > 52 and FullD[1] > FullD[2] and FullD[2] > 52 and FullD[2] <75 and FullD  < FullD[1] then FullD else Double.NaN;
plot WeakSELL = if Weak2 is true then 1 else 0;
def Trending = caution_UP or caution_Down;
def Signal = crosseda or crossedb;

addlabel(yes,
if crossabove then ("BUY")
else if crossedb then ("SELL")
else if WeakBUY then ("WBUY")
else if WeakSELL then ("WSELL")
else if caution_UP then("Up")
else if caution_Down then("Down")
else " ",
if Signal then color.magenta else if WeakBUY and WeakSELL then color.white else if Trending then color.yellow else color.current);

UPPER INDICATOR:
http://tos.mx/sg3pepL

Code:
#Elastic Stochastic Upper with signals
#Assembled by Chewie on usethinkscript.com https://usethinkscript.com/threads/elastic-stochastic-for-thinkorswim-upper-and-lower-indicator.4360/

declare upper;
input snap_high = 80;
input snap_low = 20;
input caution_high = 80.0;
input caution_low = 20.0;
input caution = yes;
input weak = yes;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 2;
input smoothingType = {default SMA, EMA};

def priceH = high;
def priceL = low;
def priceC = close;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def fullk;
def FullD;

switch (smoothingType) {
case SMA:
    fullk = Average(FastK, slowing_period);
    FullD = Average(fullk, DPeriod);
case EMA:
    fullk = ExpAverage(FastK, slowing_period);
    FullD = ExpAverage(fullk, DPeriod);
}

def OverBought = snap_high;
def OverSold = snap_low;

def crossedb = Crosses(FullD, overbought, CrossingDirection.BELOW);
plot crossbelow =  if crossedb is true then 1 else 0;
crossbelow.SetDefaultColor(Color.magenta);
crossbelow.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_down);

def crosseda = Crosses(FullD, oversold, CrossingDirection.above);
plot crossabove = if crosseda is true then 1 else 0;
crossabove.SetDefaultColor(Color.magenta);
crossabove.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_up);

def Caution_UP = FullD > caution_high;
plot CautionUP = if caution and Caution_UP is true then 1 else 0;
CautionUP.setDefaultColor(Color.yellow);
CautionUP.SetPaintingStrategy(PaintingStrategy.Boolean_wedge_up);

def Caution_DOWN = FullD < caution_low;
plot CautionDOWN = if caution and Caution_DOWN is true then 1 else 0;
CautionDOWN.setDefaultColor(Color.yellow);
CautionDOWN.SetPaintingStrategy(PaintingStrategy.Boolean_wedge_DOWN);

def Weak1 = if FullD < 48  and FullD  > 25 and FullD[1] < 48 and FullD[1] < FullD[2] and FullD[2] < 48 and FullD[2] > 25 and FullD  > FullD[1] then FullD else Double.NaN;
plot WeakBUY = if weak and Weak1 is true then 1 else 0;
WeakBUY.SetDefaultColor(Color.white);
WeakBUY.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_up);

def Weak2 = if FullD > 52  and FullD  < 75 and FullD[1] > 52 and FullD[1] > FullD[2] and FullD[2] > 52 and FullD[2] <75 and FullD  < FullD[1] then FullD else Double.NaN;
plot WeakSELL = if weak and Weak2 is true then 1 else 0;
WeakSELL.SetDefaultColor(Color.white);
WeakSELL.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_DOWN);

LOWER INDICATOR:
http://tos.mx/REZmVJ8

Code:
#Elastic_Stochastic with signals
#Assembled by Chewie on usethinkscript.com  https://usethinkscript.com/threads/elastic-stochastic-for-thinkorswim-upper-and-lower-indicator.4360/

declare lower;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 2;
input smoothingType = {default SMA, EMA};

def priceH = high;
def priceL = low;
def priceC = close;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def fullk;
plot FullD;
FullD.SetDefaultColor(color.yellow);

switch (smoothingType) {
case SMA:
    fullk = Average(FastK, slowing_period);
    FullD = Average(fullk, DPeriod);
case EMA:
    fullk = ExpAverage(FastK, slowing_period);
    FullD = ExpAverage(fullk, DPeriod);
}

plot OverBought = over_bought;
plot OverSold = over_sold;
OverBought.SetDefaultColor(Color.red);
OverSold.SetDefaultColor(Color.green);

AddCloud(FULLD, OverBought, Color.RED, Color.CURRENT);
AddCloud(OverSold, FULLD, Color.GREEN, Color.CURRENT);

def crossedb = Crosses(FullD, overbought, CrossingDirection.BELOW);
plot crossbelow = if crossedb then crossedb + overbought else Double.NaN;
crossbelow.SetDefaultColor(Color.magenta);
crossbelow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

def crossedu = Crosses(FullD, oversold, CrossingDirection.ABOVE);
plot crossabove = if crossedu then crossedu + oversold else Double.NaN;
crossabove.SetDefaultColor(Color.magenta);
crossabove.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

def Weak1 = if FullD < 48  and FullD  > 25 and FullD[1] < 48 and FullD[1] < FullD[2] and FullD[2] < 48 and FullD[2] > 25 and FullD  > FullD[1] then FullD else Double.NaN;
plot WeakBUY = Weak1;
WeakBUY.SetDefaultColor(Color.white);
WeakBUY.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

def Weak2 = if FullD > 52  and FullD  < 75 and FullD[1] > 52 and FullD[1] > FullD[2] and FullD[2] > 52 and FullD[2] <75 and FullD  < FullD[1] then FullD else Double.NaN;
plot WeakSELL = Weak2;
WeakSELL.SetDefaultColor(Color.white);
WeakSELL.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Enjoy!
 
Last edited:
F

FOTM_8888

Member
VIP
@chewie76.. thank you some much for this awesome indicator.. a quick question, can you help me out how can add order to do a back testing of this indicator for futures? thank you some much
 
dougn

dougn

Member
2019 Donor
Great work and very generous of you to share it.

And especially thank you for including the watchlist column.
 
M

MM325

New member
VIP
Fantastic, I'll give this a try next week...looks promising. Much appreciated!
 
netarchitech

netarchitech

Well-known member
VIP
@chewie76 Thank you for your recent efforts to provide the uTS Community with new and interesting thinkscripts. On that note, I've taken the liberty of creating two Elastic Stochastic scans for your and the community's review...Since the original script could not provide one scan, I've divided it into two...one SMA version and one EMA version...

Elastic Stochastic SMA SCAN

Code:
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 2;

def priceH = high;
def priceL = low;
def priceC = close;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = Average(FastK, slowing_period);
def FullD = Average(fullk, DPeriod);

def OverBought = over_bought;
def OverSold = over_sold;

def crossedb = Crosses(FullD, overbought, CrossingDirection.BELOW);
def crossedu = Crosses(FullD, oversold, CrossingDirection.ABOVE);

# Note: Comment out (using the # sign) to run either the Bear or Bull SMA Scan statement below

# Elastic Stochastic Bear SMA Scan
#plot crossbelow = if crossedb then crossedb + overbought else Double.NaN;

# Elastic Stochastic Bull SMA Scan
plot crossabove = if crossedu then crossedu + oversold else Double.NaN;

Elastic Stochastic EMA SCAN

Code:
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 2;

def priceH = high;
def priceL = low;
def priceC = close;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = ExpAverage(FastK, slowing_period);
def FullD = ExpAverage(FullK, DPeriod);

def OverBought = over_bought;
def OverSold = over_sold;

def crossedb = Crosses(FullD, overbought, CrossingDirection.BELOW);
def crossedu = Crosses(FullD, oversold, CrossingDirection.ABOVE);

# Note: Comment out (using the # sign) to run either the Bear or Bull EMA Scan statement below

# Elastic Stochastic EMA Bear Scan
#plot crossbelow = if crossedb then crossedb + overbought else Double.NaN;

# Elastic Stochastic EMA Bull Scan
plot crossabove = if crossedu then crossedu + oversold else Double.NaN;


Good Luck and Good Trading :)
 
E

egshih

New member
VIP
VIP Enthusiast
Hi Everyone, Here is @chewie76 Elastic Stochastic Converted over to TradingView. Here is the Upper Version.

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © egshih

//@version=4
study(title="ElasticStochastic Upper",overlay=true)
//#Elastic Stochastic Upper with signals
//#Assembled by Chewie on usethinkscript.com https://usethinkscript.com/threads/elastic-stochastic-for-thinkorswim-upper-and-lower-indicator.4360/
//Converted over to TradingView by egshih
snap_high = input(title="Snap High",defval=80)
snap_low = input(title="Snap Low",defval=20)
caution_high = input(title="Caution High",defval=80)
caution_low = input(title="Caution Low",defval=20)
KPeriod = input(title="KPeriod",defval=5)
DPeriod = input(title="DPeriod",defval=3)
slowing_period = input(title="Slowing Period",defval=2)
smoothingType =input(title="AverageType",defval="SMA",options=["SMA","EMA"])

priceH = high
priceL = low
priceC = close
lowest_k = lowest(priceL, KPeriod)
c1 = priceC - lowest_k
c2 = highest(priceH, KPeriod) - lowest_k
FastK = c2 != 0 ? c1 / c2 * 100 : 0

fullk = sma(FastK, slowing_period)
FullD = sma(fullk, DPeriod)


//if smoothingType == "SMA"
    //fullk = sma(FastK, slowing_period)
    //FullD = sma(fullk, DPeriod)
//else
    //fullk = ema(FastK, slowing_period)
    //FullD = ema(fullk, DPeriod)

OverBought = snap_high
OverSold = snap_low



crossedb = crossunder(OverBought, FullD)
//plotshape (series=crossedb,title="OverBought",style=label.style_arrowdown,color=color.red,location=location.abovebar)
plotchar(crossedb,title="Overbought",char="⬇", color=color.red,location=location.abovebar,text="OB")


crosseda = crossover(FullD, OverSold)
//plotshape (series=crosseda,title="OverSold",style=label.style_arrowup,color=color.green,location=location.belowbar)
plotchar(crosseda,title="Oversold",char="⬆", color=color.green,location=location.belowbar,text="os")
Caution_UP = FullD > caution_high
plotshape(series=Caution_UP,title="CautionHigh",style=label.style_triangleup,color=color.yellow,location=location.abovebar)

Caution_DOWN = FullD < caution_low
plotshape(series=Caution_DOWN,title="CautionLow",style=label.style_triangledown,color=color.yellow,location=location.belowbar)

Weak1 = FullD < 48  and FullD  > 25 and FullD[1] < 48 and FullD[1] < FullD[2] and FullD[2] < 48 and FullD[2] > 25 and FullD  > FullD[1] ? FullD : na
plotchar(Weak1,title="WeakBuy",char="⬆", color=color.lime,location=location.belowbar,text="WB")

Weak2 = FullD > 52  and FullD  < 75 and FullD[1] > 52 and FullD[1] > FullD[2] and FullD[2] > 52 and FullD[2] <75 and FullD  < FullD[1] ? FullD : na
plotchar(Weak2,title="WeakSell",char="⬇", color=color.fuchsia,location=location.abovebar,text="WS")

Lower Version

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © egshih

//@version=4
study(title="ElasticStochastic Lower",overlay=false)
//#Elastic Stochastic Lower with signals
//#Assembled by Chewie on usethinkscript.com https://usethinkscript.com/threads/elastic-stochastic-for-thinkorswim-upper-and-lower-indicator.4360/
//Converted over to TradingView by egshih

over_bought = input(defval=80,title="OverBought")
over_sold = input(defval=20,title="OverSold")
KPeriod = input(title="KPeriod",defval=5)
DPeriod = input(title="DPeriod",defval=3)
slowing_period = input(title="Slowing Period",defval=2)
smoothingType =input(title="AverageType",defval="SMA",options=["SMA","EMA"])

priceH = high
priceL = low
priceC = close
lowest_k = lowest(priceL, KPeriod)
c1 = priceC - lowest_k
c2 = highest(priceH, KPeriod) - lowest_k
FastK = c2 != 0 ? c1 / c2 * 100 : 0
fullk = sma(FastK, slowing_period)
FullD = sma(fullk, DPeriod)

FullDPlot=plot(series=FullD,title="FullD",color=color.yellow)

OverBought = over_bought
OverBoughtPlot=plot (OverBought,title="OverBoughtLine",color=color.red)
OverSold = over_sold
OverSoldPlot=plot (OverSold,title="OverSoldLine",color=color.green)


crossedb = crossunder(OverBought, FullD)

plotchar(crossedb,title="OverBoughtSignal",char="⬇",color=color.red,location=location.top,text="OB")
crossedu = crossover(FullD, OverSold)

plotchar(crossedu,title="OverBoughtSignal",char="⬆",color=color.green,location=location.bottom,text="OS")

fill(OverBoughtPlot,FullDPlot,color= FullD>OverBought?color.red:color.white)
fill(OverSoldPlot,FullDPlot,color= FullD<OverSold?color.green:color.white)

Weak1 = FullD < 48  and FullD  > 25 and FullD[1] < 48 and FullD[1] < FullD[2] and FullD[2] < 48 and FullD[2] > 25 and FullD  > FullD[1] ? FullD : na
plotchar(Weak1,title="WeakBuy",char="⬆", color=color.lime,location=location.bottom,text="WB")

Weak2 = FullD > 52  and FullD  < 75 and FullD[1] > 52 and FullD[1] > FullD[2] and FullD[2] > 52 and FullD[2] <75 and FullD  < FullD[1] ? FullD : na
plotchar(Weak2,title="WeakSell",char="⬇", color=color.fuchsia,location=location.top,text="WS")
 
Last edited by a moderator:
M

madpuri

Member
looks like a regular stochastic with one of the lines showing and arrows added. I don’t see any additions to the stochastic code to make it “elastic”

i like the idea but I am not seeing what makes it elastic in the code
 
S

s1111

New member
Looks great, thank you for sharing this Scripts . I'm new to trading , this website have been a amazing wealth of learning experience . I have downloaded 3-4 scripts but still making mistakes on timing which net me loss , hopefully as the day goes by I learn and be on the positive side. I mostly watch 5 min chart , is there any setting I need to change? also is there a way to add alert sound ?
Thanks in advance
 
M

madpuri

Member
Looks great, thank you for sharing this Scripts . I'm new to trading , this website have been a amazing wealth of learning experience . I have downloaded 3-4 scripts but still making mistakes on timing which net me loss , hopefully as the day goes by I learn and be on the positive side. I mostly watch 5 min chart , is there any setting I need to change? also is there a way to add alert sound ?
Thanks in advance
Indicators may provide some unique insight but most are rehashes of what is out there. Reading price bars are what it basically comes down too. Trading is not hard. All that there is to know can be taught in 1 hour max.
 
M

madpuri

Member
Yup just checked. This added nothing. Just a 532 setting without the D showing. Really don’t see how you added anything new.
 
chewie76

chewie76

Active member
VIP
VIP Enthusiast
Yup just checked. This added nothing. Just a 532 setting without the D showing. Really don’t see how you added anything new.
I created an upper indicator. That’s new. It added something.
 

Similar threads

Top