SuperTREX For ThinkOrSwim

Greetings,

Has this indicator been converted to TOS?

https://www.tradingview.com/script/cAQJtauT-SuperTREX/

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

//@version=4
study(title = "SuperTREX", overlay = true)

length = input( 14 )
overSold = input( 35 )
overBought = input( 70 )
p = close
vrsi = rsi(p, length)
price = close
var bool long = na
var bool short = na
long :=crossover(vrsi,overSold)
short := crossunder(vrsi,overBought)
var float last_open_long = na
var float last_open_short = na
last_open_long := long ? close : nz(last_open_long[1])
last_open_short := short ? close : nz(last_open_short[1])

entry_value =last_open_long
entry_value1=last_open_short
xy=(entry_value+entry_value)/2
// INPUTS //
st_mult = input(4, title = 'SuperTrend Multiplier', minval = 0, maxval = 100, step = 0.01)
st_period = input(10, title = 'SuperTrend Period', minval = 1)
// CALCULATIONS //
up_lev =xy - (st_mult * atr(st_period))
dn_lev =xy + (st_mult * atr(st_period))
up_trend = 0.0
up_trend := entry_value[1] > up_trend[1] ? max(up_lev, up_trend[1]) : up_lev
down_trend = 0.0
down_trend := entry_value1[1] < down_trend[1] ? min(dn_lev, down_trend[1]) : dn_lev
// Calculate trend var
trend = 0
trend := close > down_trend[1] ? 1: close < up_trend[1] ? -1 : nz(trend[1], 1)
// Calculate SuperTrend Line
st_line = trend ==1 ? up_trend : down_trend
plot(xy,color = trend == 1 ? color.green : color.red)
buy=crossover( xy, st_line)
sell=crossunder(xy, st_line)
plotshape(buy, title="buy", text="Buy", color=color.green, style=shape.labelup, location=location.belowbar, size=size.small, textcolor=color.white, transp=0) //plot for buy icon
plotshape(sell, title="sell", text="Sell", color=color.red, style=shape.labeldown, location=location.abovebar, size=size.small, textcolor=color.white, transp=0) //plot for sell icon
/////// Alerts /////
alertcondition(buy,title="buy")
alertcondition(sell,title="sell")
check the be below
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © RafaelZioni
#study(title = "SuperTREX", overlay = true)
# converted and modifiedTrueRange by Sam4Cok@Samer800 - 02/2023

input ShowBubbles = yes;
input ShowCloud = yes;
input ShowTrendLine = yes;
input price = close;
input RsiLength = 16;
input overBought = 60;
input overSold = 39;
input st_mult   = 4.04;    # 'SuperTrend Multiplier'
input st_period = 10;      # 'SuperTrend Period'

def na = Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if isNaN(data) then repl else data;
    plot return = ret_val;
}

def vrsi = RSI(Price = price, Length = RsiLength);

def long  = Crosses(vrsi, overSold, CrossingDirection.ABOVE);
def short = Crosses(vrsi, overBought, CrossingDirection.BELOW);

def last_open_long;# = na
def last_open_short;# = na

last_open_long = if long then price else nz(last_open_long[1],price);
last_open_short = if short then price else nz(last_open_short[1],price);


def entry_value  = last_open_long;
def entry_value1 = last_open_short;

def xy=(entry_value + entry_value)/2;

#// CALCULATIONS //
def Multi = st_mult * atr(Length=st_period);
def up_lev = xy - Multi;
def dn_lev = xy + Multi;

def up_trend; def down_trend;
up_trend   = if entry_value[1] > nz(up_trend[1], price) then max(up_lev, up_trend[1]) else up_lev;
down_trend = if entry_value1[1] < nz(down_trend[1],price) then min(dn_lev, down_trend[1]) else dn_lev;

#// Calculate trend var
def trend1;
trend1 = if price > down_trend[1] then 1 else if price < up_trend[1] then -1 else nz(trend1[1],1);
def trend = nz(trend1,1);
#// Calculate SuperTrend Line
def st_line = if trend ==1 then up_trend else down_trend;

plot Uptrend = if ShowTrendLine and trend ==1 then st_line else na;
Uptrend.SetDefaultColor(Color.GREEN);
plot Dntrend = if ShowTrendLine and trend !=1 then st_line else na;
Dntrend.SetDefaultColor(Color.RED);

plot Line = xy;#,color = trend == 1 ? color.green : color.red)
Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Line.AssignValueColor( if trend==1 then Color.GREEN else Color.RED);

def buy  = crosses(xy, st_line, CrossingDirection.ABOVE);
def sell = crosses(xy, st_line, CrossingDirection.BELOW);

AddChartBubble(ShowBubbles and buy, low, "B", color.green, no);
AddChartBubble(ShowBubbles and sell, high, "S", color.red, yes);

AddCloud(if ShowCloud and trend==1 then ohlc4 else na,xy,Color.DARK_GREEN);
AddCloud(if ShowCloud and trend!=1 then xy else na, ohlc4,Color.DARK_RED);


#---- END CODE
 
check the be below
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © RafaelZioni
#study(title = "SuperTREX", overlay = true)
# converted and modifiedTrueRange by Sam4Cok@Samer800 - 02/2023

input ShowBubbles = yes;
input ShowCloud = yes;
input ShowTrendLine = yes;
input price = close;
input RsiLength = 16;
input overBought = 60;
input overSold = 39;
input st_mult   = 4.04;    # 'SuperTrend Multiplier'
input st_period = 10;      # 'SuperTrend Period'

def na = Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if isNaN(data) then repl else data;
    plot return = ret_val;
}

def vrsi = RSI(Price = price, Length = RsiLength);

def long  = Crosses(vrsi, overSold, CrossingDirection.ABOVE);
def short = Crosses(vrsi, overBought, CrossingDirection.BELOW);

def last_open_long;# = na
def last_open_short;# = na

last_open_long = if long then price else nz(last_open_long[1],price);
last_open_short = if short then price else nz(last_open_short[1],price);


def entry_value  = last_open_long;
def entry_value1 = last_open_short;

def xy=(entry_value + entry_value)/2;

#// CALCULATIONS //
def Multi = st_mult * atr(Length=st_period);
def up_lev = xy - Multi;
def dn_lev = xy + Multi;

def up_trend; def down_trend;
up_trend   = if entry_value[1] > nz(up_trend[1], price) then max(up_lev, up_trend[1]) else up_lev;
down_trend = if entry_value1[1] < nz(down_trend[1],price) then min(dn_lev, down_trend[1]) else dn_lev;

#// Calculate trend var
def trend1;
trend1 = if price > down_trend[1] then 1 else if price < up_trend[1] then -1 else nz(trend1[1],1);
def trend = nz(trend1,1);
#// Calculate SuperTrend Line
def st_line = if trend ==1 then up_trend else down_trend;

plot Uptrend = if ShowTrendLine and trend ==1 then st_line else na;
Uptrend.SetDefaultColor(Color.GREEN);
plot Dntrend = if ShowTrendLine and trend !=1 then st_line else na;
Dntrend.SetDefaultColor(Color.RED);

plot Line = xy;#,color = trend == 1 ? color.green : color.red)
Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Line.AssignValueColor( if trend==1 then Color.GREEN else Color.RED);

def buy  = crosses(xy, st_line, CrossingDirection.ABOVE);
def sell = crosses(xy, st_line, CrossingDirection.BELOW);

AddChartBubble(ShowBubbles and buy, low, "B", color.green, no);
AddChartBubble(ShowBubbles and sell, high, "S", color.red, yes);

AddCloud(if ShowCloud and trend==1 then ohlc4 else na,xy,Color.DARK_GREEN);
AddCloud(if ShowCloud and trend!=1 then xy else na, ohlc4,Color.DARK_RED);


#---- END CODE
Big up Samer
 

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
293 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