Professional Documents
Culture Documents
Scripts
Scripts
0 at
https://mozilla.org/MPL/2.0/
// © ParkF
//@version=5
indicator('[_ParkF]RSI+', overlay=false, max_bars_back=1500)
// rsi divergence
// input
rsig = 'RSI'
rb = input(2, 'How many Right Bars for Pivots', group=rsig)
lb = input(15, 'How many Left Bars for Pivots', group=rsig)
sph = input(close, 'Pivot source for Bear Divs', group=rsig)
spl = input(close, 'Pivots Source for Bull Divs', group=rsig)
len = input.int(14, ' RSI Length', minval=1, group=rsig)
lvl = input.int(5, 'Lookback Level for Divs', options=[1, 2, 3, 4, 5], group=rsig)
// pivot
ph = ta.pivothigh(sph, lb, rb)
pl = ta.pivotlow(spl, lb, rb)
bear_div_1= hi0>hi1
and rh1>rh0
bear_div_2= hi0>hi1 and hi0>hi2
and rh2>rh0 and rh2>rh1 and lvl>=2
bear_div_3= hi0>hi1 and hi0>hi2 and hi0>hi3
and rh3>rh0 and rh3>rh1 and rh3>rh2 and lvl>=3
bear_div_4= hi0>hi1 and hi0>hi2 and hi0>hi3 and hi0>hi4
and rh4>rh0 and rh4>rh1 and rh4>rh2 and rh4>rh3 and lvl>=4
bear_div_5= hi0>hi1 and hi0>hi2 and hi0>hi3 and hi0>hi4 and hi0>hi5
and rh5>rh0 and rh5>rh1 and rh5>rh2 and rh5>rh3 and rh5>rh4 and lvl>=5
recall(x) =>
ta.barssince(not na(x))
// rsi function
pine_rsi(rsrc, len) =>
u = math.max(rsrc - rsrc[1], 0)
d = math.max(rsrc[1] - rsrc, 0)
rs = ta.rma(u, len) / ta.rma(d, len)
res = 100 - 100 / (1 + rs)
res
pine_rma(rsrc, length) =>
b = 1 / length
sum = 0.0
sum := na(sum[1]) ? ta.sma(rsrc, length) : b * rsrc + (1 - b) * nz(sum[1])
u = math.max(rsrc - rsrc[1], 0)
d = math.max(rsrc[1] - rsrc, 0)
b = 1 / len
ruh = b * math.max(high - close[1], 0) + (1 - b) * ta.rma(u, len)[1]
rdh = (1 - b) * ta.rma(d, len)[1]
rul = (1 - b) * ta.rma(u, len)[1]
rdl = b * math.max(close[1] - low, 0) + (1 - b) * ta.rma(d, len)[1]
function(rsi, len) =>
f = -math.pow(math.abs(math.abs(rsi - 50) - 50), 1 + math.pow(len / 14, 0.618)
- 1) / math.pow(50, math.pow(len / 14, 0.618) - 1) + 50
rsiadvanced = if rsi > 50
f + 50
else
-f + 50
rsiadvanced
rsiha = 100 - 100 / (1 + ruh / rdh)
rsila = 100 - 100 / (1 + rul / rdl)
rsia = ta.rsi(rsrc, len)
rsih = if ad
function(rsiha, len)
else
rsiha
rsil = if ad
function(rsila, len)
else
rsila
// candle
plotcandle(rsi[1], rsih, rsil, rsi, 'RSI_Candle', color=ta.change(rsi) > 0 ?
#ffffff : #000000, wickcolor=#000000, bordercolor=#2a2e39)
plot(rsi, 'RSI_Line', color= ta.change(rsi) > 0 ? color.black : color.black,
display=display.none, linewidth=2)
// linear regression
// input
lrg = 'Linear Regression'
linreg1 = input(true, 'Longterm Linear Regression On / Off', group=lrg)
periodTrend = input.int(100, 'Longterm Linear Regression Period', minval=4,
group=lrg)
linreg2 = input(true, 'Shorterm Linear Regression On / Off', group=lrg)
periodTrend2 = input.int(25, 'Shorterm Linear Regression Period', minval=4,
group=lrg)
deviationsAmnt = input.float(2, 'Deviation', minval=0.1, step=0.1, group=lrg)
estimatorType = input.string('Unbiased', 'Estimator', options=['Biased',
'Unbiased'], group=lrg)
var extendType = input.string('Right', 'Extend', options=['Right', 'Segment'],
group=lrg) == 'Right' ? extend.right : extend.none
// drawline configuration
drawLine(X1, Y1, X2, Y2, ExtendType, Color, LineStyle) =>
var line Line = na
Line := linreg1 ? line.new(X1, Y1, X2, Y2, xloc.bar_index, ExtendType, Color,
LineStyle, width=2) : na
line.delete(Line[1])
drawLine2(X1, Y1, X2, Y2, ExtendType, Color, LineStyle) =>
var line Line = na
Line := linreg2 ? line.new(X1, Y1, X2, Y2, xloc.bar_index, ExtendType, Color,
LineStyle, width=2) : na
line.delete(Line[1])
periodMinusOne = periodTrend - 1
[linReg, slope, deviation, correlate, r2] = rsdcr2(periodMinusOne, deviationsAmnt,
estimatorType)
endPointBar = bar_index - periodTrend + 1
endPointY = linReg + slope * periodMinusOne
endPointBar2 = bar_index - periodTrend2 + 1
// drawline plot
drawLine(endPointBar, endPointY + deviation, bar_index, linReg + deviation,
extendType, #e91e63, line.style_solid)
drawLine(endPointBar, endPointY, bar_index, linReg, extendType, #e91e63,
line.style_dotted)
drawLine(endPointBar, endPointY - deviation, bar_index, linReg - deviation,
extendType, #e91e63, line.style_solid)
drawLine2(endPointBar2, endPointY + deviation, bar_index, linReg + deviation,
extendType, color.blue, line.style_solid)
drawLine2(endPointBar2, endPointY, bar_index, linReg, extendType, color.blue,
line.style_dotted)
drawLine2(endPointBar2, endPointY - deviation, bar_index, linReg - deviation,
extendType, color.blue, line.style_solid)
// trendline
// input
trlg = 'Trend Lines'
o = rsi[1]
h = rsih
l = rsil
c = rsi
log_chart = input(true, title='Use Log Chart', group=trlg)
a_Color_Type = input.string(defval='Monochrome', title='Use Trendlines Color
Scheme', options=['Colored', 'Monochrome'], group=trlg)
// trendline function
a_f_trendline(a__input_function, a__delay, a__only_up, a__extend) =>
var int a_Ax = 1
var int a_Bx = 1
var float a_By = 0
var float a_slope = 0
a_Ay = fixnan(a__input_function)
if ta.change(a_Ay) != 0
a_Ax := time[a__delay]
a_By := a_Ay[1]
a_Bx := a_Ax[1]
a_slope := log_chart ? (math.log(a_Ay) - math.log(a_By)) / (a_Ax - a_Bx) :
(a_Ay - a_By) / (a_Ax - a_Bx)
a_slope
else
a_Ax := a_Ax[1]
a_Bx := a_Bx[1]
a_By := a_By[1]
a_By
// draw trendline
var line a_trendline = na
var int a_Axbis = 0
var float a_Aybis = 0
var bool a__xtend = true
a_extension_time = a_Extension_Multiplier * a_bar_time * 25
a_Axbis := a_Ax + a_extension_time
a_Aybis := log_chart ? a_Ay * math.exp(a_extension_time * a_slope) : a_Ay +
a_extension_time * a_slope
if a_Extension_Multiplier != 0
a__xtend := false
a__xtend
if ta.change(a_Ay) != 0
if not na(a_line_color)
a_trendline = line.new(a_Bx, a_By, a_Axbis, a_Aybis, xloc.bar_time,
extend=a__xtend ? extend.right : extend.none, color=a_line_color,
style=line.style_solid, width=a_width)
a_trendline
[a_Bx, a_By, a_Axbis, a_Aybis, a_slope]
// secondary trendline
// trendline extension
b_Extension_Multiplier=
b_Extensions==" 25"? 1 :
b_Extensions==" 50"? 2 :
b_Extensions==" 75"? 3 :
b_Extensions==" 100"? 4 :
b_Extensions==" 150"? 6 :
b_Extensions==" 200"? 8 :
b_Extensions==" 300"? 12 :
b_Extensions==" 400"? 16 :
b_Extensions==" 500"? 20 :
b_Extensions==" 750"? 30 :
b_Extensions=="1000"? 40 :
b_Extensions=="Infinate"? 0 : na
// trendline function
b_f_trendline(b__input_function, b__delay, b__only_up, b__extend) =>
var int b_Ax = 1
var int b_Bx = 1
var float b_By = 0
var float b_slope = 0
b_Ay = fixnan(b__input_function)
if ta.change(b_Ay) != 0
b_Ax := time[b__delay]
b_By := b_Ay[1]
b_Bx := b_Ax[1]
b_slope := log_chart ? (math.log(b_Ay) - math.log(b_By)) / (b_Ax - b_Bx) :
(b_Ay - b_By) / (b_Ax - b_Bx)
b_slope
else
b_Ax := b_Ax[1]
b_Bx := b_Bx[1]
b_By := b_By[1]
b_By
// draw trendlines
var line b_trendline = na
var int b_Axbis = 0
var float b_Aybis = 0
var bool b__xtend = true
b_extension_time = b_Extension_Multiplier * b_bar_time * 25
b_Axbis := b_Ax + b_extension_time
b_Aybis := log_chart ? b_Ay * math.exp(b_extension_time * b_slope) : b_Ay +
b_extension_time * b_slope
if b_Extension_Multiplier != 0
b__xtend := false
b__xtend
if ta.change(b_Ay) != 0
if not na(b_line_color)
b_trendline = line.new(b_Bx, b_By, b_Axbis, b_Aybis, xloc.bar_time,
extend=b__xtend ? extend.right : extend.none, color=b_line_color,
style=line.style_dashed, width=b_width)
b_trendline
[b_Bx, b_By, b_Axbis, b_Aybis, b_slope]
// plot
b_color_high = b_slope_high * time < 0 ? color.green : na
b_color_low = b_slope_low * time > 0 ? color.red : na