One spelling
- Logic:
and,or,not, not&&,||,!(the same tokens). - Functions:
func spread(float h, float l) => h - l. The keyword-less form compiles too;defdeclares a method, not another spelling. - Body: an arrow while the body is one expression; braces and
returnfrom two statements. - Parameters: write the type; add a qualifier (
const,simple) only to restrict. The default isseries. - Analysis:
talib.sma(...);ta.sma(...)is the same namespace. - Persistence:
static, orintrafor a value kept across the ticks of one forming bar only; declare them after the inputs, assign with:=.vardoes not exist. - Arrays:
array.new<float>(0)and the method forma.push(x). - Drawings: create once into a
staticvariable and change it withset_*. - Strategy ids: one string constant per order id.
- Absence:
na(x), notx == na(a warning). - Enumerated arguments:
plotStyle.histogram,display.pane,size.small, not strings or numbers. - Colors:
color.redor#RRGGBB; fade withcolor.new(color.red, 0.7)(opacity 0 to 1). - Arguments: name every argument after the second:
plot(x, title="Spread", color=color.red).step=may be named.
Layout
- Order:
//@lipi=2, the declaration, inputs, calculations, thenplotand other output calls. - One statement per line, four spaces per block level,
elseon the line of the closing}. Break a long statement after a comma or an operator, never before one. - Comparisons do not chain and have unusual precedence: write
a < b and b < c, and parenthesise mixed conditions.
Names
- Variables, functions, arguments: lowerCamelCase (
fastLength). - Types, enums and their members: UpperCamelCase (
Swing,Speed.Fast). - Never reuse a built-in name (rules in Names and conventions).