OPEN-SOURCE SCRIPT
업데이트됨

HTF Candle Countdown Timer

273
//version=5
indicator("HTF Candle Countdown Timer", overlay=true)

// ============================================================================
// INPUTS - SETTINGS MENU
// ============================================================================

// --- Mode Selection ---
mode = input.string(title="Mode", defval="Auto", options=["Auto", "Custom"],
tooltip="Auto: Αυτόματη αντιστοίχιση timeframes\nCustom: Επιλέξτε το δικό σας timeframe")

// --- Custom Timeframe Selection ---
customTF = input.timeframe(title="Custom Timeframe", defval="15",
tooltip="Ενεργό μόνο σε Custom Mode")

// --- Table Position ---
tablePos = input.string(title="Table Position", defval="Bottom Right",
options=["Top Left", "Top Right", "Bottom Left", "Bottom Right"])

// --- Colors ---
textColor = input.color(title="Text Color", defval=color.white)
bgColor = input.color(title="Background Color", defval=color.black)
transparentBg = input.bool(title="Transparent Background", defval=false,
tooltip="Ενεργοποίηση διάφανου φόντου")

// --- Text Size ---
textSize = input.string(title="Text Size", defval="Normal",
options=["Auto", "Tiny", "Small", "Normal", "Large", "Huge"])

// ============================================================================
// FUNCTIONS
// ============================================================================

// Μετατροπή string position σε table position constant
getTablePosition(pos) =>
switch pos
"Top Left" => position.top_left
"Top Right" => position.top_right
"Bottom Left" => position.bottom_left
"Bottom Right" => position.bottom_right
=> position.bottom_right

// Μετατροπή string size σε size constant
getTextSize(size) =>
switch size
"Auto" => size.auto
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
=> size.normal

// Αυτόματη αντιστοίχιση timeframes
getAutoTimeframe() =>
currentTF = timeframe.period
string targetTF = ""

if currentTF == "1"
targetTF := "15"
else if currentTF == "3"
targetTF := "30"
else if currentTF == "5"
targetTF := "60"
else if currentTF == "15"
targetTF := "240"
else if currentTF == "60"
targetTF := "D"
else if currentTF == "240"
targetTF := "W"
else
// Default fallback για μη-mapped timeframes
targetTF := "60"

targetTF

// Μετατροπή timeframe string σε λεπτά για σύγκριση
timeframeToMinutes(tf) =>
float minutes = 0.0

if str.contains(tf, "D")
multiplier = str.tonumber(str.replace(tf, "D", ""))
minutes := na(multiplier) ? 1440.0 : multiplier * 1440.0
else if str.contains(tf, "W")
multiplier = str.tonumber(str.replace(tf, "W", ""))
minutes := na(multiplier) ? 10080.0 : multiplier * 10080.0
else if str.contains(tf, "M")
multiplier = str.tonumber(str.replace(tf, "M", ""))
minutes := na(multiplier) ? 43200.0 : multiplier * 43200.0
else
minutes := str.tonumber(tf)

minutes

// Format countdown σε ώρες:λεπτά:δευτερόλεπτα ή λεπτά:δευτερόλεπτα
formatCountdown(milliseconds) =>
totalSeconds = math.floor(milliseconds / 1000)
hours = math.floor(totalSeconds / 3600)
minutes = math.floor((totalSeconds % 3600) / 60)
seconds = totalSeconds % 60

string result = ""

if hours > 0
result := str.format("{0,number,00}:{1,number,00}:{2,number,00}", hours, minutes, seconds)
else
result := str.format("{0,number,00}:{1,number,00}", minutes, seconds)

result

// Μετατροπή timeframe σε readable format
formatTimeframe(tf) =>
string formatted = ""

if str.contains(tf, "D")
formatted := tf + "aily"
else if str.contains(tf, "W")
formatted := tf + "eekly"
else if str.contains(tf, "M")
formatted := tf + "onthly"
else if tf == "60"
formatted := "1H"
else if tf == "240"
formatted := "4H"
else
formatted := tf + "min"

formatted

// ============================================================================
// MAIN LOGIC
// ============================================================================

// Επιλογή target timeframe βάσει mode
targetTimeframe = mode == "Auto" ? getAutoTimeframe() : customTF

// Validation: Έλεγχος αν το target timeframe είναι μεγαλύτερο από το τρέχον
currentTFMinutes = timeframeToMinutes(timeframe.period)
targetTFMinutes = timeframeToMinutes(targetTimeframe)

var string warningMessage = ""

if targetTFMinutes <= currentTFMinutes
warningMessage := "⚠ HTF < Current TF"
else
warningMessage := ""

// Υπολογισμός του χρόνου κλεισίματος του HTF candle
htfTime = request.security(syminfo.tickerid, targetTimeframe, time)
htfTimeClose = request.security(syminfo.tickerid, targetTimeframe, time_close)

// Υπολογισμός υπολειπόμενου χρόνου σε milliseconds
remainingTime = htfTimeClose - timenow

// Format countdown
countdown = warningMessage != "" ? warningMessage : formatCountdown(remainingTime)

// Format timeframe για εμφάνιση
displayTF = formatTimeframe(targetTimeframe)

// ============================================================================
// TABLE DISPLAY
// ============================================================================

// Δημιουργία table
var table countdownTable = table.new(
position=getTablePosition(tablePos),
columns=2,
rows=2,
bgcolor=transparentBg ? color.new(bgColor, 100) : bgColor,
frame_width=1,
frame_color=color.gray,
border_width=1)

// Update table content
if barstate.islast
// Header
table.cell(countdownTable, 0, 0, "Timeframe:",
text_color=textColor,
bgcolor=transparentBg ? color.new(bgColor, 100) : bgColor,
text_size=getTextSize(textSize))

table.cell(countdownTable, 1, 0, displayTF,
text_color=textColor,
bgcolor=transparentBg ? color.new(bgColor, 100) : bgColor,
text_size=getTextSize(textSize))

// Countdown
table.cell(countdownTable, 0, 1, "Countdown:",
text_color=textColor,
bgcolor=transparentBg ? color.new(bgColor, 100) : bgColor,
text_size=getTextSize(textSize))

table.cell(countdownTable, 1, 1, countdown,
text_color=warningMessage != "" ? color.orange : textColor,
bgcolor=transparentBg ? color.new(bgColor, 100) : bgColor,
text_size=getTextSize(textSize))

// ============================================================================
// END OF SCRIPT
// ============================================================================
릴리즈 노트
HTF Candle Countdown TimerThe HTF Candle Countdown Timer is a simple and practical indicator that displays a real-time countdown to the close of the next candle in a higher time frame (Higher Time Frame - HTF), helping traders align with multi-timeframe strategies. With automatic or custom HTF selection, the indicator provides a clear visual representation of the remaining time, ideal for monitoring significant closes in higher timeframes without constant manual calculations. It is particularly useful in dynamic markets where synchronized analysis across multiple timeframes is key to better decision-making.How It WorksThe indicator works by calculating the time remaining until the close of the current candle in a higher time frame (HTF), using data from the TradingView platform. The core logic relies on retrieving the close time (time_close) of the HTF via the request.security function, which pulls data from the selected HTF into the current chart.HTF Selection: In "Auto" mode, the indicator automatically maps the current timeframe to a higher one based on predefined pairs (e.g., 1 minute → 15 minutes, 5 minutes → 1 hour, 1 hour → Daily). In "Custom" mode, it uses the user-defined timeframe.
Time Calculation: The remaining time is derived from the difference htfTimeClose - timenow (in milliseconds), which is converted into a readable format (hours:minutes:seconds or minutes:seconds). The algorithm checks if the HTF is indeed higher than the current one (in minutes), and if negative, it displays a warning " HTF < Current TF".
Update: Updates occur only on the last bar (real-time), ensuring accuracy without overloading the chart.

This methodology ensures precision and speed, without complex mathematical formulas beyond basic arithmetic operations and time unit conversions.Parameters and SettingsThe indicator offers flexible settings through the input menu, allowing customization to each user's preference. Default values are optimized for immediate use, while changes directly impact the display and accuracy:Mode: Options "Auto" (default) or "Custom". "Auto" enables automatic HTF mapping; "Custom" activates the next parameter. Affects ease of use – "Auto" for beginners, "Custom" for advanced users.
Custom Timeframe: Timeframe in string format (e.g., "15" for 15 minutes, "D" for daily). Default "15". Active only in Custom mode; a smaller HTF than current triggers a warning.
Table Position: Options "Top Left", "Top Right", "Bottom Left", "Bottom Right" (default). Sets the table position on the chart for optimal visibility.
Text Color: Default white (color.white). Affects readability across different chart themes.
Background Color: Default black (color.black). Defines the table background for contrast.
Transparent Background: Default false. When enabled, makes the background transparent (100% transparency), ideal for light themes.
Text Size: Options "Auto", "Tiny", "Small", "Normal" (default), "Large", "Huge". Adjusts size for different screen sizes or preferences.

Visual ElementsThe indicator appears as a compact 2x2 table in the user-defined position, without interfering with chart lines or candles (overlay=true). The elements are:Cell 1 (Left, Top): Text "Timeframe:" with adjustable text color and background. Represents the label for the HTF.
Cell 2 (Right, Top): The formatted HTF (e.g., "15min", "1H", "Daily"). Shows the active timeframe.
Cell 3 (Left, Bottom): Text "Countdown:" in the same style. Label for the time.
Cell 4 (Right, Bottom): The countdown in HH:MM:SS format (if >1 hour) or MM:SS, with orange color in case of warning. Represents the exact remaining time; updates real-time.

The table has a gray border (frame_color=color.gray) and 1-pixel width for a subtle appearance.Trading SignalsThe indicator does not generate direct buy/sell signals or trading alerts, as it focuses on providing timing information. However, it offers a warning signal with the indication " HTF < Current TF" (in orange color) when the selected HTF is smaller or equal to the current one, alerting to invalid usage. This can be used indirectly in strategies, e.g., as a trigger for checks before trades near HTF closes.Recommended UsageThe indicator fits ideally in multi-timeframe strategies (e.g., combining 5 minutes with 1 hour), where knowledge of HTF close times helps avoid false moves.Markets: Suitable for Forex, stocks, cryptocurrencies, and indices, especially in volatile conditions where HTF closes influence direction.
Timeframes: Best on lower timeframes (1-15 minutes) for monitoring higher ones (1H-Daily), but works on all TFs with adjustment.
Strategies: Scalping or day trading with HTF confirmation, position trading for weekly/monthly closes, or combined with oscillators (e.g., RSI) for timed entries/exits.

Use it on real-time charts for maximum value.Important NotesLimitations: Operates exclusively in real-time (does not update on historical bars), and automatic mapping covers only specific TFs (e.g., not for 30 minutes) – use Custom mode for specialization. In offline mode or TradingView delays, time may not be 100% accurate.
Tips: Combine with alerts from other indicators for automated notifications near closes. Keep transparent background on light themes for better integration. Always verify HTF > current for accurate data, and remember the indicator is a support tool, not a guarantee of profitability.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.