AQL Language & Editor
It opens from Strategies → AQL code editor…. It solves a specific problem: without it, a strategy could only be defined through the combinations of the Mass Test (which is a search space, ambiguous by design). AQL code is the written form of one concrete strategy — unambiguous and reproducible — which the editor turns directly into something testable.
A first look
Name: SMA + RSI crossover Market: @ES Direction: long Entry: SMA(Close, 50) crosses above SMA(Close, 200) and RSI(Close, 14) > 50 Exit: RSI(Close, 14) > 70 TakeProfit: 3% StopLoss: 2 x ATR
The editor colors with this very palette: keywords, indicators, sources, numbers, operators.
Structure
- Name: a free-form name for the strategy.
- Market:/ Timeframe: / Generator: where the strategy comes from (optional): the market, the timeframe and the tool that found it. They do not change the rule; when the file is opened, the editor switches to that market.
- Direction:long / short (the default direction).
- Entry:conditions joined by and. Repeated = OR; with long/short it mixes directions.
- Exit: exit conditions (optional, repeated = OR).
- TakeProfit:/ StopLoss: the targets.
- Series:other markets the strategy reads (optional; see Reference series, below).
Comments. Single line: // or # to the end of the line. Paragraph, over several lines: between braces { … }, as in Delphi, or between /* … */. They can go anywhere, even in the middle of a condition (CCI(7) < { oversold } -100), and they let you switch off a whole block without deleting it.
Capitals. AniQuant writes the sections with an initial capital (Name, Entry, TakeProfit…), but the reader ignores case: older files in lower case are still read the same way. If the Market is a shuffled-data market (AQ Market Shuffle), the line carries the comment # SHUFFLED DATA: do not trade and the export window warns about it with a red band.
Indicators and operands
- →With a source: SMA(Close, 50)
- →Without a source: ATR(14)
- →A price series: Close[5] (5 bars ago)
- →Patterns without parentheses: BullishEngulfing
- →Shift: SMA(Close,20)[1]
A condition compares two things: one indicator with another, or with a number. It can also do arithmetic with them (see Formulas, below). And the strategy can enter with a Stop or Limit order instead of at market (see Entry orders).
Operators
>= / <= include the boundary value; <> means «not equal to». For DayOfYear and the other calendar filters, DayOfYear >= 72 and DayOfYear <= 77 selects the window of days 72 to 77 (both included).
Take Profit / Stop Loss
- →Percentage: 3%
- →Amount: $1.5
- →A multiple of ATR: 2 x ATR. It is the ATR of the previous bar: the current bar's would include its own range, which is not yet known when price touches the level. The same goes for break-even.
- →No target: none
The ATR period in TP/SL is ignored (it uses the global one).
Several entries · OR of blocks and long+short reversal
Repeat Entry: to join blocks with OR: the strategy enters if any of the blocks holds (each block being an internal and). The same with a repeated Exit:. A plain block inherits the strategy's direction:.
Add a direction to the block — Entry long: / Entry short: — to mix longs and shorts in one single strategy. When a block of the opposite direction to the open position fires, that position is flipped: it closes and opens the opposite one on the same bar (selling and buying the same day).
Direction: long Entry long: DayOfYear >= 48 and DayOfYear <= 54 Entry short: DayOfYear >= 55 and DayOfYear <= 58 Exit: DayOfYear >= 59 and DayOfYear <= 63
The exit covers only the flat gaps between windows: between a long window and a short one butted together there is no exit, the reversal is fired by the opposite block. The Seasonal Optimizer generates this automatically when it sends a long+short plan to the Portfolio — one strategy, exportable with its reversal to EasyLanguage (TradeStation), MQL5 (MetaTrader 5) and ProRealTime.
Reference series: reading another market
A condition can read a market other than the one you trade: the VIX to filter the S&P 500, bonds for gold, the Nasdaq for the Dow… Orders always go to the main series (the chosen symbol's); the other series is only read. It is declared in a Series: block with a name for each series, and used with the of suffix.
Full example: the CCI-710 system (buy the rebound of the 7-period CCI from oversold, with the 200-bar average rising, and exit after 10 bars) traded only with the VIX low and falling:
Name: CCI-710 with VIX Direction: long Series: vix = "$VIX" Entry long: CCI(7)[1] < -100 and CCI(7) > CCI(7)[1] and SMA(Close,200) > SMA(Close,200)[5] and Close of vix < 20 and SMA(Close,5) of vix < SMA(Close,5)[1] of vix Exit: BarsSinceEntry >= 10
The first three conditions are the usual CCI-710; the last two read the VIX: its close below 20 and its 5-session average below yesterday's (fear low and easing).
One line per series: alias = "SYMBOL", with the symbol in quotes. Optionally, its timeframe: vix = "$VIX" @D1. Without a timeframe, that series' bars are used as stored.
It goes after the whole term: Close of vix, SMA(Close,5)[1] of vix. You can also write the symbol directly, without declaring it: Close of "$VIX" < 20.
SMA(Close,5)[1] of vix is yesterday's VIX average, even if you trade the ES on 5-minute bars. No need to work out how many intraday bars fit in a day.
It never looks ahead: each bar sees the last bar of the other series that had already closed. The day's VIX (it closes at 22:15 Spanish time, 16:15 New York) counts for that day's daily ES bar, but not for an intraday bar before 22:15: that one sees yesterday's VIX.
True on the first bar of a new day (TradeStation's Date <> Date[1]). Useful intraday to act only once a day, right when the other series' daily value comes in.
The series is looked up in the Quote Manager by its symbol. For the example: export $VIX.X from TradeStation, import it and register it with the symbol $VIX. While the other series has no data (at the start of the history), the strategy does not trade.
Formulas: arithmetic, Define and Count
A condition can do arithmetic with indicators and prices: add, subtract, multiply, divide, count bars, find the highest value of a formula… No programming language to learn, and nothing AniQuant already does is lost: the strategy is tested the same way, runs on the GPU and is exported on its own to all 6 platforms.
Example: buy a very wide-range bar with a large body, after a bullish run, when it is the widest bar of the last 20:
Name: Wide range bar Direction: long Define range = High - Low Define body = Abs(Close - Open) Entry: range > 2 * ATR(14) and body > 0.6 * range and Count(Close > Open, 10) >= 7 and Highest(range, 20)[1] < range Exit: BarsSinceEntry >= 5
The third condition requires 7 of the last 10 bars to have closed above their open; the fourth, that today's range beats the widest of the previous 20 bars.
+ - * / and parentheses, with the usual order (* and / first). And three functions: Abs(x) (absolute value), Min(a, b) and Max(a, b). Example: (Close - Low) / (High - Low) > 0.7, the close in the top 30 % of the bar.
One per line, no colon: Define range = High - Low. A Define can use the ones above it. It is a shortcut so you don't repeat the formula and can read it better: it keeps nothing from one bar to the next (it is not an EasyLanguage variable), and the strategy is the same as writing the whole formula.
Count(condition, N): how many of the last N bars (the current one included) meet the condition. Sum(x, N): the sum over the last N bars, e.g. Sum(Close - Close[1], 5) < 0. N is a whole number of bars.
The usual ones now accept a formula instead of a price: Highest(High - Low, 20), SMA(Close - Open, 3), Lowest(RSI(Close, 14), 10). With a plain price (Highest(High, 20)) they are exactly the same as before.
After a parenthesis, a function or a Define: (High - Low)[1], range[1], Count(Close > Open, 5)[1]. Crosses work with formulas too: SMA(Close - Open, 3) crosses above 0.
Inside parentheses you can combine conditions: (Close > Open or Close > Close[1]), not (Close < SMA(Close, 50)). Between the lines of a block, and still rules.
Entry orders: Stop and Limit
By default, when the signal fires AniQuant enters at market, on the open of the next bar. It can also enter with a Stop order or a Limit order: the order is placed at the close of the signal bar and waits for the price; if the price does not come within the time you give it, it expires and there is no trade.
When buying, the level goes above (for example, the high of the signal bar): you only enter if the price breaks it. When selling, below. It is the classic breakout entry.
When buying, the level goes below (for example, the low of the signal bar): you only enter if the price pulls back to it. When selling, above. It is the pullback entry.
At the level of an indicator
The Stop or the Limit can also be placed at the value of an indicator on the signal bar, instead of at a price of the bar: a moving average, a band, the N-bar high, the anchored average, a pivot or yesterday's low… With the same optional distance (ticks, % or ATR), validity and rearm as always. For example, buying with a Limit at the pivot S2, or selling with a Stop below the anchored average.
- Lab: in the E/S column, the Order role (only for indicators that give a price). Each level, with its periods, for each ticked type (Stop, Limit) is one more variant of the sweep.
- AQ Genesis: in Configure, below the entry order, the level families: the signal bar, pivots, previous period, N-bar high/low, bands and moving averages. Each round takes one with sense: a buy Limit at a support, a buy Stop at a resistance.
- AQL: EntryOrder: limit at PivotS(2) valid 1 bars or EntryOrder: stop at Highest(High, 10) + 2 ticks.
- The value used: the indicator's on the signal bar, fixed while the order waits. For pivots and previous period levels, the next bar's: tomorrow's pivot is computed with today, which has already finished.
- Export: on all six platforms. On daily data the level is exact; MetaTrader 5 always is. On the others, with weeks, months or intraday sessions, on the last bar of each period the code still uses the previous period's level (at the close it does not know the period ends), and says so in a comment.
If the level is on the other side of the price (a buy Limit above it), the level already passed rule below applies. With no value (indicator warm-up), it is not placed.
In the Laboratory
In the sweep settings, the Entry row has three boxes: At market, Stop and Limit. You can tick one, two or all three: each one is tried as one more variant of the sweep (the combinations counter is multiplied) and each strategy in the ranking carries its own in the name, for example [Ord:Stop:X:1].
Without touching anything else, the Stop goes at the extreme of the signal bar (breaks the high when buying, the low when selling) and the Limit at the opposite extreme, valid for 1 bar. In ⚙ Advanced you can change everything: the reference, the distance, the validity and what to do in the special cases (below). Stop and Limit run on the GPU, as fast as at market.
That detail for each order is in ⚙ Sweep settings, always visible, with what each option means.
In AQ Genesis
In ⚙️ Settings, the Entry order row has the same boxes. If you tick several, Genesis considers them all: each round of the genetic search tries one, in turn, so they do not compete with each other. If you tick only one, every strategy uses it. Each sealed strategy keeps its own (in its name and its card) all the way to the Portfolio, Walk-Forward and the exports. The log says which orders take turns, and the search runs on the GPU.
In the AQL language
One EntryOrder: line. Without it, the strategy enters at market as always.
EntryOrder: stop high + 2 ticks valid 1 bars EntryOrder: limit close - 0.5 x ATR valid 3 bars rearm always EntryOrder: stop extreme valid 2 bars ifcrossed skip EntryOrder: market
The reference is a price of the signal bar: extreme (the high to buy with a stop, the low to buy with a limit; the other way round when selling), high, low, close or open. The distance, optional, in ticks, in % or in x ATR (14-period Wilder ATR). The sign is set by the type: buy stop and sell limit, +; buy limit and sell stop, -. Check warns you if it is the wrong way round.
valid N bars: how many bars the order waits (1 by default). If another signal arrives while it waits, rearm better (the default) moves it to the new level only if it is better (lower to buy, higher to sell); rearm always always does; rearm never, never. When re-armed, the validity starts again. With validity 1 there is no possible re-arming.
If, when it is placed, the price is already on the other side of the level (a buy stop below the close, for example): by default ifcrossed market, it enters anyway (if the next bar opens beyond it, at the open), as a broker would; with ifcrossed skip the signal does not produce a trade.
By default a limit only fills if the price trades through the level by one tick, as in AmiBroker, NinjaTrader, MultiCharts and TradingView: in real life, touching the level does not guarantee a fill. With touch a touch is enough, which gives more optimistic results.
How it fills
If the bar opens already beyond the level, it enters at the open: the stop at a worse price (as in real life); the limit at a better price.
If the price reaches the level during the bar, it enters at the level, rounded to the tick in the direction that makes the order harder.
The stop slips (once triggered it is a market order); the limit does not (its risk is not slipping, it is not being filled), just like the take profit.
The editor
A backtest on the chosen symbol, opening the Strategy Performance Report instantly.
It sends it to the Portfolio as a concrete strategy → re-test, equity, Survival, Multi-TF and PBO. The whole pipeline.
It seeds the indicators as fixed-period rows; the search engine reproduces the strategy (and many more). Widen them into ranges to optimize around it.
And the other way round: from the Mass Test or the Portfolio, right-click → Edit strategy (AQL) opens any strategy as editable code. You discover → you edit → you test or re-export.
Notes: the code describes a single strategy (not ranges); both is interpreted as long; a bare or between two conditions is treated as and (for an OR, repeat the Entry: block or use parentheses: (a or b)).
More from the editor
- ·When it opens empty it brings a complete example strategy («Pullback in trend»): press Test and it runs as is. Delete it and write your own.
- ·It opens with the symbol you have loaded in the main window.
- ·Export ▾ reaches all six platforms: TradeStation/MultiCharts, AmiBroker, MetaTrader 5, ProRealTime, TradingView and NinjaTrader 8.
- ·It accepts negative numbers: CCI(7) < -100, WilliamsR(14) > -20.
AniQuant can be tried free for 14 days, with every module and no card. If you have the book, 30.