Use if-else statements for conditional logic.
//@version=5
indicator("Conditional Example", overlay=true)
ma = ta.sma(close, 14)
plotcolor = close > ma ? color.green : color.red
plot(ma, title="SMA 14", color=plotcolor)
Define and use custom functions.
//@version=5
indicator("Function Example", overlay=true)
f_smaPlusOne(src, length) =>
sma = ta.sma(src, length)
sma + 1
result = f_smaPlusOne(close, 14)
plot(result, title="SMA + 1", color=color.blue)
Use arrays for more complex data manipulation.
//@version=5
indicator("Array Example", overlay=true)
var float[] myArray = array.new_float(10, 0)
array.set(myArray, 0, close)
plot(array.get(myArray, 0), title="Array Value", color=color.purple)