Untitled

 avatar
unknown
plain_text
a month ago
2.8 kB
1
Indexable
//@version=5
indicator("Special Candle Marker", overlay=true)

// Special numbers
var int[] special_numbers = array.from(3, 11, 17, 29, 41, 47, 53, 59)
var int[] special_numbers2 = array.from(2, 4, 10, 12, 16, 18, 28, 30, 42, 46, 48, 52, 54, 58)

// Function to check if a number is in the special numbers array
is_special_number(n) =>
    array.includes(special_numbers, n)

is_special_number2(n) =>
    array.includes(special_numbers2, n)

isLowerLow = low[1] > low and low[2] > low
isHigherHigh = high[1] < high and high[2] < high

isLowerLow2(n) =>
    if is_special_number2(n)
        if is_special_number(n+1)
            if low[1] > low and low[2] > low and low[3] > low
                true

isHigherHigh2(n) =>
    if is_special_number2(n)
        if is_special_number(n+1)
            if high[1] > high and high[2] > high and high[3] > high
                true
            


// Function to get the current quarter
get_quarter() =>
    current_month = month(time)
    if current_month <= 3
        1
    else if current_month <= 6
        2
    else if current_month <= 9
        3
    else
        4

// Function to count candles within the quarter (for daily timeframe)
get_candle_count_in_quarter() =>
    var count = 0
    var last_quarter = 0
    current_quarter = get_quarter()
    
    if current_quarter != last_quarter
        count := 1
        last_quarter := current_quarter
    
    count := count + 1

// Function to count 4-hour candles within two weeks
get_4h_count_in_two_weeks() =>
    var count = 0
    var last_two_week_period = 0
    current_two_week_period = math.floor((weekofyear - 1) / 2) + 1
    
    if current_two_week_period != last_two_week_period
        count := 2
        last_two_week_period := current_two_week_period
    
    count := count + 1
    count

// Determine if it's a daily or 4-hour timeframe
is_daily = timeframe.isdaily
is_4h = timeframe.isintraday and timeframe.multiplier == 240

// Calculate the count based on the timeframe
count = if is_daily
    get_candle_count_in_quarter()
else if is_4h
    get_4h_count_in_two_weeks()
else
    0

// Plot the green dot if the count matches a special number
plotshape(is_special_number(count) and isLowerLow, title="Low", style=shape.circle, location=location.belowbar, color=color.red, size=size.small)
plotshape(is_special_number(count) and isHigherHigh, title="High", style=shape.circle, location=location.abovebar, color=color.green, size=size.small)

// Plot the number on the candle if it's a special number
if (is_special_number(count))
    label.new(bar_index, high, text=str.tostring(count), color=color.white, style=label.style_none, textcolor=color.blue)
Editor is loading...
Leave a Comment