Appearance

Personalize your experience

Mode
Accent Color
Direction
All Docs/QuaScript//
QuaScript logo

QuaScript Documentation

Language guide, engine API, 601 builtins and the preset library · v3.0.0-phase1

Strategies

A strategy header adds a simulated broker. Orders placed on a bar become active on the next bar and fill along that bar's price path: open, then the nearer extreme, the other extreme, close.

QuaScriptengine result
Loading the engine result…
breakout.qs
strategy "Donchian Breakout" {
    overlay    = true
    capital    = 100000
    commission = 0.05
    slippage   = 1
    sizing     = risk_percent
    size       = 1
}

(_, upper, lower) = ta.donchian(20)
trend = ta.ema(close, 200)
a = ta.atr(14)

if position.size == 0 and close > upper[1] and close > trend {
    order.market("L", side.long)
    exit.bracket("L exit", entry = "L", stop = close - 2 * a, target = close + 6 * a,
                 trail_offset = 2 * a, trail_trigger = close + 2 * a)
}
if position.size == 0 and close < lower[1] and close < trend {
    order.market("S", side.short)
    exit.bracket("S exit", entry = "S", stop = close + 2 * a, target = close - 6 * a)
}
risk.max_drawdown(25)
render.line(upper, "Upper")
render.line(lower, "Lower")
quatick-charts · QuaScript engine on synthetic 1-minute bars · drag to pan · scroll to zoom · Run executes the script on the engine (⌘/Ctrl+Enter while editing)

Orders

CallFills
order.market(id, side, qty)at the next bar's open (or this close with fill = close)
order.limit(id, side, price, qty)when price trades through price, at price or better
order.stop(id, side, price, qty)when price trades through price
order.stop_limit(id, side, stop, limit, qty)becomes a limit order at limit once stop trades
order.cancel(id) / order.cancel_all()removes pending entry orders
  • side is side.long or side.short. An entry against the open position reverses it.
  • qty = na (the default) sizes the order with the header's sizing / size.
  • tif = order.gtc (default), order.ioc, order.fok or order.post_only.
  • group = "g" puts orders in a one-cancels-others group.
  • Placing an order with the id of a pending one replaces it.
  • pyramiding limits the entries in one direction.

Exits

CallEffect
exit.bracket(id, entry, stop, target, trail_offset, trail_trigger, qty, qty_pct, unit)stop, target and trailing stop for the lots of entry (all lots if omitted); stop and target cancel each other
exit.close(id, qty, qty_pct)closes the lots of entry id at the next open
exit.close_all()flattens the position at the next open

unit = "ticks" reads stop / target / trail values as ticks from the entry price. A bracket placed together with its entry protects the position from the bar the entry fills on.

Position and portfolio

position.size side avg_price open_pnl bars_held entry_time and portfolio.equity initial_capital net_profit realized_pnl max_drawdown win_rate profit_factor trade_count read the broker's state on the current bar.

Risk rules

CallRule
risk.max_drawdown(pct)stop trading and flatten once equity falls pct percent below its peak
risk.max_daily_loss(amount)no new entries for the rest of the day after losing amount
risk.max_position(qty)entries that would exceed qty are rejected
risk.max_trades_per_day(n)at most n entries per day

Helpers: risk.position_size(entry, stop, risk_pct), risk.kelly(win_rate, payoff), risk.value_at_risk(returns, len, confidence), risk.expected_shortfall(...).

Results

A strategy's result has the trade list (entry / exit bar and price, side, quantity, profit, run-up, drawdown, exit reason), the equity and drawdown curves and these statistics: net profit (and %), gross profit / loss, profit factor, win rate, average trade / win / loss, payoff, expectancy, largest win / loss, maximum drawdown (and %), Sharpe, Sortino, Calmar, recovery factor, exposure, average bars in trade, commission paid, buy-and-hold return, consecutive wins / losses. The terminal's Strategy Tester shows them; quas run prints a summary and writes all of it to JSON.

Optimising

terminal.sh
quas sweep breakout.qs data.csv --param fast=5:30:5 --param slow=20:100:10 --threads 8 --sort sharpe

Every combination runs on its own thread; results are identical for any thread count.


© 2026 Quatick Technologies. All rights reserved.