Triangular Stoch RSI Bands For ThinkOrSwim

Darth Tradicus

Member
VIP
The author states:
The indicator calculates Triangularity over Stoch RSI Overbought and Oversold Conditions
Ever wondered how far above overbought and below oversold, the conditions are?

The indicator plots auto band levels above overbought and below oversold
hHI97DB.png


https://www.tradingview.com/script/8OVkDNNf-Triangular-Stoch-RSI-Bands/
 
Last edited by a moderator:
https://www.tradingview.com/script/8OVkDNNf-Triangular-Stoch-RSI-Bands/

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

//@version=4
study("Triangular Stoch RSI Bands", overlay=true)

tma(src, length) =>
    ema(ema(ema(src,length), length), length)

l = input(20, "dynamic Length")

pivot1 = (highest(high, 9) + lowest(low, 9))/2
pivot2 = (highest(high, 26) + lowest(low, 26))/2
cum=(pivot1+pivot2)/2

adjust_n= cum - 0.89*atr(14)
adjust_p= cum + 0.89*atr(14)

Dynamic_Long = tma(adjust_n,l)
Dynamic_Short = tma(adjust_p,l)


// plot(Dynamic_Long, color=color.green)
// plot(Dynamic_Short, color=color.red)


//Stochastic RSI
smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
overbought = 80
oversold = 20

uc_long_condition = close>Dynamic_Long and close>Dynamic_Short and crossunder(k, 20)
uc_short_condition = close<Dynamic_Long and close<Dynamic_Short and crossover(k, 80)

//Calculations
var trend_number = 0
if close>Dynamic_Short or close<Dynamic_Long
    trend_number := nz(trend_number[1]) + 1

var highs = float(na)-float(na)
var lows = float(na)-float(na)

atr = 0//0.618*atr(14)

if uc_long_condition
    highs := high + atr
else if uc_short_condition
    lows := low - atr

tma_highs = tma(highs,l)
tma_lows = tma(lows,l)
base = (tma_highs+tma_lows)/2
p1=plot(tma_highs, color=color.green)
p2=plot(tma_lows, color=color.red)
plot(base, color=color.gray, transp=50)
fill(p1, p2, color=color.yellow)

pc = plot(close, transp=100)

fill(pc, p1, color= close>tma_highs ? color.green: na)
fill(pc, p2, color= close<tma_lows ? color.red: na)

//Plotting LEVELS


dep = input(0.01, " DEPTH 1")
upper1 = tma_highs  + tma_highs*dep
lower1 = tma_lows  - tma_lows*dep
plot(upper1, color=color.gray, transp=50)
plot(lower1, color=color.gray, transp=50)

dep2 = input(0.0168, " DEPTH 2")
upper2 = tma_highs  + tma_highs*dep2
lower2 = tma_lows  - tma_lows*dep2
plot(upper2, color=color.blue, transp=50)
plot(lower2, color=color.blue, transp=50)


dep3 = input(0.0314, " DEPTH 3")
upper3 = tma_highs  + tma_highs*dep3
lower3 = tma_lows  - tma_lows*dep3
plot(upper3, color=color.gray, transp=50)
plot(lower3, color=color.gray, transp=50)

dep4 = input(0.0446, " DEPTH 4")
upper4 = tma_highs  + tma_highs*dep4
lower4 = tma_lows  - tma_lows*dep4
plot(upper4, color=color.blue, transp=50)
plot(lower4, color=color.blue, transp=50)
check the below. I just modified the band as well.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Ankit_1618
#study("Triangular Stoch RSI Bands", overlay=true)
# Converted and mod by Sam4Cok@Samer800    - 04/2024

input Source = close; #, title="RSI Source")
input atrMulit = 0.89;
input pivotLength1 = 9;
input pivotLength2 = 26;
input dynamicLength = 20; #, "dynamic Length")
input smoothK = 3; #, "K", minval=1)
input smoothD = 3; #, "D", minval=1)
input rsiLength = 14; #, "RSI Length", minval=1)
input StochasticLength = 14; #, "Stochastic Length", minval=1)
input overboughtLevel = 80;
input oversoldLevel = 20;

def na = Double.NaN;

# stoch(source, high, low, length) =>
script stoch {
    input src = close;
    input h = high;
    input l = low;
    input len = 14;
    def hh = Highest(h, len);
    def ll = Lowest(l, len);
    def stoch = 100 * (src - ll) / (hh - ll);
    plot return = stoch;
}
#-- TMA
script tma {
    input src = close;
    input length = 20;
    def ema1 = ExpAverage(src, length);
    def ema2 = ExpAverage(ema1, length);
    def ema3 = ExpAverage(ema2, length);
    plot tma = ema3;
}
def nATR = ATR(Length = 14);
def nATR1 = Min(Source * 0.3/100, nATR);
def hh1 = Highest(high, pivotLength1);
def hh2 = Highest(high, pivotLength2);
def ll1 = Lowest(low, pivotLength1);
def ll2 = Lowest(low, pivotLength2);
def pivot1 = (hh1 + ll1) / 2;
def pivot2 = (hh2 + ll2) / 2;
def cum = (pivot1 + pivot2) / 2;
def adjust_n = cum - atrMulit * nATR;
def adjust_p = cum + atrMulit * nATR;

def Dynamic_Long  = tma(adjust_n, dynamicLength);
def Dynamic_Short = tma(adjust_p, dynamicLength);

def rsi1 = RSI(Price = Source, Length = rsiLength);
def stoch1 = stoch(rsi1, rsi1, rsi1, StochasticLength);
def k = Average(stoch1, smoothK);
def d = Average(k, smoothD);

def uc_long_condition = Source > Dynamic_Long and Source > Dynamic_Short and (k crosses below oversoldLevel);
def uc_short_condition = Source < Dynamic_Long and Source < Dynamic_Short and (k crosses above overboughtLevel);

#/Calculations
#def trend_number = if Source>Dynamic_Short or Source<Dynamic_Long then trend_number[1] + 1 else 0;

def highs = if uc_long_condition then high else if highs[1] then highs[1] else hh2;
def lows = if uc_short_condition then low  else if lows[1] then lows[1] else ll2;

def tma_highs = tma(if !isNAN(highs) then highs else hh2,dynamicLength);
def tma_lows = tma(if !isNaN(lows) then lows else ll2,dynamicLength);
def base = (tma_highs+tma_lows)/2;

plot tmaHi = tma_highs; #, color=color.green)
plot tmaLo = tma_lows; #, color=color.red)
plot baseLine = base; #, color=color.gray, transp=50)
tmaHi.SetDefaultColor(Color.GREEN);
tmaLo.SetDefaultColor(Color.RED);
baseLine.SetDefaultColor(Color.GRAY);
#//Plotting LEVELS

input showBand = yes;
input bandLvl1 = 0.236; #, " DEPTH 1")
input bandLvl2 = 0.382; #, " DEPTH 2")
input bandLvl3 = 0.500; #, " DEPTH 3")
input bandLvl4 = 0.618; #, " DEPTH 4")

def diff = if showBand then WildersAverage(tma_highs - tma_lows, dynamicLength) else na;

def upper1 = tma_highs + diff * bandLvl1;
def upper2 = tma_highs + diff * bandLvl2;
def upper3 = tma_highs + diff * bandLvl3;
def upper4 = tma_highs + diff * bandLvl4;
def lower1 = tma_lows  - diff * bandLvl1;
def lower2 = tma_lows  - diff * bandLvl2;
def lower3 = tma_lows  - diff * bandLvl3;
def lower4 = tma_lows  - diff * bandLvl4;

def up1 = upper1;
def up2 = upper2;
def up3 = upper3;
def up4 = upper4;
def lo1 = lower1;
def lo2 = lower2;
def lo3 = lower3;
def lo4 = lower4;

DefineGlobalColor("Green1" , CreateColor(4,181,4));
DefineGlobalColor("Green2" , CreateColor(3,145,3));
DefineGlobalColor("Green3" , CreateColor(2,117,2));
DefineGlobalColor("Green4" , CreateColor(1,93,1));

DefineGlobalColor("Red1" , CreateColor(184,4,4));
DefineGlobalColor("Red2" , CreateColor(145,3,3));
DefineGlobalColor("Red3" , CreateColor(117,2,2));
DefineGlobalColor("Red4" , CreateColor(100,1,1));

AddCloud(up4, up3, GlobalColor("Green1"), GlobalColor("Green1"), yes);
AddCloud(up3, up2, GlobalColor("Green2"), GlobalColor("Green2"), yes);
AddCloud(up2, up1, GlobalColor("Green3"), GlobalColor("Green3"), yes);
AddCloud(up1, tma_highs, GlobalColor("Green4"));

AddCloud(lo3, lo4, GlobalColor("Red1"), GlobalColor("Red1"), yes);
AddCloud(lo2, lo3, GlobalColor("Red2"), GlobalColor("Red2"), yes);
AddCloud(lo1, lo2, GlobalColor("Red3"), GlobalColor("Red3"), yes);
AddCloud(tma_lows, lo1, GlobalColor("Red4"));

#AddChartBubble(trend_number==1, close, "TT", Color.WHITE);
#-- 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
251 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