Untitled

 avatar
unknown
plain_text
5 months ago
3.9 kB
119
Indexable
//@version=5
indicator(title="DCA- RSI", shorttitle="UH",overlay = true, format=format.price, precision=2)

// Input for timeframe selection
tf = input.timeframe("D", "Timeframe")  // Günlük zaman dilimi varsayılan olarak kullanılır

// RSI Calculation on selected timeframe
len = input.int(14, minval=1, title="Length")
src = input(close, "Source")

// Fetch RSI moving average on the selected timeframe
rsi_ma_tf = request.security(syminfo.tickerid, tf, ta.rma(ta.rsi(src, len), len))

// Colors for histogram
bullcolor = input.color(#00ff00, 'Bull color') 
bearcolor = input.color(#ff0000, 'Bear color')

// Determine color based on RSI MA value
rsi_color = rsi_ma_tf >= 50 ? bullcolor : bearcolor

// Calculate histogram values relative to 50
histogram_value = rsi_ma_tf - 50

// Add histogram bars
histogram_color = rsi_color
plot(histogram_value, style=plot.style_histogram, color=histogram_color, linewidth=1)

// Variables for counting
var int count_green = 0
var int count_red = 0
var float prev_high = na
var float prev_low = na

// Gizleme seçenekleri
show_1 = input.bool(true, title="Show 1")
show_2 = input.bool(true, title="Show 2")
show_3 = input.bool(true, title="Show 3")
show_4 = input.bool(true, title="Show 4")
show_5 = input.bool(true, title="Show 5")
show_6 = input.bool(true, title="Show 6")
show_7 = input.bool(true, title="Show 7")
show_8 = input.bool(true, title="Show 8")
show_9 = input.bool(true, title="Show 9")

// Track previous RSI MA to detect color changes
var float prev_rsi_ma = na  // Ensure prev_rsi_ma is initialized as a float

// Function to check if the label should be shown
f_show_label(count) =>
    (count == 1 and show_1) or(count == 2 and show_2) or(count == 3 and show_3) or(count == 4 and show_4) or(count == 5 and show_5) or(count == 6 and show_6) or(count == 7 and show_7) or(count == 8 and show_8) or(count == 9 and show_9)

// For green (RSI >= 50), track high levels
if (rsi_ma_tf >= 50)  // Indicator is green
    if (na(prev_rsi_ma) or prev_rsi_ma < 50)
        // First green candle, reset count and mark the candle with '1'
        count_green := 1
        if f_show_label(count_green)
            label.new(bar_index, high, text=str.tostring(count_green), style=label.style_label_down, color=color.green, textcolor=color.white, size=size.small)
        prev_high := high
    else
        // Continue counting if current high exceeds the previous high
        if (high > prev_high)
            count_green := count_green + 1
            if (count_green > 9)
                count_green := 1  // Reset to 1 if count exceeds 9
            if f_show_label(count_green)
                label.new(bar_index, high, text=str.tostring(count_green), style=label.style_label_down, color=color.green, textcolor=color.white, size=size.small)
            prev_high := high

// For red (RSI < 50), track low levels
if (rsi_ma_tf < 50)  // Indicator is red
    if (na(prev_rsi_ma) or prev_rsi_ma >= 50)
        // First red candle, reset count and mark the candle with '1'
        count_red := 1
        if f_show_label(count_red)
            label.new(bar_index, low, text=str.tostring(count_red), style=label.style_label_up, color=color.red, textcolor=color.white, size=size.small)
        prev_low := low
    else
        // Continue counting if current low breaks the previous low
        if (low < prev_low)
            count_red := count_red + 1
            if (count_red > 9)
                count_red := 1  // Reset to 1 if count exceeds 9
            if f_show_label(count_red)
                label.new(bar_index, low, text=str.tostring(count_red), style=label.style_label_up, color=color.red, textcolor=color.white, size=size.small)
            prev_low := low

// Update the previous RSI MA value for the next bar
prev_rsi_ma := rsi_ma_tf
Editor is loading...
Leave a Comment