Renko RSI (ticker.renko)

readCrypto · study · 57 行 · 点赞 49 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// Renko RSI (ticker.renko)
//
// The Renko series comes from TradingView's own Renko ticker, requested with request.security
// (same formula as the Donchian Channel strategy):
//   renko_ticker = ticker.renko(syminfo.tickerid, renko_style, renko_val)
//   request.security(renko_ticker, timeframe.period, ..., barmerge.gaps_off, barmerge.lookahead_off)
// The RSI and its Signal (EMA) are calculated INSIDE the Renko context, so every brick counts as one bar
// (brick-by-brick RSI). The result is a normal series: one value for each chart bar, equal to the value of
// the latest brick at that time.
indicator('Renko RSI (ticker.renko)', shorttitle = 'Renko RSI', overlay = false, precision = 0)
 
//==========================================================
// Inputs
//==========================================================
renko_style = input.string('ATR', title = 'Renko Style', options = ['ATR', 'Traditional'], group = 'Renko Settings')
renko_val   = input.int(14, title = 'Renko Box Size / ATR Length', group = 'Renko Settings')
rsiLength   = input.int(14, 'RSI length (bricks)', minval = 1, group = 'Renko RSI')
sigLength   = input.int(7, 'Signal length (EMA, bricks)', minval = 1, group = 'Renko RSI')
overbought  = input.int(70, 'Overbought level', minval = 50, maxval = 100, group = 'Renko RSI')
oversold    = input.int(30, 'Oversold level', minval = 0, maxval = 50, group = 'Renko RSI')
 
//==========================================================
// Renko data (TradingView Renko ticker)
//==========================================================
renko_ticker = ticker.renko(syminfo.tickerid, renko_style, renko_val)
 
// Calculated on the Renko bars: close, RSI of the brick closes, and the EMA of that RSI.
f_renkoRsi(int _len, int _sig) =>
    float _rsi = ta.rsi(close, _len)
    float _signal = ta.ema(_rsi, _sig)
    [close, _rsi, _signal]
 
[renko_close, renkoRSI, renkoRSISignal] = request.security(renko_ticker, timeframe.period, f_renkoRsi(rsiLength, sigLength), barmerge.gaps_off, barmerge.lookahead_off)
 
//==========================================================
// Plot
//==========================================================
// Red when rising, blue when falling, the previous color while unchanged (same bricks -> same value)
color renkoRSIColor = color.black
renkoRSIColor := renkoRSI > renkoRSI[1] ? color.new(color.red, 10) : renkoRSI < renkoRSI[1] ? color.new(color.blue, 10) : nz(renkoRSIColor[1], color.black)
 
p1 = plot(renkoRSI, 'Renko RSI Line', color = renkoRSIColor, linewidth = 2)
p2 = plot(renkoRSISignal, 'Renko RSI Signal', color = color.new(color.black, 90), linewidth = 1, display = display.none)
fill(p1, p2, color = renkoRSI > renkoRSISignal ? color.new(color.red, 75) : renkoRSI < renkoRSISignal ? color.new(color.blue, 75) : color.new(color.black, 100), title = 'Fill RSI')
 
// Renko close for checking in the Data Window
plot(renko_close, 'Renko close', display = display.data_window)
 
// Guide lines
hOB = hline(overbought, 'Overbought', color = color.red, linestyle = hline.style_dashed)
hMid = hline(50, 'Middle Line', color = color.gray, linestyle = hline.style_dotted)
hOS = hline(oversold, 'Oversold', color = color.green, linestyle = hline.style_dashed)
hTop = hline(100, 'Top', color = color.new(color.gray, 100))
hBot = hline(0, 'Bottom', color = color.new(color.gray, 100))
fill(hOB, hTop, color = color.new(color.red, 90), title = 'Overbought zone')
fill(hBot, hOS, color = color.new(color.green, 90), title = 'Oversold zone')

← 返回列表