Documentation/AlgoCode/Examples
Examples
Minimal Pine snippets you can paste into Chart Script and adapt for live deploy.
SMA cross entries
//@version=5
strategy("SMA Cross", overlay=true)
fast = ta.sma(close, 9)
slow = ta.sma(close, 21)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.entry("Short", strategy.short)Multi-target with algo.levels
//@version=5
strategy("Levels demo", overlay=true)
if ta.crossover(ta.sma(close, 5), ta.sma(close, 20))
strategy.entry("L", strategy.long)
algo.levels(sl = 50, tp1 = 100, tp2 = 200, qty1 = 50, qty2 = 50)Script exit with strategy.close
//@version=5
strategy("Close on RSI", overlay=true)
rsi = ta.rsi(close, 14)
if rsi < 30
strategy.entry("L", strategy.long)
if rsi > 70
strategy.close("L")More on exits: Risk & exits · Deploy