Skip to content
ƒ FlowscriptDocs
ftw.trade docs ↗
Documentation
Language / Flowscript

Indicators and models

Moving averages, oscillators, windows, sessions, market profile and models over the inputs your host supplies.

Indicators calculate over series your host supplies. The language does not connect to a venue or choose a data provider; the host declares and records those inputs.

Moving averages#

sma, ema, wma, rma, hma, dema, tema take (src, len); vwma(src, vol, len) and vwap(price, vol, len) weigh by volume.

Momentum and oscillators#

FunctionGives
rsi(src, len)0 to 100
stoch(close, high, low, len)0 to 100
cci(src, len), mfi(src, vol, len), obv(src, vol)The classic readings
roc(src, len), momentum(src, len)Rate of change (percent) and momentum
macd(src, fast, slow), macdSignal(…, sig), macdHist(…, sig)One function per line

Volatility and bands#

bbUpper(src, len, mult) and bbLower(…) (the middle is sma(src, len)), stddev, zscore, wilderAtr(high, low, close, len) (the ATR charts draw) and trueRange.

Trend#

adx(high, low, close, diLen, adxLen), diPlus, diMinus, supertrend(high, low, close, factor, len) with supertrendDir, and sar(high, low, close, start, inc, max).

Windows and levels#

highest, lowest, rolling_sum, cum, linreg, corr(a, b, len), median, percentile, barssince(cond), valuewhen(cond, src), and pivothigh and pivotlow (known a few bars late, by design).

Sessions and VWAP#

  • periodVwap(price, volume, t, 86400) is the day's VWAP from 00:00 UTC; anchoredVwap starts from any bar; both have σ bands.
  • inSession, inWeekdaySession, sessionOpen, sessionHigh and sessionLow frame a trading session in any city's time.
  • import "std/vwap"; adds what a VWAP trader reads: where price sits in σ, the week's and month's anchors, whether the day is trending, and a failed push into a band.

Market profile#

tpo.poc, tpo.vah, tpo.val, tpo.vpoc, tpo.poorHigh, tpo.singleAbove, tpo.nakedPocAbove and more read the last whole day's (or week's, or the forming session's) time-price profile, the same in a backtest and live.

Trained models#

Models train on the market as the strategy runs, with no look-ahead, and refit on a schedule. The same model is fitted in a backtest and live.

ModelAnswers
ml.linear, ml.ridge, ml.lasso, ml.elasticNet, ml.svrA forecast of y
ml.boostGradient-boosted trees forecasting y
ml.logistic, ml.boostClassifierThe chance y is above zero
ml.svmA signed margin
ml.knnThe mean y of the nearest rows

Each is written ml.<kind>(y, [x1, x2, …], window: n, horizon: h, retrain: r): it learns y h bars after the predictors over the last n rows, refits every r rows, and answers na until its first fit.

Flowscript
uses { bars: "^1" }
const close = bars.close("BTC-USD", "1h");
const ret = close[0] / close[1] - 1;
const fwd = close[0] / close[3] - 1;
const f = ml.ridge(fwd, [ret, close / ema(close, 20) - 1, rsi(close, 14)], window: 300, horizon: 3, retrain: 20);
metric("forecast", f);

This publishes a forecast without sending an action. Your host can expose actions that use the result. The ftw.trade strategy starters include a trading example with five features.

Liquidations#

Liquidation feeds are host-provided inputs. ftw.trade exposes liq.* for supported perp markets; its source documentation describes coverage. These feeds are part of that platform's binding rather than built into the language.