Skip to content

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)

MA Crossover Labels Indicator

The editor includes this example as Indicator: MA Cross Labels.

script("MA Cross Labels", kind="indicator")

input fastLength = 20
input slowLength = 50

fast = ta.sma(close, fastLength)
slow = ta.sma(close, slowLength)
crossUp = ta.crossover(fast, slow)
crossDown = ta.crossunder(fast, slow)

plot(fast, title="Fast MA", color="#2962FF", width=2)
plot(slow, title="Slow MA", color="#FF9800", width=2)
plotText(fast, when=crossUp, text="Cross up: {price}", color="#2962FF", position="below")
plotText(fast, when=crossDown, text="Cross down: {price}", color="#FF9800", position="above")

Labels use the fast MA value on a confirmed signal candle, formatted with the instrument's price precision. This is not an interpolated price between candles. The last candle is excluded by default; add closedOnly=0 to each plotText call to allow forming-candle labels that may repaint.

See plotText options and limits.

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)
  }
}

Adaptive trend and market structure source files

The terminal repository includes two complete, independent StScript examples:

  • examples/stscript/adaptive-trend-signals.sts: adaptive ATR trend line, step/gradient fill, BUY/SELL label badges and optional markers.
  • examples/stscript/smart-money-structure-suite.sts: confirmed pivots, HH/HL/LH/LL, BOS/CHoCH, bounded OB/FVG collections, mitigation/projection options, candle colors and local alert conditions.

These examples are independent implementations, not a claim of identical signals to third-party Pine indicators. Import the .sts file through the desktop editor, review the inputs, then run and add the indicator to the chart. Keep confirmedOnly=1 in the SMC example for closed-candle changes. Pivots appear at their original candle only after confirmation.

Bounded projected zone

script("Confirmed pivot zone", kind="indicator")
input strength = 3
pivot = ta.pivotlow(low, strength, strength)
range = ta.atr(14)
if isClosed and not na(pivot) {
  draw.box("support", barIndex - strength, pivot + range, barIndex + 16, pivot, color="#76F7B8", opacity=0.2, text="Support", midline=1)
  draw.label("pivot", barIndex - strength, pivot, "HL", position="below")
}

The fixed IDs update one zone and one label. Generate unique IDs only when you intentionally retain older objects, and remove obsolete objects to stay within the object budget.

Adaptive Flow Pressure Oscillator

The terminal repository also includes examples/stscript/adaptive-flow-pressure-oscillator.sts. Open the UTF-8 .sts through the desktop editor, run it and add the registered indicator to the chart.

This is an independent implementation based on the public AFPO concept, not the closed QuantAlgo source or a promise of identical signals. It normalizes close displacement by ATR, multiplies by dampened relative volume, smooths pressure and scales it by rolling standard deviation. Signals use the raw normalized pressure. A separate soft-compressed display approaches the outer zones without changing the signal series. The slower bias is rendered as a histogram in an independent pane.

Missing/null/zero volume uses neutral effort and shows a price-only note. Flat price and zero variance do not divide by zero. Inputs control periods, zone thresholds, pane height, colors and divergence filters.

R marks regular divergence and H hidden divergence between price extrema and confirmed oscillator pivots. A badge is anchored to the original pivot but appears only after the configured right-side confirmation bars close. The example supplies local closed-candle alerts for zone, zero and bias crosses, momentum turns and four divergence types. Importing the file does not save or run it automatically.

Lorentzian Classification

Open examples/stscript/lorentzian-classification.sts from the terminal repository through the desktop editor. It uses five normalized features: RSI, WaveTrend, CCI, ADX and fast RSI. The runtime accepts up to 15 features calculated within the same script.

The example includes Gaussian/RQ kernel estimates, ATR near/far zones, EMA/ADX/kernel filters, closed-bar entries/exits, first-pullback markers, near/strong reversion markers, optional per-bar vote labels, confidence candle shades and local console alerts. Vote strength is not a calibrated probability.

signalStream is 1 for long entry, -1 for short entry, 2 for long exit, -2 for short exit and 0 otherwise; entry takes priority when events coincide. This is an ordinary result series, not a connection to automatic trading or the original Premium -6..+6 stream.

Selection uses causal nearest-neighbor voting with mature outcome labels. It intentionally differs from the public Pine ANN heuristic. The example does not include the closed Premium rules, daily higher-timeframe data, sources from other scripts, or a trade-statistics table. ML API defines the actual behavior and limits.

Prime / MVP oscillator suite

Open examples/stscript/prime-oscillators-suite.sts from the terminal repository. mode=0 selects Prime; mode=1 selects MVP. This is an independent composition inspired by the public Prime Oscillators Pro description, not the closed ChartPrime formulas or exact True 7 signals. Higher-timeframe flow and automatic timeframe presets are not included.

Prime combines RSI and raw WaveTrend with DEMA smoothing. MVP combines money flow and ATR-normalized deviation from VWMA, with a blue/purple ribbon and extension warnings. The panel includes a money-flow tracker, volume matrix, dynamic top/bottom power strips, ranking captions, regular divergences and local closed-candle signals.

The seven explicit ranking conditions are RSI>50, WT>0, fast EMA>slow EMA, close>fast EMA, rising oscillator, positive money flow and positive volume matrix. Captions show bullish conditions / available conditions. Without usable volume, the last two conditions are excluded, making the denominator 5; money-flow plots/matrix/volume signals are disabled, MVP falls back to the price oscillator and a status note appears. Warmup remains missing; a stationary market becomes neutral after warmup.

Diamonds mark confirmed confluence shifts; squares mark volume-weighted fairness recoveries; triangles mark oscillator reentries from extreme zones. D/MF captions indicate confirmed regular divergences. Backdated pivot anchors become known only after confirmation, not on the original pivot candle.