Formula Editor & XapiScript complete reference

Comprehensive practical reference for formulas and formula-driven strategy values.

The Formula Editor is the interface to Generic Trader's XapiScript formula framework. It is used for calculations, indicators, event/state logic, position-aware values and formula-driven strategy fields. The most reliable way to build formulas is through the Formula Editor interface and its built-in functions rather than trying to treat XapiScript as a conventional text-only programming language with an external syntax manual.

Open the Formula Editor

Use the f(x) control in the upper toolbar. The Formula window separates built-in System formulas from My formulas created by the user. Use the search field to find functions by concept or name. See Open the Formula Editor and System formulas vs. My formulas.

Function families

FamilyExamples / purpose
Market dataBid, Ask, Last, sizes, recent/quote information
Session dataDaily open, high, low, settlement, open interest
Technical indicatorsSMA, EMA, RSI, MACD, ATR, VWAP, Bollinger Bands, Stochastic, Donchian and many others
Position/accountPosition-aware values and tradable-account context
Event/stateCrossing, changes, snapshots, accumulation and since-reset calculations
Price utilitiesRounding or constraining calculated values to valid market increments
OptionsImplied volatility, Greeks and related option analytics

See Useful Formula Editor function categories.

Create a custom formula

Select Create Formula, give the formula a descriptive function name, define any required parameters, then add functionality from the built-in formula picker. Build incrementally: first confirm the simplest component works, save it, then add the next condition or calculation. See Create a custom formula.

Parameters and compound results

Formula parameters can represent symbols, booleans, strings, numbers or indicator-oriented inputs. Some built-in functions return compound values rather than one scalar. Use the platform's sub-reference tools to select the needed numeric or string component rather than guessing internal field names. See Work with compound formula results.

Market-reference formulas

Choose the market source that matches the intended logic. Bid, Ask and Last are not interchangeable. A formula based on the last trade behaves differently from one based on the current bid. See Current-market reference formulas.

Event and state logic

Event functions are useful when the formula should react to a transition rather than continuously evaluate a condition. Examples include crossing detection, value-change detection, accumulation, snapshots and high/low tracking since a reset. See Event and state functions in formulas and Capture a value when an event occurs.

Position-aware logic

Position information can be used in formulas that depend on signed quantity or average entry price. This is essential for rules such as adjusting a stop relative to the current position. See Position-aware formula logic.

Price rounding

A mathematically valid number is not always a valid tradable price. Use the platform's price-rounding utility when a formula calculates an order price so the result conforms to the contract's minimum tick. See Use ClosestPrice for valid tick increments.

Use formulas in strategies

When formula mode is enabled in supported strategy fields, values such as price, quantity, side, symbol or other properties can be driven by formulas instead of static inputs. Use the simplest native order structure that satisfies the requirement before adding formula complexity. See Use formulas inside order strategies and Order strategies complete reference.

Example use cases

  • Session breakout: combine daily high/low values with crossing logic. See Session breakout formulas.
  • Capture a trigger value: snapshot a price when an event occurs so it does not recalculate continuously.
  • Position-based stop: reference the current position/entry information, then calculate and round a valid stop price.
  • Indicator-derived strategy value: use a built-in technical indicator as an input to a strategy field.

Testing discipline

  1. Describe the desired behavior precisely.
  2. Build one component at a time.
  3. Use system functions instead of recreating existing calculations.
  4. Round generated order prices correctly.
  5. Test in demo under realistic market movement.
  6. Inspect actual working orders after submission.
  7. Only move to live use after the entire sequence is understood.

See Test a custom formula or strategy safely and How to request help with a custom strategy.

Was this article helpful?

Get Started Now!

Try out our technology for free or open an account and start trading.

There is a substantial risk of loss in trading futures and options.