STS Script Examples¶
Moving Average Indicator¶
script("Moving Average", kind="indicator")
input length = 20
ma = ta.sma(close, length)
plot(ma, title="MA", color="#2962FF", width=2)
Bollinger Bands Indicator¶
script("Bollinger Bands", kind="indicator")
input length = 20
input mult = 2
basis = ta.bb_basis(close, length)
upper = ta.bb_upper(close, length, mult)
lower = ta.bb_lower(close, length, mult)
plot(basis, title="Basis", color="#2962FF", width=2)
plot(upper, title="Upper", color="#26A69A", width=1)
plot(lower, title="Lower", color="#EF5350", width=1)
Manual Test Buy Robot¶
This script opens a buy position immediately on onBar if there is no existing BTCUSD position.
script("Manual Test Buy", kind="robot")
input timeFrame = 300
input historyCount = 300
input volume = 0.01
input dryRun = 1
onBar {
if trade.positionsCount(symbol="BTCUSD") == 0 {
trade.buy(symbol="BTCUSD", volume=volume)
}
}
Moving Average Crossover Robot¶
script("MA Crossover", kind="robot")
input fastLength = 9
input slowLength = 21
input timeFrame = 300
input historyCount = 300
input volume = 0.01
input dryRun = 1
fast = ta.sma(close, fastLength)
slow = ta.sma(close, slowLength)
onBar {
if ta.crossover(fast, slow) and trade.positionsCount(symbol="BTCUSD") == 0 {
trade.buy(symbol="BTCUSD", volume=volume)
}
if ta.crossunder(fast, slow) and trade.positionsCount(symbol="BTCUSD") > 0 {
trade.closeAll(symbol="BTCUSD")
}
}
Live Tick Buy Robot¶
This script demonstrates live quote execution through onTick.
script("Live Tick Buy", kind="robot")
input timeFrame = 300
input historyCount = 300
input volume = 0.01
input dryRun = 1
onTick {
if ask > 0 and trade.positionsCount(symbol="BTCUSD") == 0 {
trade.buy(symbol="BTCUSD", volume=volume)
}
}