CODESCRIPT

System

14 entries. What each one takes, what it returns, and a working example.

chartBgColor()

The chart background color (#rrggbb).

NOTE

For drawing in keeping with the theme — so your added layers color consistently with the background.

CODESCRIPT
if barstate.islast {
  label(close, chartBgColor(), barIndex)
}
plot(close)

Writes the background color onto the last bar as a label.

chartFgColor()

The chart foreground (text) color (#rrggbb).

NOTE

For keeping label/text color consistent with the theme.

CODESCRIPT
if barstate.islast {
  label(close, chartFgColor(), barIndex)
}
plot(close)

Writes the foreground color onto the last bar as a label.

chartIsStandard()

Returns whether the chart uses standard candles — currently always true.

NOTE

A gate for logic that branches on bar type; the value is constant because CodeScript produces standard bars.

CODESCRIPT
plot(chartIsStandard() ? 1 : 0, "Standart mı")

Plots a constant 1 on a standard chart.

chartLeftVisibleBarTime()

The timestamp of the first bar in the data range.

NOTE

For anchoring on the left edge of the visible window; as a reference when positioning along the time axis.

CODESCRIPT
plot(chartLeftVisibleBarTime())

Plots the first bar's timestamp as a flat line.

chartRightVisibleBarTime()

The timestamp of the last bar in the data range.

NOTE

For anchoring on the right edge of the visible window (the most recent bar).

CODESCRIPT
plot(chartRightVisibleBarTime())

Plots the last bar's timestamp as a flat line.

logError(mesaj)

Does not return a value; appends the message to the run log as an error (does NOT stop the script).

mesaj
string
The error text to write to the log.
NOTE

Does not halt execution — use runtimeError if you want to stop. For leaving a durable trace of an unexpected condition in the log.

CODESCRIPT
if close <= 0 {
  logError("gecersiz fiyat")
}
plot(close)

Had price been zero/negative an error line would be logged; on normal data it is not triggered.

logInfo(mesaj)

Does not return a value; appends the message to the run log as info.

mesaj
string
The information text to write to the log.
NOTE

Does not stop the script. For tracing intermediate values or which branch ran — the output collects in a separate log list.

CODESCRIPT
if barstate.islast {
  logInfo("tarama tamamlandi")
}
plot(close)

Adds an info line to the log on the last bar; the plot is unaffected.

logWarning(mesaj)

Does not return a value; appends the message to the run log as a warning.

mesaj
string
The warning text to write to the log.
NOTE

Does not stop the script; flags a non-fatal situation that deserves a touch more attention than info.

CODESCRIPT
if rsi(close, 14) > 70 {
  logWarning("asiri alim bolgesi")
}
plot(close)

Adds a warning to the log on bars where RSI rises above 70.

runtimeError(mesaj)

Does not return a value; stops the script and reports the given message as an error.

mesaj
string
The error message to show the user.
NOTE

Halts execution the moment it is called. To report a broken assumption (an invalid parameter, an unexpected state) early and clearly — guard it behind a condition so it only fires on the bad case.

CODESCRIPT
if close < 0 {
  runtimeError("fiyat negatif olamaz")
}
plot(close)

Had price been negative the script would stop; on normal data the condition is not met and price is plotted.

time_close(zaman_dilimi)

The CLOSE time (epoch milliseconds) of the current bar.

zaman_dilimi
string
Must be an empty string ("") or the current chart's timeframe.
NOTE

`time()` gives the bar's OPEN time, `time_close()` gives its close (open + bar duration). The result does not depend on exchange timezone — it's based purely on UTC bar boundaries.

CODESCRIPT
plot(time_close(""))

Plots each bar's close time (epoch ms).

timeframeChange(tf)

A boolean series: true on the bar that OPENS a new bucket of the given timeframe, false otherwise.

tf
string
Timeframe (with a unit; e.g. "1D", "1W", "1h").
NOTE

The first bar is always false (there is nothing before it). For an unrecognized timeframe the whole series is false.

CODESCRIPT
plotshape(timeframeChange("1D"), "Yeni gün")

Places a mark on the first bar of each new day.

CODESCRIPT
plot(timeframeChange("1W") ? high : na, "Hafta başı")

Plots the high on the first bar of a new week, empty (na) otherwise.

timeframeFromSeconds(saniye)

Converts seconds into a compact timeframe string (e.g. 3600 → "1h", 86400 → "1D"). Zero/negative or non-number → an empty string.

saniye
number
Length in seconds (e.g. 3600).
NOTE

The inverse of timeframeInSeconds; it picks the largest evenly-dividing unit (week > day > hour > minute).

CODESCRIPT
label(close, timeframeFromSeconds(3600))

Labels "1h" (3600 seconds = 1 hour).

CODESCRIPT
label(close, timeframeFromSeconds(86400))

Labels "1D" (86400 seconds = 1 day).

timeframeInSeconds(tf)

Returns the timeframe's length in seconds (e.g. "1h" → 3600). na for an unrecognized timeframe.

tf
string
Timeframe (with a unit; e.g. "15m", "1h", "1D").
NOTE

Converts a timeframe string into a numeric length; useful in scaling or comparisons.

CODESCRIPT
plot(timeframeInSeconds("1h"), "Saniye")

Plots a constant 3600 (1 hour = 3600 seconds).

CODESCRIPT
plot(timeframeInSeconds("1D") / 3600, "Günde kaç saat")

Plots a constant 24 (hours in a day).

timestamp(yıl, ay, gün, saat, dakika, saniye)

The epoch timestamp (milliseconds, UTC) built from the calendar parts.

yıl
number
Year (e.g. 2024).
ay
number
Month (1-12).
gün
number
Day (1-31).
saat
number
Optional, defaults to 0.
dakika
number
Optional, defaults to 0.
saniye
number
Optional, defaults to 0.
NOTE

The conversion is plain UTC — exchange timezone/DST is not involved (that only applies to READ variables like `hour`/`minute`/`year`). Arguments may be constants or series (e.g. `year`, `month`); if a series is given, the result is also computed bar-by-bar.

CODESCRIPT
plot(timestamp(2024, 1, 1, 0, 0, 0))

Plots the epoch millisecond value of 2024-01-01 00:00:00 UTC.