0% found this document useful (0 votes)
51 views4 pages

RSI

The document contains code for multiple technical analysis indicators and scripts, including: 1) An RSI indicator that allows customizing the RSI length and moving average type and length for smoothing. 2) A "Pista Ciclica" script that calculates an oscillator by taking the difference between short and long EMAs. 3) A "Pi Cycle" script that identifies cycle tops and bottoms in Bitcoin prices by looking for crossovers between short and long simple moving averages of Bitcoin highs and lows. 4) A Stochastic RSI indicator that calculates the stochastic oscillator values K and D based on a RSI value, and includes customizable smoothing and length parameters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views4 pages

RSI

The document contains code for multiple technical analysis indicators and scripts, including: 1) An RSI indicator that allows customizing the RSI length and moving average type and length for smoothing. 2) A "Pista Ciclica" script that calculates an oscillator by taking the difference between short and long EMAs. 3) A "Pi Cycle" script that identifies cycle tops and bottoms in Bitcoin prices by looking for crossovers between short and long simple moving averages of Bitcoin highs and lows. 4) A Stochastic RSI indicator that calculates the stochastic oscillator values K and D based on a RSI value, and includes customizable smoothing and length parameters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

//@version=5

indicator(title="Relative Strength Index", shorttitle="RSI", format=format.price,


precision=2, timeframe="", timeframe_gaps=true)

ma(source, length, type) =>


switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")


rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger
Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev",
group="MA Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)


down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
isBB = maTypeInput == "Bollinger Bands"

plot(rsi, "RSI", color=#7E57C2)


plot(rsiMA, "RSI-based MA", color=color.yellow)
rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI
Background Fill")
bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na,
title = "Upper Bollinger Band", color=color.green)
bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na,
title = "Lower Bollinger Band", color=color.green)
fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na,
title="Bollinger Bands Background Fill")

----------------------------------------------------------------------------------
Pista Ciclica - critical track

version 2.0

//@version=3
study("Pista Ciclica")
lenght = input(25, minval=1)
ema = ema(close, lenght)
ema2 = ema(close, 1)
pista_ciclica = ema2 - ema
hline = hline(0, color=red, linestyle=dotted)
bcolor = iff( pista_ciclica > 0, iff( pista_ciclica > nz(pista_ciclica[1]), lime,
green), iff( pista_ciclica < nz(pista_ciclica[1]), red, maroon))
plot(pista_ciclica, style=area, color=bcolor, title="Pista ciclica")

----------------------------------------------------------------------------------
Pista Ciclica - critical track
version 1.0

//@version=3
study("My Script")
ema = ema(close, 25)
ema2 = ema(close, 1)
pista_ciclica = ema2 - ema
hline = hline(0, color=red, linestyle=dotted)
plot(pista_ciclica, style=area, color = change(pista_ciclica) <= 0 ? red : green,
title="Pista ciclica")

-----------------------------------------------------------------------------------
--------------------
PI cycle

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

//@version=4
study("Pi Cycle Bitcoin High/Low", shorttitle="Pi Cycle Bitcoin High/Low",
overlay=true)

//Create Inputs for the 4 MAs, and Visual

lowma_long = input(471, minval=1, title="BTC Low - Long SMA")


is_show_lowma1 = input(true, type=input.bool, title="Show Low Long SMA?")

lowema_short = input(150, minval=1, title="BTC Low - Short EMA")


is_show_lowma2 = input(true, type=input.bool, title="Show Low Short EMA?")

hima_long = input(350, minval=1, title="BTC High - Long SMA")


is_show_hima1 = input(true, type=input.bool, title="Show High Long SMA?")

hima_short = input(111, minval=1, title="BTC High - Short SMA")


is_show_hima2 = input(true, type=input.bool, title="Show High Short SMA?")

//Set resolution to the Daily Chart


resolution = input('D', type=input.string, title="Time interval")

//Run the math for the 4 MAs


ma_long_low = security(syminfo.tickerid, resolution, sma(close,
lowma_long)*745)/1000
ema_short_low = security(syminfo.tickerid, resolution, ema(close, lowema_short))
ma_long_hi = security(syminfo.tickerid, resolution, sma(close, hima_long)*2)
ma_short_hi = security(syminfo.tickerid, resolution, sma(close, hima_short))

//Set SRC
src = security(syminfo.tickerid, resolution, close)

//Plot the 4 MAs


plot(is_show_lowma1?ma_long_low:na, color=color.red, linewidth=2, title="Low Long
MA")
var lowma_long_label = label.new(x = bar_index, y = lowma_long, color =
color.rgb(0, 0, 0, 100), style = label.style_label_left, textcolor = color.red,
text = "BTC Low - Long SMA")
label.set_xy(lowma_long_label, x = bar_index, y = ma_long_low)
plot(is_show_lowma2?ema_short_low:na, color=color.green, linewidth=2, title="Low
Short EMA")
var lowema_short_label = label.new(x = bar_index, y = lowema_short, color =
color.rgb(0, 0, 0, 100), style = label.style_label_left, textcolor = color.green,
text = "BTC Low - Short EMA")
label.set_xy(lowema_short_label, x = bar_index, y = ema_short_low)

plot(is_show_hima1?ma_long_hi:na, color=color.white, linewidth=2, title="High Long


MA")
var hima_long_label = label.new(x = bar_index, y = hima_long, color = color.rgb(0,
0, 0, 100), style = label.style_label_left, textcolor = color.white, text = "BTC
High - Long MA")
label.set_xy(hima_long_label, x = bar_index, y = ma_long_hi)

plot(is_show_hima2?ma_short_hi:na, color=color.yellow, linewidth=2, title="High


Short MA")
var hima_short_label = label.new(x = bar_index, y = hima_short, color =
color.rgb(0, 0, 0, 100), style = label.style_label_left, textcolor = color.yellow,
text = "BTC High - Short MA")
label.set_xy(hima_short_label, x = bar_index, y = ma_short_hi)

//Find where the MAs cross each other


PiCycleLow = crossunder(ema_short_low, ma_long_low) ? src + (src/100 * 10) : na
PiCycleHi = crossunder(ma_long_hi, ma_short_hi) ? src + (src/100 * 10) : na

//Create Labels
plotshape(PiCycleLow, text="Pi Cycle Low", color=color.navy, textcolor=color.white,
style=shape.labelup,size=size.normal, location=location.belowbar, title="Cycle
Low")
plotshape(PiCycleHi, text="Pi Cycle High", color=color.teal, textcolor=color.white,
style=shape.labeldown,size=size.normal, location=location.abovebar, title="Cycle
High")

//Generate vertical lines at the BTC Halving Dates


isDate(y, m, d) =>
val = timestamp(y,m,d)
if val <= time and val > time[1]
true
else
false

// First Halving
if isDate(2012, 11, 28)
line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both,
style=line.style_dashed, color=color.yellow)
label.new(bar_index, low, text="1st Halving - Nov 28, 2012",
style=label.style_label_upper_left, textcolor=color.yellow, color=color.black,
textalign=text.align_right, yloc=yloc.belowbar)

// Second Halving
if isDate(2016, 7, 9)
line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both,
style=line.style_dashed, color=color.yellow)
label.new(bar_index, low, text="2nd Halving - Jul 9, 2016",
style=label.style_label_upper_left, textcolor=color.yellow, color=color.black,
textalign=text.align_right, yloc=yloc.belowbar)

// Third Halving
if isDate(2020, 5, 11)
line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both,
style=line.style_dashed, color=color.yellow)
label.new(bar_index, low, text="3rd Halving - May 11, 2020",
style=label.style_label_upper_left, textcolor=color.yellow, color=color.black,
textalign=text.align_right, yloc=yloc.belowbar)

// Fourth Halving
//if isDate(2024, 3, 26)
// line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both,
style=line.style_dashed, color=color.yellow)
// label.new(bar_index, low, text="4th Halving - March 26, 2024",
style=label.style_label_upper_left, textcolor=color.yellow, color=color.black,
textalign=text.align_right, yloc=yloc.belowbar)

-----------------------------------------------------------------------------------
----------

//@version=4
study(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price,
precision=2, resolution="", overlay=true)

lenSMA = input(26, minval = 1, title = "SMA Length")


lenEMA = input(9, minval = 1, title = "EMA Length")

plot(sma(close, lenSMA), color = color.black, linewidth = 3, title = "Plot SMA")


plot(ema(close, lenEMA), color = color.purple, linewidth = 2, title = "Plot EMA")

//Daily Open
dOpen = security(syminfo.tickerid, "D", open, lookahead = barmerge.lookahead_on)

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)
k1 = k+dOpen
d1 = d+dOpen
plot(k1, "K", color=#0094FF)
plot(d1, "D", color=#FF6A00)
h00 = dOpen+80
h11 = dOpen+20
h0 = plot(h00, "Upper Band", color=#606060)
h1 = plot(h11, "Lower Band", color=#606060)

You might also like