Reputation: 11
Hi i want my script to look back 1 bar or 2 bars and if RSI was OS or OB to continue with script but i can't find anything to work like that
if (RSIOverBought = close[2])
...
(i know this can't work is just for easier understanding)
Upvotes: 0
Views: 2076
Reputation: 174
The following code shows an example on how to reference a previous rsi value.
//@version=4
study("RSI Barcolor",overlay=false)
length = input(15, "Length")
lookback = input(2, "Lookback")
ob = input(70, "Overbought")
os = input(30, "Oversold")
rsi = rsi(close, length)
var color col = na
if crossover(rsi[lookback], ob)
// do something here...
col := color.aqua
if crossunder(rsi[lookback], os)
// do something here...
col := color.yellow
if crossover(rsi[lookback], os) or crossunder(rsi[lookback], ob)
col := na
barcolor(col,offset=-lookback)
plot(rsi)
hline(ob)
hline(os)
Upvotes: 3