S T O C K G A M E P R O

Order-Flow Simulator

Saved coding config auto-loads in Trading Terminal.

CUSTOM INDICATOR BUILDER

Indicator tips
Use return to output a value.
You can write full JS with if, for, while.
Quick start
return sma10 - sma20;
return close - vwap;

AUTO TRADING BUILDER

Auto trade tips
Runs every tick. Use buy(), sell(), hold(), or advanced order helpers.
Risk
Always add safeguards (max size, cooldowns).

Variable Reference

Use inside the Indicator Code editor.

Full variable list and advanced auto-trade syntax are documented at the bottom.

Core OHLCV
  • open, high, low, close, vol
  • prevOpen, prevHigh, prevLow, prevClose, prevVol
  • prev2Open, prev2High, prev2Low, prev2Close, prev2Vol
  • i (index), t (0-1)
Derived
  • range, body, bodyPct, bodyDir
  • upperWick, lowerWick, gap, gapPct
  • hl2, hlc3, ohlc4, hlRangePct
  • change, changePct, logReturn, trueRange
Indicators
  • sma5, sma10, sma20, ema5, ema10, ema20
  • smaDiff, emaDiff, rsi14, rsiSlope, atr14
  • obv, vwap, roc12, stochK, stochD
  • volSma20, volChange, volChangePct, closeAboveVwap, trendUp
Order Types
  • orderQty, setOrderQty(qty)
  • buyOrderQty(), sellOrderQty()
  • buyMarket(qty), sellMarket(qty)
  • buyLimit(price, qty), sellLimit(price, qty)
  • buyStop(stop, qty, limitPrice?), sellStop(stop, qty, limitPrice?)
Arrays & Helpers
  • data, opens, highs, lows, closes, vols
  • sma(closes, period, i), ema(closes, period, i)
Indicator Code Examples
// Example: plot a custom momentum blend
return (rsi14 - 50) + (ema10 - ema20);
Auto-Trading Code Examples
// Example: simple oversold buy, overbought sell
if (Number.isFinite(rsi14) && rsi14 < 30 && balance > close * 3) {
  buy(3);
}
if (Number.isFinite(rsi14) && rsi14 > 70 && holdings > 0) {
  sell(Math.min(3, holdings));
}

Auto Trading Tutorial

Runs every tick. Use buy(qty), sell(qty), hold().

Advanced syntax and full variable list are at the bottom.

Portfolio Variables
  • balance, holdings, avgPrice, price
  • equity, pnl, returnRate, positionValue
Example

if (orderQty >= 5 && rsi14 < 30) { buyOrderQty(); }

if (orderQty >= 5 && rsi14 > 70) { sellOrderQty(); }

For more detailed explanations, please visit the Guide page.

Full Variable & Auto-Trading Reference

All indicator and auto-trade variables are listed below. The Custom Indicator overlay expects price-scale outputs.

Index & Time

  • t: normalized bar position (0-1)
  • i: bar index
  • time: bar timestamp bucket

OHLCV

  • open, high, low, close, vol
  • prevOpen, prevHigh, prevLow, prevClose, prevVol
  • prev2Open, prev2High, prev2Low, prev2Close, prev2Vol

Candle Structure

  • range, rangePct, body, bodyPct, bodyDir
  • isBull, isBear, isDoji
  • gap, gapPct, gapDir
  • upperWick, lowerWick, upperWickPct, lowerWickPct
  • hlRangePct, closePos, hl2, hlc3, ohlc4, typical

Returns & Range

  • change, changePct, logReturn, trueRange
  • atr7, atr14, atr21, atrPct

Moving Averages

  • sma5, sma10, sma20, sma50, sma100
  • ema5, ema10, ema20, ema50, ema100
  • smaDiff, emaDiff, ema10Slope, sma20Slope
  • priceAboveSma20, priceAboveEma20, trendUp

Momentum

  • rsi7, rsi14, rsi21, rsiSlope
  • roc12, stochK, stochD
  • macdLine, macdSignal, macdHist

Volume & Bands

  • vwap, obv, closeAboveVwap
  • volSma5, volSma20, volSma50, volChange, volChangePct, volRel
  • bbUpper, bbMiddle, bbLower, bbWidth, bbPctB

Arrays & Helpers

  • data, opens, highs, lows, closes, vols
  • sma, ema, highest, lowest, sum, avg, std

Auto-Trading Variables & Pro Syntax

Portfolio

  • balance, holdings, avgPrice, price
  • equity, pnl, returnRate, positionValue
  • lastTrade: { type, price, qty, time }

Order Helpers

  • orderQty, setOrderQty(qty)
  • buyOrderQty(), sellOrderQty()
  • buy(qty), sell(qty), hold()
  • buyMarket(qty), sellMarket(qty)
  • buyLimit(price, qty), sellLimit(price, qty)
  • buyStop(stop, qty, limitPrice?), sellStop(stop, qty, limitPrice?)
  • buyPct(pct), sellPct(pct)
  • buyValue(amount), sellValue(amount)
  • riskQty({ riskPct, stopPct, price, equityValue })

Execution Helpers

  • cooldown(key, ms): throttle by key
  • oncePerBar(key): one action per bar
  • mem: persistent memory store
  • ctx: runtime context (tick, bar index, time)