Stochastic Zone Strength Trend [wbburgin] For ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
SQvmX1R.png

Author Message:
The Stochastic Zone Strength Trend indicator is a very powerful momentum and trend indicator that 1) identifies trend direction and strength, 2) determines pullbacks and reversals (including oversold and overbought conditions), 3) identifies divergences, and 4) can filter out ranges. I have some examples below on how to use it to its full effectiveness. It is composed of two components: Stochastic Zone Strength and Stochastic Trend Strength.
More details : https://www.tradingview.com/v/KBgIgpIN/

CODE:
CSS:
#https://www.tradingview.com/v/KBgIgpIN/
#// © wbburgin
#indicator('Stochastic Zone Strength Trend [wbburgin]', overlay=false)
# Converted by Sam4Cok@Samer800    - 07/2023
declare lower;
#rescale(series float src, float oldMin, float oldMax, float newMin, float newMax) =>
script rescale {
    input src = close;
    input waveLength = 200;
    input newMin = 0;
    input newMax = 100;
    def oldMin = if src == lowest(src, waveLength) then src else oldMin[1];
    def oldMax = if src == highest(src, waveLength) then src else oldMax[1];
    def rescale = newMin + (newMax - newMin) * (src - oldMin) / Max(oldMax - oldMin, 0.000001);
    plot out = rescale;
}
# stoch(source, high, low, length) =>
script stoch {
    input src = close;
    input len = 200;
    def lowest_k = Lowest(src, len);
    def c1 = src - lowest_k;
    def c2 = Highest(src, len) - lowest_k;
    def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
    plot return = FastK;
}
#anysource_zonestrength(int amplitude, simple int wavelength, float source) =>
script anysource_zonestrength {
    input amplitude = 15;
    input wavelength = 200;
    input source = close;
    def hx = Highest(source, amplitude);
    def lx = Lowest(source, amplitude);
    def HLA = 0.25 * ((2 * source) + hx + lx);
    def OCP = source[1];
    def g = (HLA + OCP) / 2;
    def stringer_prerun = if HLA > OCP then
                          if hx > HLA then hx - HLA + hx - OCP else hx - OCP else
                          if lx < HLA then lx - OCP - HLA + lx else lx - OCP;
    def h = g * (1 + (stringer_prerun) * -1 / g);
    def amp_highest = Highest(h, amplitude);
    def amp_lowest = Lowest(h, amplitude);
    def s = ExpAverage(amp_lowest, wavelength);
    def t = ExpAverage(amp_highest, wavelength);
    def u = (HLA - s) / (t - s) - 0.5;
    plot out = u;
}
#anysource_str(int amplitude, float source)=>
script anysource_str {
    input amplitude = 15;
    input source = close;
    def hx = Highest(source, amplitude);
    def lx = Lowest(source, amplitude);
    def ha_close =  0.25 * ((2 * source) + hx + lx);
    def ha_open = source[1];
    def haAVG = (ha_close + ha_open) / 2;
    def stringer_prerun = if ha_close > ha_open then
                          if hx > ha_close then hx - ha_close + hx - ha_open else hx - ha_open else
                          if lx < ha_close then lx - ha_open - ha_close + lx else lx - ha_open;
    def str = AbsValue(stringer_prerun);
    plot out = str;
}
#stochzonestrength(float source, string form,simple int amplitude,simple int wavelength,simple int smoothing=3)=>
script stochzonestrength {
    input source = close;
    input form = 0;
    input amplitude = 15;
    input wavelength = 200;
    input smoothing = 3;
    def zs = anysource_zonestrength(amplitude, wavelength, source);
    def k2 = Average(stoch(zs, wavelength), smoothing);
    def zsp = ExpAverage(anysource_str(amplitude, source), wavelength);
    def k4 = Average(stoch(zsp, wavelength), smoothing);
    def szs = if form==0 then k2 else k4;#if form!=0 then k4 else Double.NaN;
    plot out = szs;
}
input src = close;
input amplitude = 15;        # 'Amplitude'
input waveLength = 200;      # 'Wavelength'
input SmoothingFactor = 3;           # "Smoothing Factor"
input showZoneStrength = yes;        # "Show Zone Strength"
input showTrendStrength = yes;       # "Show Trend Strength"
input TrendAnchor = {"0", default "50"};           # "Trend Anchor"
input trendTransformLength = 200;                  # "Trend Transform MA Length"
input trendPlotType = {default "Area", "Line"};    # "Trend Plot Type"

def na = Double.NaN;
def last = isNaN(close);
def "0" = TrendAnchor==TrendAnchor."0";
def "50" = TrendAnchor==TrendAnchor."50";
#//Zone Strength
def zs = anysource_zonestrength(amplitude,wavelength,src);
def zs_Color = rescale(zs, wavelength);
#//Stochastic Zone Strength - Normal
def stoch = stochzonestrength(src,0,amplitude,wavelength,SmoothingFactor);
#//Stochastic Zone Strength - Trend Strength
def trend = stochzonestrength(src,1,amplitude,wavelength,SmoothingFactor);
def trend_form2 = (trend - ExpAverage(trend, trendTransformLength)) + 50;
def color_trend = rescale(stoch,wavelength);# (AbsValue(floor(stoch));

plot ZoneStrength = if showZoneStrength then stoch else na;    # "Zone Strength"
ZoneStrength.AssignValueColor(if zs_Color > 80 then Color.RED else
                              if zs_Color < 20 then Color.GREEN else
                              CreateColor(255-zs_Color * 2,255-zs_Color * 2, 0));
ZoneStrength.SetLineWeight(2);

plot TrendStrReg = if showTrendStrength and "0" and trendPlotType == trendPlotType."Area"
                   then trend else na;    # "Trend Strength - Regular - Area"
TrendStrReg.AssignValueColor(CreateColor(255-color_trend * 2, 0,255- color_trend*2));
TrendStrReg.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

plot TrendStrLin = if showTrendStrength and "0" and trendPlotType == trendPlotType."Line"
                   then trend else na;    # "Trend Strength - Regular - Line"
TrendStrLin.AssignValueColor(CreateColor(255-color_trend * 2, 0,255- color_trend*2));
TrendStrLin.SetLineWeight(2);

plot tf2 = if showTrendStrength and "50" then trend_form2 else na;#, "Trend Transform"
tf2.AssignValueColor(CreateColor(255-color_trend * 2, 0,255- color_trend*2));
tf2.SetLineWeight(2);

plot midline = if last then na else 50;
midline.SetDefaultColor(Color.WHITE);

plot overbought = if last then na else 80;
plot oversold = if last then na else 20;
overbought.SetDefaultColor(Color.GRAY);
oversold.SetDefaultColor(Color.GRAY);
overbought.SetStyle(Curve.SHORT_DASH);
oversold.SetStyle(Curve.SHORT_DASH);
#fill(overbought,oversold,color.new(color.purple,95))
#-- Clouds

AddCloud(tf2,midline, Color.MAGENTA, Color.MAGENTA);
AddCloud(TrendStrReg,0, Color.MAGENTA, Color.MAGENTA);

AddCloud(if stoch>= 80 then stoch else na,80, Color.DARK_RED);
AddCloud(if stoch<= 20 then 20 else na,stoch, Color.DARK_GREEN);

#--- END of CODE
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
425 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