Skip to main content

ArenaScript › Grammar v1.2

ArenaScript v1.2: syntax, examples and execution rules

ArenaScript describes a trading rule in a few declarative lines: when to enter, when to exit, how much to commit, and which parameters the engine may search. This page gives five complete examples, the Pine v5 equivalents and the execution rules as the engine applies them. What ArenaScript is for, and what it does not do: ArenaScript overview.

Structure of a script

A header, then sections. Indentation inside a section is free; # starts a comment.

Line or sectionRole
strategy "Name" version 1.2First line: name and grammar version.
asset: BTCMarket (BTC, ETH, SOL, BNB…).
timeframe: 4hCandle size: 5m, 15m, 30m, 1h, 2h, 4h; 1d in the Lab with a long history.
capital: 10000Starting capital.
entry:Long entry: condition: lines and size:.
short_entry:Short entry, same form.
exit:Exit conditions, stop, target, trailing stop, time limit.
params:Ranges the engine may search.

Five complete examples

Each of these scripts passes validate_arenascript on the public MCP server (checked 23 November 2026). They illustrate the syntax; none is a recommendation.

1. Long only: RSI pullback in an uptrend, fixed stop

strategy "RSI pullback in uptrend" version 1.2
asset: BTC
timeframe: 1h
capital: 10000

entry:
  condition: price > EMA(200)
  and RSI(14) crosses above 30
  size: 50%

exit:
  condition: RSI(14) > 70
  stop_loss: 3%

Buy half the capital when the close is above the 200 EMA and the RSI comes back above 30. Sell when the RSI goes above 70, or at a stop 3% below the entry price.

2. Long and short around the 200 EMA

strategy "Long and short around the 200 EMA" version 1.2
asset: ETH
timeframe: 4h
capital: 10000

entry:
  condition: price > EMA(200)
  and RSI(14) crosses above 40
  size: 50%

short_entry:
  condition: price < EMA(200)
  and RSI(14) crosses below 60
  size: 50%

exit:
  stop_loss: 3%
  take_profit: 6%

short_entry: opens a short. The stop and the target of exit: apply to both sides, measured from the entry price (for a short, the stop is 3% above). One position at a time.

3. ATR stop and target: Donchian breakout

strategy "Donchian breakout ATR" version 1.2
asset: BTC
timeframe: 4h
capital: 10000

entry:
  condition: price > DONCHIAN_HIGH(20)
  size: 50%

exit:
  stop_loss: 2 x ATR(14)
  take_profit: 3 x ATR(14)

DONCHIAN_HIGH(20) is the highest high of the 20 previous candles, the current one excluded. The stop sits 2 ATR below the entry, the target 3 ATR above, with the ATR read on the entry candle and kept for the whole trade.

4. Volume filter, trend strength and time limit

strategy "Breakout with volume filter" version 1.2
asset: SOL
timeframe: 1h
capital: 10000

entry:
  condition: price > DONCHIAN_HIGH(24)
  and volume > SMA(volume,20)
  and ADX(14) > 20
  size: 50%

exit:
  stop_loss: 2%
  take_profit: 4%
  timeout: 48

The breakout counts only when the candle volume is above its 20-candle average and the ADX above 20. timeout: 48 closes the trade after 48 candles if neither the stop nor the target was hit. A multiplier on the volume average (SMA(volume,20) * 1.5) is refused in v1.2.

5. Parameter ranges with params:

strategy "EMA cross with ranges" version 1.2
asset: BTC
timeframe: 4h
capital: 10000

entry:
  condition: EMA(12) crosses above EMA(26)
  size: 100%

exit:
  condition: EMA(12) crosses below EMA(26)
  stop_loss: 2 x ATR(14)

params:
  fast: min=5 max=20 type=int default=12
  slow: min=21 max=60 type=int default=26
  atr_stop: min=1.0 max=3.0 type=float default=2.0

The script runs as written with the default values. In the Lab, a sweep searches the ranges: fast moves the first moving average of each condition, slow the second, atr_stop the ATR multiplier of the stop. Every combination tried is counted in the verdict.

Conditions

One condition per line. Further lines start with and or or. AND binds tighter than OR: A / or B / and C means A OR (B AND C). For (A or B) and C, write A / and C / or B / and C.

FamilyAccepted forms
Moving averagesEMA(12) crosses above EMA(26), SMA(50) > SMA(200), price > EMA(200), price crosses below SMA(20) — SMA, EMA, RMA, WMA, HMA, ALMA, VWMA
RSIRSI(14) < 30, RSI(14) crosses above 30
OscillatorsSTOCH(14) < 20, CCI(20) > 100 — also ROC, CMO, CHANGE, MOM, WPR, MFI, ZSCORE
Trend strengthADX(14) > 20
MACDMACD(12,26,9) > SIGNAL, MACD(12,26,9) > 0 (MACD > 0 without arguments is refused)
Bands and channelsprice < BB_LOWER(20,2), price > KC_UPPER(20,2), price > DONCHIAN_HIGH(20), price < DONCHIAN_LOW(20), price > VWAP()
Volumevolume > SMA(volume,20)
CandlesCANDLE_ENGULFING, CANDLE_HAMMER, CANDLE_DOJI

List returned by the engine reference (arenascript_reference) on 23 November 2026. A form outside this list is refused with an explicit error, never silently ignored.

Exits and position size

Write the exit you want. Without any exit line, the engine applies an implicit exit tied to the entry signal, which is harder to read and to compare with a Pine script.

params:

Each line declares one range: name: min=… max=… type=int|float default=…. The script always runs with the default values; the ranges only matter when the Lab runs a sweep, on the CPU or on an NVIDIA GPU with CUDA. Recognised names include fast and slow (first and second moving average of a condition), atr_stop and atr_take (ATR multipliers), stop_loss and take_profit (percentages). Write the default equal to the value in the condition, as in example 5.

Pine v5 ↔ ArenaScript

Each line was checked on 23 November 2026 by replaying a Pine script and its ArenaScript version in the engine of the online judge, on BTCUSDT: same trades, entry and exit candle included, unless stated.

Pine v5ArenaScript v1.2
ta.ema(close, 12), ta.sma(close, 50)EMA(12), SMA(50)
ta.crossover(fast, slow) / ta.crossunder(fast, slow)EMA(12) crosses above EMA(26) / crosses below
ta.rsi(close, 14) > 70, ta.crossover(rsi, 30)RSI(14) > 70, RSI(14) crosses above 30
close > ta.highest(high, 20)[1]price > DONCHIAN_HIGH(20)
[dip, dim, adx] = ta.dmi(14, 14) … adx > 20ADX(14) > 20
volume > ta.sma(volume, 20)volume > SMA(volume,20)
cond1 and cond2two lines, the second starting with and
strategy.entry("Long", strategy.long) / strategy.shortentry: / short_entry: (the short side was not part of the replay)
strategy.close("Long") on a conditionexit: + condition:
strategy.exit(…, stop=close * 0.97) placed on the entry barstop_loss: 3%
strategy.exit(…, stop=close - 2 * ta.atr(14), limit=close + 3 * ta.atr(14))stop_loss: 2 x ATR(14), take_profit: 3 x ATR(14)
default_qty_type=strategy.percent_of_equity, default_qty_value=50size: 50%
commission_type=strategy.commission.percent, commission_value=0.1default fee of the Lab (0.1% per side)
process_orders_on_close=truedefault fill of the Lab (at the signal close)

No equivalent in v1.2: request.security, arrays, loops, your own functions, drawings and plot. Full side-by-side scripts: Pine Script vs ArenaScript. Already have a Pine script? The online judge reads it directly.

Execution rules

These are the rules of the Lab’s default mode (tv_exact_v1), read in the engine source. The online judge uses the same mode.

A backtest on the public MCP server is a draft (sealed: false) on about 35 days of server candles; its figures can differ from the Lab. Research on past data, never advice.

Get the free LabAlready have Pine? Test it free

Using it with an AI (MCP)

The public MCP server https://strategyarena.io/mcp (streamable HTTP, no key) lets an assistant write and check ArenaScript. Setup and client list: MCP page.

Loop for an assistant

1. arenascript_reference          # grammar and rules
2. write ArenaScript only (no Python, no Pine)
3. validate_arenascript           # engine preflight, line by line
4. repair_arenascript             # removes what the engine refuses, lists each removal
5. backtest_arenascript           # draft, sealed: false
6. inspect_pine_export_capability # EXACT / PARTIAL
7. get_lab_desktop_handoff        # the verdict is played in the Lab

Rules for the assistant

The internal strategies of the Strategy Arena simulation are also published in ArenaScript (list_arenascript_monsters, contracts page). Language overview for the site’s own engines: ArenaScript protocol.