Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Real Relative Strength + Volume", shorttitle = "Relative Strength", overlay = false)
- // Get User's inputs -----------------------------------------------------------
- // Index selection
- index = input.symbol(defval = "SPY", title = "Reference for comparison", group = "Reference selection")
- symbol = syminfo.tickerid
- // Period's parameters
- period_5M = input.int (defval = 12, title = "Intraday RS period", group = "Period's parameters")
- period_1D = input.int (defval = 5, title = "Daily RS period", group = "Period's parameters")
- length_5M = input.int (defval = 390, title = "Intraday RV period", group = "Period's parameters")
- length_1D = input.int (defval = 50, title = "Daily RV period", group = "Period's parameters")
- period = timeframe.isminutes ? period_5M : period_1D
- length = timeframe.isminutes ? length_5M : length_1D
- // Smoothing's parameters
- pre_smoothing_switch = input.bool (false, "", inline = "pre_smoothing_switch", group = "Smoothing's parameters")
- post_smoothing_switch = input.bool (false, "", inline = "post_smoothing_switch", group = "Smoothing's parameters")
- pre_smoothing_value = input.int (defval = 2, minval = 2, title = "Pre-calculating smoothing", inline = "pre_smoothing_switch", group = "Smoothing's parameters")
- post_smoothing_value = input.int (defval = 2, minval = 2, title = "Post-calculating smoothing", inline = "post_smoothing_switch", group = "Smoothing's parameters")
- pre_smoothing = pre_smoothing_switch ? pre_smoothing_value : 1
- post_smoothing = post_smoothing_switch ? post_smoothing_value : 1
- // Graphical's parameters
- sensitivity_switch = input.bool (true, "", inline = "sensitivity_value", group = "Graphical's parameters")
- correlation_switch = input.bool (true, "", inline = "correlation_size", group = "Graphical's parameters")
- level_1_switch = input.bool (true, "", inline = "level_1_value", group = "Graphical's parameters")
- level_2_switch = input.bool (true, "", inline = "level_2_value", group = "Graphical's parameters")
- sensitivity_value = input.int (defval = 2, minval = 1, title = "Chart Sensitivity", inline = "sensitivity_value", group = "Graphical's parameters")
- correlation_size = input.int (defval = 3, minval = 1, title = "Correlation dots", inline = "correlation_size", group = "Graphical's parameters")
- level_1_value = input.float (defval = 1, minval = 0, title = "Horizontal line 1", inline = "level_1_value", group = "Graphical's parameters")
- level_2_value = input.float (defval = 3, minval = 0, title = "Horizontal line 2", inline = "level_2_value", group = "Graphical's parameters")
- level_1 = level_1_switch and sensitivity_switch ? math.atan(level_1_value / sensitivity_value) : level_1_switch ? level_1_value : na
- level_2 = level_2_switch and sensitivity_switch ? math.atan(level_2_value / sensitivity_value) : level_2_switch ? level_2_value : na
- // Calculations ----------------------------------------------------------------
- // Requesting values
- request () =>
- source = close
- change = ta.ema(ta.change(close, period), pre_smoothing)
- atr = ta.atr(period) [1]
- [source, change, atr]
- [index_source, index_change, index_atr] = request.security(index , timeframe.period, request())
- [symbol_source, symbol_change, symbol_atr] = request.security(symbol, timeframe.period, request())
- // Calculating RS
- power_index = index_change / index_atr
- expected_change = power_index * symbol_atr
- relative_strength = (symbol_change - expected_change) / symbol_atr * (volume / ta.sma(volume, length) [1])
- // Calculating correlation
- correlation_value = ta.correlation(symbol_source, index_source, period)
- // Creating an awesome chart ---------------------------------------------------
- // Relative strength
- graphical_strength = ta.ema(sensitivity_switch ? math.atan(relative_strength / sensitivity_value) : relative_strength, post_smoothing)
- plot (graphical_strength, style = plot.style_columns, color = graphical_strength > 0 ? color.rgb(13,183,135,50) : color.rgb(239,83,80,50))
- // Horizontal levels
- plot ( level_1, color = color.new(color.yellow, 60))
- plot (-level_1, color = color.new(color.yellow, 60))
- plot ( level_2, color = color.new(color.yellow, 60))
- plot (-level_2, color = color.new(color.yellow, 60))
- // Correlation
- correlation_color = color.rgb(239 - 113 * (correlation_value + 1), 83 + 50 * (correlation_value + 1), 80 + 27.5 * (correlation_value + 1))
- plot(correlation_switch ? 0 : na, color = color.rgb(0,0,0), style=plot.style_circles, linewidth = correlation_size + 2)
- plot(correlation_switch ? 0 : na, color = correlation_color, style=plot.style_circles, linewidth = correlation_size)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement