Skip to main content

VarDefines and variable persistence

VarDefines lets you define named numeric variables by evaluating ScriptEngine expressions and storing the result on the position. These variables are then available in later Entry/Exit/Adjustment condition evaluation.

Source reference (MesoSim): Strategy Definition Reference

Field support summary

Strategy Definition fieldMesoLive supportNotes
Entry.VarDefinesSupportedEvaluated during Build preview and at entry fills.
Exit.VarDefinesNot supportedNot executed in live in the current version.
MoveLegAdjustment.VarDefinesSupportedEvaluated when the Operator applies the adjustment; persisted to the position.
RemoveLegsAdjustment.VarDefinesSupportedSame as above.
AddLegsAdjustment.VarDefinesSupportedSame as above.
UpdateVarsAdjustment.VarDefinesSupportedCan be executed from the Signals UI; can auto-run when it’s the only adjustment action.

How persistence works in MesoLive

  • Variables are stored per position and reused during later evaluations.
  • New variables defined later are merged into the persisted set (existing values remain unless overwritten by a VarDefines with the same name).
  • Some built-in “threshold” vars are persisted at entry for convenience:
    • profit_target, stop_loss, max_days_in_trade (from Exit.*)
  • Expiration DTE variables like expiration_<ALIAS>_dte are persisted and kept up-to-date; selection-only helpers like expiration_<ALIAS>_min/max are not persisted beyond selection contexts.

Build preview vs live evaluation

Build preview

When you click Build for a new position, MesoLive constructs a preview position (selected expirations/legs) and evaluates:

  • Entry.VarDefines (preview only)
  • Entry.Conditions
  • Entry.AbortConditions

This allows conditions to reference pos_* / leg_* variables during Build. The values are not persisted until the position is actually entered and fills are recorded.

Live positions (after entry)

After entry, variables are persisted and evaluated/updated when:

  • Entry vars are recorded (entry fill workflow)
  • An Operator applies an adjustment that contains VarDefines
  • An UpdateVarsAdjustment runs (manual or auto-run)

If a VarDefines evaluation fails (missing market data, invalid expression, etc.), the update may be skipped and an event is recorded.

How to verify

  • During Build: open the Variables table on the build page and confirm expected variables exist and look sane.
  • After entry/adjustments: open Position Details and review the position’s Variables.
  • For debugging failures: check Events and use Data Explorer to confirm quote freshness.