Allowed characters
[a-zA-Z_][a-zA-Z0-9_]*
- Must start with a letter or underscore.
- May then contain letters, digits, and underscores.
- Case-sensitive:
Close,close, andCLOSEare three different names. - No limit on length in practice (every identifier is interned once).
Examples: rsi, rsi14, _hidden, userName, MACDHist, kernelFunction.
Invalid: 20sma (starts with a digit), rsi-14 (hyphen), rsi.14 (dot).
Reserved keywords
The following names are reserved by the grammar and cannot be used as identifiers:
and break by continue else
enum export false for if
import in library method na
not once or strategy switch
true type var varip while
In addition the following names are reserved at top level because they are declaration keywords:
indicator library strategy study
(Inside a function body they can appear as parameters — the restriction applies to top-level declaration targets.)
Built-in names
Many identifiers are owned by the standard library. Shadowing them with a = or var declaration is allowed but hides the built-in for the rest of the script:
sma(x, y) => x + y // shadows ta.sma for bare `sma(…)` calls
plot(sma(close, 2))
The namespaced form (ta.sma) is always available regardless of shadowing. Common built-in namespaces:
- Series —
open,high,low,close,volume,time,bar_index - Namespaces —
ta.*,math.*,str.*,array.*,map.*,matrix.*,input.*,request.*,strategy.*,color.*,shape.*,size.*,location.*,line.*,box.*,label.*,table.*,plot.*,hline.*,format.*,scale.*,display.*,extend.*,font.*,position.*,syminfo.*,timeframe.*,session.*,barstate.*,dayofweek.*,chart.*,currency.*,log.*
For an exhaustive list see Built-ins.
v1–v4 compatibility aliases
Scripts written in older major versions call many functions without their namespace. ChartScript resolves bare names only after user-function lookup, so your own sma definition still wins:
- TA globals routed to
ta.*:sma,ema,rma,wma,vwma,swma,alma,hma,rsi,atr,tr,stdev,dev,variance,correlation,cci,cmo,cog,mfi,mom,roc,sar,stoch,tsi,wpr,linreg,cum,obv,accdist,highest,lowest,highestbars,lowestbars,barssince,valuewhen,crossover,crossunder,cross,rising,falling,change,pivothigh,pivotlow,percentrank,bbw,kcw,median,vwap - Math globals routed to
math.*:avg,max,min,abs,ceil,floor,round,sqrt,pow,exp,log,log10,sign,sin,cos,tan,asin,acos,atan,sum,todegrees,toradians - String routed to
str.*:tostring,tonumber - Flow:
iff(cond, then, else)→cond ? then : else
Legacy color names also resolve as bare identifiers (aqua, silver, red, …) and fold to the same hex as color.aqua, color.silver, color.red; a local variable named red shadows the constant.
Suggested style
- lowerCamelCase for variables and function parameters:
kernelLength,isTrendingUp. - UPPER_SNAKE_CASE for script-level constants:
MAX_ZONES,BULL_COLOR. - PascalCase for types and enums:
type Pivot,enum Trend. - Prefix a variable with its unit when it carries one:
len,lenBars,lenPct,lenPrice.
See Style guide for the full project conventions.