//@version=5
indicator("Lesson 3 - Operators", overlay=true)
// Is this bar an up bar?
upBar = close > close[1]
// Ternary: green on up bars, red on down bars.
lineColor = upBar ? color.green : color.red
plot(close, "Close", color=lineColor, linewidth=2)
// Wide bars: range more than 2x the 20-bar average range.
avgRange = ta.sma(high - low, 20)
wideBar = (high - low) > 2 * avgRange
plotshape(wideBar, "Wide bar", shape.circle, location.abovebar,
color=color.yellow, size=size.tiny)
如何執行
1. 在 TradingView 打開任一圖表,點選下方的 Pine Editor。
2. 把編輯器裡的內容全選,用這段程式覆蓋過去,然後按 Save。
3. 點選 Add to chart。如果是策略, 再打開 Strategy Tester 分頁。
宣告變數
Pine 用 = 做指派。length = 14 建立一個整數變數。src = close 把收盤價序列指派給它。指派完之後,你可以在腳本的任何地方重複使用它們。