100% found this document useful (1 vote)
83 views2 pages

RSI Multitimefram

This document contains the source code for a study that plots the RSI indicator on multiple time frames. It calculates RSI on the current timeframe and a higher timeframe, displaying both on the chart. It also includes bands and fill color for the RSI values.

Uploaded by

nikunj olpadwala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
83 views2 pages

RSI Multitimefram

This document contains the source code for a study that plots the RSI indicator on multiple time frames. It calculates RSI on the current timeframe and a higher timeframe, displaying both on the chart. It also includes bands and fill color for the RSI values.

Uploaded by

nikunj olpadwala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// � LonesomeTheBlue

//@version=4
study(title="RSI Multi Time Frame", shorttitle="RSI", max_lines_count = 500,
format=format.price, precision=2)
TimeframeU = input(defval = 'Auto', title ="Higher Time Frame", options = ['Auto',
'1', '3', '5', '10', '15', '30', '60', '120', '180', '240', '360', '480', '720',
'D', 'W', '2W', 'M', '3M', '6M', '12M'])
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)
rsi_col = input(color.blue, title = "Indicator Color", type = input.color)
rsi_width = input(defval = 2, title = "Indicator Line Width", minval = 1, maxval =
4)
rsi_h_col = input(color.green, title = "Indicator HTF Color", type = input.color)
rsi_h_width = input(defval = 2, title = "Indicator HTF Line Width", minval = 1,
maxval = 4)
num_bars = input(defval = 294, title = "Number of Bars for RSI HTF", minval = 10,
maxval = 495)

htf = TimeframeU == 'Auto' ?


timeframe.period == '1' ? '60' :
timeframe.period == '2' ? '60' :
timeframe.period == '3' ? '60' :
timeframe.period == '5' ? '60' :
timeframe.period == '10' ? '120' :
timeframe.period == '15' ? '120' :
timeframe.period == '30' ? 'D' :
timeframe.period == '45' ? 'D' :
timeframe.period == '60' ? 'D' :
timeframe.period == '120' ? 'D' :
timeframe.period == '180' ? 'D' :
timeframe.period == '240' ? 'D' :
timeframe.period == 'D' ? 'W' :
timeframe.period == 'W' ? 'M' : timeframe.period : TimeframeU

rsi = rsi(src, len)


band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")
plot(rsi, color = rsi_col, linewidth = rsi_width)

// RSI HTF
var rsi_htf_lines = array.new_line(0)
var float last_rsi = na
new_htf_bar = change(time(htf)) != 0
rsi_htf = security(syminfo.tickerid, htf, rsi(src, len), lookahead = false)

var line rsi_line = na


if new_htf_bar
last_rsi := rsi_htf[1]
line.delete(rsi_line)
rsi_line := line.new(x1 = bar_index , y1 = rsi_htf, x2 = bar_index - 1, y2 =
last_rsi, color = rsi_h_col, width = rsi_h_width)
else
line.set_x1(rsi_line, bar_index)
line.set_x2(rsi_line, bar_index - 1)
line.set_y1(rsi_line, rsi_htf)
rsi_line

if new_htf_bar
if array.size(rsi_htf_lines) >= num_bars
line.delete(array.get(rsi_htf_lines, array.size(rsi_htf_lines) - 1))
array.pop(rsi_htf_lines)
array.unshift(rsi_htf_lines, line.new(x1 = bar_index - 1 , y1 = last_rsi, x2
=bar_index - 2, y2 = last_rsi[1], color = rsi_h_col, width = rsi_h_width))
else
if array.size(rsi_htf_lines) > 0
for x = 0 to array.size(rsi_htf_lines) - 1
line.set_x1(array.get(rsi_htf_lines, x),
line.get_x1(array.get(rsi_htf_lines, x)) + 1)
line.set_x2(array.get(rsi_htf_lines, x),
line.get_x2(array.get(rsi_htf_lines, x)) + 1)

// show value as indicator values


plot(rsi_htf, color = rsi_h_col, show_last = 1)

You might also like