本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=3
study("Candle Based RSI w/ EMA 9 Crossover")
// inputs, rsi length, option to turn heikin ashi candles on
rsi_length = input(14)
HA = input(false)
// rsi of each input
rsi_close = rsi(close,rsi_length)
rsi_open = rsi(open,rsi_length)
rsi_high = rsi(high,rsi_length)
rsi_low = rsi(low,rsi_length)
// heikin ashi inputs of rsi
ash_rsi_o = (rsi_open[1]+rsi_close[1])/2
ash_rsi_c = (rsi_close +rsi_high +rsi_low +rsi_open)/4
ash_rsi_h = ((rsi_high >= ash_rsi_c) and (rsi_high >= ash_rsi_o )) ? rsi_high : (ash_rsi_o >= ash_rsi_c) ? ash_rsi_o : ash_rsi_c
ash_rsi_l = ((rsi_low <= ash_rsi_c) and (rsi_low <= ash_rsi_o )) ? rsi_low : (ash_rsi_o <= ash_rsi_c) ? ash_rsi_o : ash_rsi_c
// type of input to plot & color
open_in = HA ? ash_rsi_o : rsi_open
high_in = HA ? ash_rsi_h : rsi_high
low_in = HA ? ash_rsi_l : rsi_low
close_in = HA ? ash_rsi_c : rsi_close
RSIcolor = HA ? (ash_rsi_o<ash_rsi_c ? lime:red) : (rsi_open<rsi_close ? lime : red)
// plotting candles, their hlc3, and a 30-70 marking
plotcandle(open_in, high_in ,low_in ,close_in, color = RSIcolor)
plot(close_in)
fill(plot(30),plot(70),color=black)
//rsiema
//RSIEMA
lenema = input(9, minval=1, title="RSI EMA Length")
out = ema(rsi_close, lenema)
col=out >= out[1] ? lime : red
plot(out, title="RSI EMA", color=col, linewidth=2)
//bgcolour
b_color = (out < out[1]) ? color(red,70) : (out >= out[1]) ? color(green,60) : na
bgcolor(title="Highlight background", color=b_color)