Untitled
unknown
plain_text
8 months ago
3.7 kB
39
Indexable
//@version=5
indicator("RSI box", overlay = true)
// --------------------------------------------------------------------------------------------------------------------}
// ππππ ππππππ
// --------------------------------------------------------------------------------------------------------------------{
int length = input.int(14, title="Length")
bool show_levl = input.bool(true, "Trend Levels")
// Colors for the trend levels
color up = input.color(color.rgb(85, 232, 80), "+", group = "Colors", inline = "i")
color dn = input.color(color.rgb(220, 69, 69), "-", group = "Colors", inline = "i")
var box1 = box(na)
series float atr = ta.atr(200)
// --------------------------------------------------------------------------------------------------------------------}
// πππΏππΎπΌπππ πΎπΌππΎπππΌπππππ
// --------------------------------------------------------------------------------------------------------------------{
series float rsiValue = ta.rsi(close, length)
series float correction = close + (close - rsiValue)
series float rsima = ta.sma(rsiValue, length)
bool signalUp = ta.crossover(rsiValue, 30)
bool signalDn = ta.crossunder(rsiValue, 70)
color zlma_color = rsima > rsima[3] ? up : rsima < rsima[3] ? dn : na
color ema_col = rsiValue < rsima ? up : dn // Determine the EMA color
// --------------------------------------------------------------------------------------------------------------------}
// πππππΌππππΌππππ
// --------------------------------------------------------------------------------------------------------------------{
method draw_box(color col, top, bot, price)=>
box.new(
bar_index, top, bar_index, bot, col, 1,
bgcolor = color.new(col, 90),
text = str.tostring(math.round(price, 2)),
text_size = size.tiny,
text_color = chart.fg_color,
text_halign = text.align_right
)
if show_levl
bool check_signals = signalUp or signalDn
switch
// Draw a box when a bullish signal is detected
signalUp => box1 := up.draw_box(close, close - atr, close)
// Draw a box when a bearish signal is detected
signalDn => box1 := dn.draw_box(close + atr, close, close)
switch
// Extend the right side of the box if no new signal is detected
not signalUp or not signalDn => box1.set_right(bar_index + 4)
=> box1 := box(na) // Otherwise, reset the box
switch
// Add a downward label when price crosses below the bottom of the box
ta.crossunder(high, box1.get_bottom()) and not check_signals[1] and not check_signals and rsiValue > rsima=>
label.new(bar_index - 1, high[1], "βΌ", color = color(na), textcolor = dn, style = label.style_label_down)
// Add an upward label when price crosses above the top of the box
ta.crossover(low, box1.get_top()) and not check_signals and not check_signals[1] and rsiValue < rsima=>
label.new(bar_index - 1, low[1], "β²", color = color(na), textcolor = up, style = label.style_label_up)
plotshape(signalUp ? low : na, "", shape.square, location.absolute, color = up, size = size.tiny)
plotshape(signalDn ? high : na, "", shape.square, location.absolute, color = dn, size = size.tiny)
// --------------------------------------------------------------------------------------------------------------------}
Editor is loading...
Leave a Comment