OPEN-SOURCE SCRIPT

CCI TIME COUNT

104
//version=6
indicator("CCI Multi‑TF", overlay=true)

// === Inputs ===
// CCI Inputs
cciLength = input.int(20, "CCI Length", minval=1)
src = input.source(hlc3, "Source")

// Timeframes
timeframes = array.from("1", "3", "5", "10", "15", "30", "60", "1D", "1W")
labels = array.from("1m", "3m", "5m", "10m", "15m", "30m", "60m", "Daily", "Weekly")

// === Table Settings ===
tblPos = input.string('Top Right', 'Table Position', options = ['Top Left', 'Top Right', 'Bottom Left', 'Bottom Right', 'Middle Left', 'Middle Right'], group = 'Table Settings')
i_textSize = input.string('Small', 'Text Size', options = ['Tiny', 'Small', 'Normal', 'Large'], group = 'Table Settings')
textSize = i_textSize == 'Small' ? size.small : i_textSize == 'Normal' ? size.normal : i_textSize == 'Large' ? size.large : size.tiny
textColor = color.white

// Resolve table position
var pos = switch tblPos
'Top Left' => position.top_left
'Top Right' => position.top_right
'Bottom Left' => position.bottom_left
'Bottom Right' => position.bottom_right
'Middle Left' => position.middle_left
'Middle Right' => position.middle_right
=> position.top_right

// === Custom CCI Function ===
customCCI(source, length) =>
sma = ta.sma(source, length)
dev = ta.dev(source, length)
(source - sma) / (0.015 * dev)

// === CCI Values for All Timeframes ===
var float[] cciVals = array.new_float(array.size(timeframes))
for i = 0 to array.size(timeframes) - 1
tf = array.get(timeframes, i)
cciVal = request.security(syminfo.tickerid, tf, customCCI(src, cciLength))
array.set(cciVals, i, cciVal)

// === Countdown Timers ===
var string[] countdowns = array.new_string(array.size(timeframes))
for i = 0 to array.size(timeframes) - 1
tf = array.get(timeframes, i)
closeTime = request.security(syminfo.tickerid, tf, time_close)
sec_left = barstate.isrealtime and not na(closeTime) ? math.max(0, (closeTime - timenow) / 1000) : na
min_left = sec_left >= 0 ? math.floor(sec_left / 60) : na
sec_mod = sec_left >= 0 ? math.floor(sec_left % 60) : na
timer_text = barstate.isrealtime and not na(sec_left) ? str.format("{0,number,00}:{1,number,00}", min_left, sec_mod) : "–"
array.set(countdowns, i, timer_text)

// === Build Table ===
if barstate.islast
rows = array.size(timeframes) + 1
var table t = table.new(pos, 3, rows, frame_color=color.rgb(252, 250, 250), border_color=color.rgb(243, 243, 243))

// Headers
table.cell(t, 0, 0, "Timeframe", text_color=textColor, bgcolor=color.rgb(238, 240, 242), text_size=textSize)
table.cell(t, 1, 0, "CCI (" + str.tostring(cciLength) + ")", text_color=textColor, bgcolor=color.rgb(239, 243, 246), text_size=textSize)
table.cell(t, 2, 0, "Time to Close", text_color=textColor, bgcolor=color.rgb(239, 244, 248), text_size=textSize)

// Data Rows
for i = 0 to array.size(timeframes) - 1
row = i + 1
label = array.get(labels, i)
cciVal = array.get(cciVals, i)
countdown = array.get(countdowns, i)

// Color CCI: Green if < -100, Red if > 100
cciColor = cciVal < -100 ? color.green : cciVal > 100 ? color.red : color.rgb(236, 237, 240)

// Background warning if <60 seconds to close
tf = array.get(timeframes, i)
closeTime = request.security(syminfo.tickerid, tf, time_close)
sec_left = barstate.isrealtime and not na(closeTime) ? math.max(0, (closeTime - timenow) / 1000) : na
countdownBg = sec_left < 60 ? color.rgb(255, 220, 220, 90) : na

// Table cells
table.cell(t, 0, row, label, text_color=color.rgb(239, 240, 244), text_size=textSize)
table.cell(t, 1, row, str.tostring(cciVal, "#.##"), text_color=cciColor, text_size=textSize)
table.cell(t, 2, row, countdown, text_color=color.rgb(232, 235, 243), bgcolor=countdownBg, text_size=textSize)

Отказ от ответственности

Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.