TradingView
Quuh
Mar 11, 2022 12:39 PM

Volatility Adapted Relative Strength 

Alcoa CorporationNYSE

描述

VARS uses a stock's ALPHA in comparison to the SPX to determine whether there is RS on an volatility adjusted basis.

版本注释

Changes:
(1) Length of the α-timeframe.
(2) Additional coloring for higher α-values.

版本注释

Each variable of the indicator is now fully editable.

版本注释

The script now works with two different beta and alpha reference points to map VARS to longer and shorter running time frames. Each value is customizable.
Nota bene: The default values are still work in progress.
评论
icedig201
Hi, this indicator is similar to Matt Caruso CARS (Caruso Adaptive Relative Strength)?
Quuh
@icedig201,
I think you could say so. Although I have worked on such an indicator long before, this version is certainly influenced by Matt's indicator in some details.
icedig201
@Quuh, You did amazing job. I made RS indicator similar to CARS but I need your help for background coloring
icedig201
@icedig201, Please help me if possible
Quuh
@icedig201,
My coding skills are also only subpar. But the bgcolor function is actually not very difficult to use, the beta calculations etc. were much more difficult. But where exactly is your problem?
icedig201
@Quuh, Actually I have zero knowledge about coding. One of my online trading friend gave me RS script which is 90% similar without background coloring to Matt Caruso. That is why I want your help.
icedig201
@icedig201, study("Relative Strength", shorttitle="Relative Strength")

//Input
source = input(title="Source", type=input.source, defval=close)
comparativeTickerId = input("NSE:NIFTY", type=input.symbol, title="Comparative Symbol")
length = input(123, type=input.integer, minval=1, title="Period")
showZeroLine = input(defval=true, type=input.bool, title="Show Zero Line")
showRefDateLbl = input(defval=true, type=input.bool, title="Show Reference Label")
toggleRSColor = input(defval=true, type=input.bool, title="Toggle RS color on crossovers")
showRSTrend = input(defval=false, type=input.bool, title="RS Trend,", group="RS Trend", inline="RS Trend")
base = input(title="Range", minval=1, defval=5, group="RS Trend", inline="RS Trend")
showMA = input(defval=false, type=input.bool, title="Show Moving Average,", group="RS Mean", inline="RS Mean")
lengthMA = input(61, type=input.integer, minval=1, title="Period", group="RS Mean", inline="RS Mean")

//Set up
baseSymbol = security(syminfo.tickerid, timeframe.period, source)
comparativeSymbol = security(comparativeTickerId, timeframe.period, source)

//Calculations
res = ((baseSymbol/baseSymbol[length])/(comparativeSymbol/comparativeSymbol[length]) - 1)
resColor = toggleRSColor ? res > 0 ? color.green : color.red : color.blue
refDay = showRefDateLbl and barstate.islast ? dayofmonth(time[length]) : na
refMonth = showRefDateLbl and barstate.islast ? month(time[length]) : na
refYear = showRefDateLbl and barstate.islast ? year(time[length]) : na
refLabelStyle = res[length] > 0 ? label.style_label_up : label.style_label_down
refDateLabel = showRefDateLbl and barstate.islast ? label.new(bar_index - length, 0, text="RS-" + tostring(length) + " reference, " + tostring(refDay) + "-" + tostring(refMonth) + "-" + tostring(refYear), color=color.blue, style=refLabelStyle, yloc=yloc.price) : na
y0 = res - res[base]
angle0 = atan(y0/base) // radians
zeroLineColor = iff(showRSTrend, angle0 > 0.0 ? color.green : color.maroon, color.maroon)

//Plot
plot(showZeroLine ? 0 : na, linewidth=2, color=zeroLineColor, title="Zero Line / RS Trend")
plot(res, title="RS", linewidth=2, color= resColor)
plot(showMA ? sma(res, lengthMA) : na, color=color.gray, title="MA")
更多