Detecting Candle Condition Crossings with Prior-State Tracking
Summary
This short MetaTrader example shows how to trigger an action when a candle-related condition changes from false to true. It maintains separate prior-state flags for buy-side and sell-side conditions. On each tick, a helper function checks whether the current condition is true while its stored state was false, then updates the stored state. This makes the function report the transition once rather than repeatedly while the condition remains true.
The sample applies the check to whether the current bar’s open is above or below a user-defined condition, leaving the actual trade rules as placeholders. It is a programming pattern for detecting threshold crossings, not a complete strategy: it specifies no threshold, position management, execution handling, or results. The initial state is set to true, which affects when the first crossing can be reported and should be considered when adapting the pattern. The note identifies the code as an example rather than a ready-to-use system.
Key ideas
- The helper detects a change into a true condition by comparing current and stored states.
- Separate state flags allow independent buy and sell condition checks.
- The example uses the current bar’s open relative to a user-defined condition.
- Trade rules and execution behavior are left unspecified.
- Initial state affects how the first crossing is handled.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.