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 field | MesoLive support | Notes |
|---|---|---|
| Entry.VarDefines | Supported | Evaluated during Build preview and at entry fills. |
| Exit.VarDefines | Not supported | Not executed in live in the current version. |
| MoveLegAdjustment.VarDefines | Supported | Evaluated when the Operator applies the adjustment; persisted to the position. |
| RemoveLegsAdjustment.VarDefines | Supported | Same as above. |
| AddLegsAdjustment.VarDefines | Supported | Same as above. |
| UpdateVarsAdjustment.VarDefines | Supported | Can 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(fromExit.*)
- Expiration DTE variables like
expiration_<ALIAS>_dteare persisted and kept up-to-date; selection-only helpers likeexpiration_<ALIAS>_min/maxare 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.ConditionsEntry.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.