Untitled

 avatar
unknown
plain_text
2 months ago
3.7 kB
31
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