[<declaration_mode>] [<type>] <identifier> = <expression> | <structure> or <tuple_declaration> = <function_call> | <structure>
以下はコードはすべて有効な変数宣言の書き方。
BULL_COLOR = color.lime i = 1 len = input(20, "Length") float f = 10.5 closeRoundedToTick = math.round_to_mintick(close) st = ta.supertrend(4, 14) var barRange = float(na) var firstBarOpen = open varip float lastClose = na [macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9) plotColor = if close > open color.green else color.red
na
は特定の型を持たない値であるため、型の明示が必要。baseLine0 = na // compile time error! float baseLine1 = na // OK baseLine2 = float(na) // OK
[bbMiddle, bbUpper, bbLower] = ta.bb(close, 5, 4)
:=
演算子を用いて行われる。//@version=5 indicator("", "", true) sensitivityInput = input.int(2, "Sensitivity", minval = 1, tooltip = "Higher values make color changes less sensitive.") ma = ta.sma(close, 20) maUp = ta.rising(ma, sensitivityInput) maDn = ta.falling(ma, sensitivityInput) // On first bar only, initialize color to gray var maColor = color.gray if maUp // MA has risen for two bars in a row; make it lime. maColor := color.lime else if maDn // MA has fallen for two bars in a row; make it fuchsia. maColor := color.fuchsia plot(ma, "MA", maColor, 2)
3 種類のモードがある。