Direction-Invariant Code for Symmetric Trading Expert Advisors
Summary
This article presents a coding method for Expert Advisors whose trading rules are symmetric between long and short positions. It represents direction numerically as +1 or −1, then uses that value in arithmetic expressions and shared order logic. Examples show how to consolidate trailing-stop calculations, moving-average crossover entries, and MACD-based signals so that buy and sell cases use common code paths.
The author argues that this structure can reduce duplicated code, simplify error handling, and make later changes apply to both directions. The examples illustrate how prices, order types, take-profit levels, colors, and labels can be selected from the direction value. The method applies when a system’s rules are genuinely symmetric; strategies with directional differences may not fit it cleanly. The article offers programming examples and an argument for maintainability, but no measured comparison of development time, bug rates, or trading performance.
Key ideas
- Represent long and short direction as positive and negative values to support shared logic.
- Use direction in arithmetic to express mirrored price and stop calculations.
- Common code paths can reduce duplicated order handling and error processing.
- The approach suits systems whose rules are symmetric across trade directions.
- The article gives illustrative code examples but no quantitative evidence of trading benefits.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.