Plot RSI
Plot RSI
Plot RSI
0 at
https://mozilla.org/MPL/2.0/
//@version=5
ha_t = ticker.heikinashi(syminfo.tickerid)
candle_type = input.string('true', title='heikinashi ??', options=['true',
'false'])
var x = true
if candle_type == 'true'
x = true
x
else
x = false
x
clos = request.security(ha_t, timeframe.period, close,
lookahead=barmerge.lookahead_on)
src = clos
len = input(21, 'Length RSI')
ad = input(true, 'RSI Advanced ?? (Recommend)')
cdob = input.string('Candle', title='Candle or Bar or Line?', options=['Candle',
'Bar', 'Line'])
uc = input(color.green, 'Up Color')
dc = input(color.red, 'Down Color')
timeframe_rsi2 = input.timeframe(defval='30', title='RSI timeframe 2')
u = math.max(src - src[1], 0)
d = math.max(src[1] - src, 0)
a = 1 / len
ruh = a * math.max(high - close[1], 0) + (1 - a) * ta.rma(u, len)[1]
rdh = (1 - a) * ta.rma(d, len)[1]
rsih = if ad
function(rsiha, len)
else
rsiha
rsil = if ad
function(rsila, len)
else
rsila
rsi = if ad
function(rsia, len)
else
rsia
//ma1_rsi = ema(rsi,lma1)
ma2_rsi = ta.ema(rsi, lma2)
ma3_rsi = ta.ema(rsi, lma3)
ma4_rsi = ta.ema(rsi, lma4)
ma5_rsi = ta.ema(rsi, lma5)
ma6_rsi = ta.ema(rsi, lma6)
/// divergence
prd = input.int(defval=5, title='Pivot Period', minval=1, maxval=50)
source = input.string(defval='Close', title='Source for Pivot Points',
options=['Close', 'High/Low'])
searchdiv = input.string(defval='Regular/Hidden', title='Divergence Type',
options=['Regular', 'Hidden', 'Regular/Hidden'])
showindis = input.string(defval='Full', title='Show Indicator Names',
options=['Full', 'First Letter', 'Don\'t Show'])
showlimit = input.int(1, title='Minimum Number of Divergence', minval=1, maxval=11)
maxpp = input.int(defval=10, title='Maximum Pivot Points to Check', minval=1,
maxval=20)
maxbars = input.int(defval=200, title='Maximum Bars to Check', minval=5,
maxval=200)
shownum = input(defval=true, title='Show Divergence Number')
showlast = input(defval=false, title='Show Only Last Divergence')
dontconfirm = input(defval=false, title='Don\'t Wait for Confirmation')
showlines = input(defval=false, title='Show Divergence Lines')
showpivot = input(defval=false, title='Show Pivot Points')
calcmacd = input(defval=true, title='MACD')
calcmacda = input(defval=true, title='MACD Histogram')
calcrsi = input(defval=true, title='RSI')
calcstoc = input(defval=true, title='Stochastic')
calccci = input(defval=true, title='CCI')
calcmom = input(defval=false, title='Momentum')
calcobv = input(defval=true, title='OBV')
calcvwmacd = input(true, title='VWmacd')
calccmf = input(true, title='Chaikin Money Flow')
calcmfi = input(true, title='Money Flow Index')
calcext = input(false, title='Check External Indicator')
externalindi = input(defval=close, title='External Indicator')
pos_reg_div_col = input(defval=color.yellow, title='Positive Regular Divergence')
neg_reg_div_col = input(defval=color.navy, title='Negative Regular Divergence')
pos_hid_div_col = input(defval=color.lime, title='Positive Hidden Divergence')
neg_hid_div_col = input(defval=color.red, title='Negative Hidden Divergence')
pos_div_text_col = input(defval=color.black, title='Positive Divergence Text
Color')
neg_div_text_col = input(defval=color.white, title='Negative Divergence Text
Color')
reg_div_l_style_ = input.string(defval='Solid', title='Regular Divergence Line
Style', options=['Solid', 'Dashed', 'Dotted'])
hid_div_l_style_ = input.string(defval='Dashed', title='Hdden Divergence Line
Style', options=['Solid', 'Dashed', 'Dotted'])
reg_div_l_width = input.int(defval=2, title='Regular Divergence Line Width',
minval=1, maxval=5)
hid_div_l_width = input.int(defval=1, title='Hidden Divergence Line Width',
minval=1, maxval=5)
showmas = input.bool(defval=false, title='Show MAs 50 & 200', inline='ma12')
cma1col = input.color(defval=color.lime, title='', inline='ma12')
cma2col = input.color(defval=color.red, title='', inline='ma12')
// get indicators
rsidd = ta.rsi(rsi, 14) // RSI
[macd, signal, deltamacd] = ta.macd(rsi, 12, 26, 9) // MACD
moment = ta.mom(rsi, 10) // Momentum
cci = ta.cci(rsi, 10) // CCI
Obv = ta.obv // OBV
stk = ta.sma(ta.stoch(rsi, rsih, rsil, 14), 3) // Stoch
maFast = ta.vwma(rsi, 12) // volume weighted macd
maSlow = ta.vwma(rsi, 26)
vwmacd = maFast - maSlow
Cmfm = (rsi - rsil - (rsih - rsi)) / (rsih - rsi) // Chaikin money flow
Cmfv = Cmfm * volume
cmf = ta.sma(Cmfv, 21) / ta.sma(volume, 21)
Mfi = ta.mfi(rsi, 14) // Moneyt Flow Index
if arrived
divlen := len
break
divlen
// check minimum number of divergence, if less than showlimit then delete all
divergence
total_div = 0
for x = 0 to array.size(all_divergences) - 1 by 1
total_div += math.round(math.sign(array.get(all_divergences, x)))
total_div
for x = 0 to 10 by 1
div_type = -1
for y = 0 to 3 by 1
if array.get(all_divergences, x * 4 + y) > 0 // any divergence?
div_type := y
if y % 2 == 1
dnumdiv_top += 1
top_label_col := array.get(div_colors, y)
top_label_col
if y % 2 == 0
dnumdiv_bottom += 1
bottom_label_col := array.get(div_colors, y)
bottom_label_col
if not array.includes(distances, array.get(all_divergences, x * 4 + y))
// line not exist ?
array.push(distances, array.get(all_divergences, x * 4 + y))
// draw labels
if showindis != 'Don\'t Show' or shownum
if shownum and dnumdiv_top > 0
divergence_text_top += str.tostring(dnumdiv_top)
divergence_text_top
if shownum and dnumdiv_bottom > 0
divergence_text_bottom += str.tostring(dnumdiv_bottom)
divergence_text_bottom
if divergence_text_top != ''
if divergence_text_bottom != ''
////////////////////////
// breakout
////////////////////////
// === BACKTEST RANGE ===
From_Year = input(defval=2019, title='From Year')
From_Month = input.int(defval=1, title='From Month', minval=1, maxval=12)
From_Day = input.int(defval=1, title='From Day', minval=1, maxval=31)
To_Year = input(defval=9999, title='To Year')
To_Month = input.int(defval=1, title='To Month', minval=1, maxval=12)
To_Day = input.int(defval=1, title='To Day', minval=1, maxval=31)
Start = timestamp(From_Year, From_Month, From_Day, 00, 00) // backtest start
window
Finish = timestamp(To_Year, To_Month, To_Day, 23, 59) // backtest finish window
// A switch to control background coloring of the test period - Use for easy
visualization of backtest range and manual calculation of
// buy and hold (via measurement) if doing prior periods since value in Strategy
Tester extends to current date by default
testPeriodBackground = input(title='Color Background - Test Period?', defval=false)
testPeriodBackgroundColor = testPeriodBackground and time >= Start and time <=
Finish ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=95)
// == FILTERING ==
// Inputs
useMaFilter = input(title='Use MA for Filtering?', defval=false)
maType = input.string(defval='SMA', options=['EMA', 'SMA'], title='MA Type For
Filtering')
maLength = input.int(defval=200, title='MA Period for Filtering', minval=1)
// Check to see if the useMaFilter check box is checked, this then inputs this
conditional "maFilterCheck" variable into the strategy entry
maFilterCheck = if useMaFilter == true
maFilter
else
0
// === PLOT SWING HIGH/LOW AND MOST RECENT LOW TO USE AS STOP LOSS EXIT POINT ===
// Inputs
//pvtLenL = input(3, minval=1, title="Pivot Length Left Hand Side") //use if
you want to change this to an input
//pvtLenR = input(3, minval=1, title="Pivot Length Right Hand Side") //use if
you want to change this to an input
pvtLenL = 3
pvtLenR = 3
// Count How many candles for current Pivot Level, If new reset.
counthi = ta.barssince(not na(pvthi))
countlo = ta.barssince(not na(pvtlo))
pvthis = fixnan(pvthi)
pvtlos = fixnan(pvtlo)
hipc = ta.change(pvthis) != 0 ? na : color.maroon
lopc = ta.change(pvtlos) != 0 ? na : color.green
if sellStudy
label.new(x=bar_index, y=math.min(rsil, rsil[1]), text="S",
color=color.fuchsia, textcolor=color.white, style=label.style_label_down,
size=size.tiny)