Professional Documents
Culture Documents
// The general form of the weights of the (2m + 1)-term Henderson Weighted Moving
Average
getWeight(m, j) =>
numerator = 315 * (math.pow(m + 1, 2) - math.pow(j, 2)) * (math.pow(m + 2, 2) -
math.pow(j, 2)) * (math.pow(m + 3, 2) - math.pow(j, 2)) * (3 * math.pow(m + 2, 2) -
11 * math.pow(j, 2) - 16)
denominator = 8 * (m + 2) * (math.pow(m + 2, 2) - 1) * (4 * math.pow(m + 2, 2)
- 1) * (4 * math.pow(m + 2, 2) - 9) * (4 * math.pow(m + 2, 2) - 25)
termMult = (termsNumber - 1) / 2
for i = 0 to termsNumber - 1 by 1
weight = getWeight(termMult, i - termMult)
sum += nz(src[i]) * weight
weightSum += weight
weightSum
sum / weightSum
// ----- BB Calculation
bb_basis = variant(bb_type, rsi, bb_length, lsmaOffset, almaOffset, almaSigma)
bb_dev = bb_std * ta.stdev(rsi, bb_length)
bb_const = rsi * bb_plus / 100
bb_upper = bb_basis + bb_dev + bb_const
bb_lower = bb_basis - bb_dev - bb_const
plotshape(shark ? bb_lower > rsi and rsiOversold > rsi ? rsiDown : na : na,
title='SharkFin/Hook Long+', color=color.new(color.lime, 15),
style=shape.triangleup, location=location.bottom, size=size.tiny,editable = false)
plotshape(shark ? bb_lower > rsi and rsiOversold < rsi ? rsiDown : na : na,
title='SharkFin/Hook Long+', color=color.new(color.orange, 15),
style=shape.triangleup, location=location.bottom, size=size.tiny,editable = false)
//MA Cross
maCross = input(true, 'Show RSI / MA Cross?')
crossunder_3 = ta.crossunder(rsi, ema_base)
plotshape(maCross ? crossunder_3 and rsi < rsiOversold1 ? rsi : na : na,
title='Signal MA Cross Long+', color=color.new(color.lime, 15), style=shape.circle,
location=location.absolute, size=size.tiny,editable = false)
crossunder_4 = ta.crossunder(rsi, ema_base)
plotshape(maCross ? crossunder_4 and rsi > rsiOverbought1 ? rsi : na : na,
title='Signal MA Cross Short+', color=color.new(color.red, 15), style=shape.circle,
location=location.absolute, size=size.tiny,editable = false)
//Mid Cross
senCross = input(true, 'Show MA / Sentiment Cross?')
crossover_3 = ta.crossover(ema_base, bb_basis)
plotshape(senCross ? crossover_3 ? bb_basis : na : na, title='Sentiment Cross
Long+', color=color.new(color.lime, 15), style=shape.circle,
location=location.absolute, size=size.small,editable = false)
crossunder_5 = ta.crossunder(ema_base, bb_basis)
plotshape(senCross ? crossunder_5 ? bb_basis : na : na, title='Sentiment Cross
Short+', color=color.new(color.red, 15), style=shape.circle,
location=location.absolute, size=size.small,editable = false)
//RSI PLOT
rsiColor = rsi > rsiOverbought ? color.lime : rsi < rsiOversold ? color.red :
color.black
rsiPlot = plot(rsi, color=rsiColor, linewidth=3, title='RSI', transp=0)
plot(ta.ema(rsi, 2), color=rsiColor, linewidth=1, title='RSI Shadow 2',
transp=35,editable = false)
plot(ta.ema(rsi, 3), color=rsiColor, linewidth=1, title='RSI Shadow 3',
transp=55,editable = false)
/////////////////////////////////////////////////////////////
// Input parameters
relativeStrengthIndexLength = input.int(14, title="RSI Length", group="RSI
Settings")
smoothingLength = input.int(21, title="RSI Smoothing Length", group="RSI Settings")
rsiInputSource = input.source(close, title="RSI Source", group="RSI Settings")
isSmoothed = input.bool(false, "Smooth RSI?", group="RSI Settings")
// MA Selection
calculateMA(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"HMA" => ta.hma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Calculating RSI
rsiValue = isSmoothed ? ta.hma(ta.rsi(rsiInputSource, relativeStrengthIndexLength),
smoothingLength) : ta.rsi(rsiInputSource, relativeStrengthIndexLength)
rsiMovingAverage = calculateMA(rsiValue, movingAverageLength, movingAverageType)
// Plotting
supertrendPlot = plot(rsiSupertrend, color = trendDirection == -1 ? colorUp :
colorDown, title="Supertrend",display = display.none,editable = false)
rsiPlota = plot(rsiValue, color = color.new(color.gray, 100), title="RSI",display =
display.none,editable = false)
overboughtLine = plot(70, color = color.from_gradient(rsiValue, 50, 70,
color.new(color.gray, 70), color.new(colorDown, 0)), title="Overbought Line",
linewidth = 3,display = display.none,editable = false)
oversoldLine = plot(30, color = color.from_gradient(rsiValue, 30, 50,
color.new(colorUp, 0), color.new(color.gray, 70)), title="Oversold Line", linewidth
= 3,display = display.none,editable = false)
plot(rsiMovingAverage, color = color.gray, title = "RSI MA", display =
showMovingAverage ? display.all : display.none, linewidth = 1,display =
display.none,editable = false)
plot(50, color = color.gray, title="Mid Line",display = display.none,editable =
false)
// Filling
fill(overboughtLine, oversoldLine, color = color.new(color.gray, 90),
title="Overbought/Oversold Fill",display = display.none,editable = false)
fill(supertrendPlot, rsiPlota, color = trendDirection == 1 ? color.new(colorDown,
90) : color.new(colorUp, 90), title="Trend Fill",display = display.none,editable =
false)
fill(supertrendPlot, rsiPlota, rsiValue, rsiSupertrend, color.new(chart.bg_color,
1000), trendDirection == 1 ? colorDown : colorUp,display = display.none,editable =
false)