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 section | Role |
|---|---|
strategy "Name" version 1.2 | First line: name and grammar version. |
asset: BTC | Market (BTC, ETH, SOL, BNB…). |
timeframe: 4h | Candle size: 5m, 15m, 30m, 1h, 2h, 4h; 1d in the Lab with a long history. |
capital: 10000 | Starting 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.
| Family | Accepted forms |
|---|---|
| Moving averages | EMA(12) crosses above EMA(26), SMA(50) > SMA(200), price > EMA(200), price crosses below SMA(20) — SMA, EMA, RMA, WMA, HMA, ALMA, VWMA |
| RSI | RSI(14) < 30, RSI(14) crosses above 30 |
| Oscillators | STOCH(14) < 20, CCI(20) > 100 — also ROC, CMO, CHANGE, MOM, WPR, MFI, ZSCORE |
| Trend strength | ADX(14) > 20 |
| MACD | MACD(12,26,9) > SIGNAL, MACD(12,26,9) > 0 (MACD > 0 without arguments is refused) |
| Bands and channels | price < BB_LOWER(20,2), price > KC_UPPER(20,2), price > DONCHIAN_HIGH(20), price < DONCHIAN_LOW(20), price > VWAP() |
| Volume | volume > SMA(volume,20) |
| Candles | CANDLE_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
size: 50%— share of the equity committed. Always write the % sign.stop_loss: 3%orstop_loss: 2 x ATR(14)— distance from the entry price.take_profit: 6%ortake_profit: 3 x ATR(14)— target, same reading.trailing_stop: 2%— stop that follows the best close.timeout: 48— maximum number of candles in a trade.condition: RSI(14) > 70inexit:— exit on a signal; several lines combine like entry conditions.
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 v5 | ArenaScript 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 > 20 | ADX(14) > 20 |
volume > ta.sma(volume, 20) | volume > SMA(volume,20) |
cond1 and cond2 | two lines, the second starting with and |
strategy.entry("Long", strategy.long) / strategy.short | entry: / short_entry: (the short side was not part of the replay) |
strategy.close("Long") on a condition | exit: + condition: |
strategy.exit(…, stop=close * 0.97) placed on the entry bar | stop_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=50 | size: 50% |
commission_type=strategy.commission.percent, commission_value=0.1 | default fee of the Lab (0.1% per side) |
process_orders_on_close=true | default 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.
- Fill. Conditions are read on the candle close; the order fills at that same close (like
process_orders_on_close=truein Pine). The Lab also offers a fill at the next candle open. - Stop and target. They are active from the candle after the entry and are checked inside the candle, on its high and low. Their levels are measured from the fill price.
- Gap. If a candle opens beyond the stop, the exit fills at the open; the same for a target opened beyond.
- Stop and target in the same candle. The engine follows the path TradingView assumes without Bar Magnifier: if the high is closer to the open than the low, the price goes open → high → low → close, otherwise open → low → high → close; the first level met fills. On an exact tie, the low is taken first.
- Other exits. Trailing stop, time limit and exit conditions are decided on the close and fill at that close.
- Fees. 0.1% of each order (10 basis points per side) by default, no slippage; both can be changed in the Lab.
- Indicators. TradingView definitions (recursive EMA, Wilder RSI); no signal until every indicator of the script has its history.
- End of data. A position still open is valued at the last close and is not counted as a closed trade.
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.
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
- Use only the sections
entry:,short_entry:,exit:,params:. Do not invent sections or filters. - Refused with an explicit error: the old sections
regime,regime_filter,invictus_protection,arena_context,ml,portfolio,custom,alert,tags;regime == BULL;lower_band; multipliers on volume or ATR averages;momentum(n),+DI(n),-DI(n); natural-language conditions. - ArenaScript is the public contract: never ask for the Strategy Arena source code, and never present a backtest as advice.
- Put the thresholds worth searching in
params:.
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.