EMA Stack Strategy (DCA or Single Entry, HTF Logic) by cryptosquanch
By cryptosquanch
Performance Metrics
- Author: cryptosquanch
- Symbol: OANDA:USDJPY
- Timeframe: 15 minutes
- Net P&L: +150.53 USD (+0.15%)
- Win Rate: 35.8%
- Profit Factor: 1.257
- Max Drawdown: 53.55 USD (0.05%)
- Total Trades: 740
Description
This strategy implements a multi-moving-average (MA) stacking system combined with flexible execution modes, allowing traders to test both trend-following entries and position management techniques within a single framework.Core conceptThe strategy uses up to four configurable moving averages to define directional bias. A valid trend is identified when the averages are properly stacked (e.g., faster MAs above slower MAs for long trades). Entries can optionally require multiple confirmed closes in a valid stack, which helps reduce noise and avoid premature signals.Higher timeframe logic and non-repainting behaviorThe script supports running MA calculations on a higher timeframe while executing on a lower chart timeframe. Signals are only updated on confirmed higher timeframe closes using request.security() with lookahead disabled, which prevents repainting and ensures that historical results reflect confirmed data.Dual trading modesTwo execution modes are available:* DCA / Grid mode: builds a position through multiple entries as price moves against the initial trade. Spacing between entries can be based on fixed units, percentage, or ATR, and can expand progressively using a scaling factor.* Single Entry mode: places one position per signal and manages it using a selectable exit system.DCA system designThe DCA module is not a simple averaging tool. It includes:* Configurable spacing using Units, Percent, or ATR* Optional geometric spacing expansion (step scaling)* Position sizing growth (volume scaling) or manual ladder sizing* Maximum total capital cap to limit exposure* Choice between anchoring to first entry price or average position priceThis structure allows users to test different grid-style risk distributions rather than relying on fixed averaging.Exit logicExit behavior differs by mode:* DCA mode: * Take profit is calculated from the average entry (breakeven) plus an offset * Optional trailing stop activates after price moves in favor * Optional “after last DCA” exit logic targets a move from the final entry instead of the average price * Optional MA-based kill switch to close positions when trend structure breaks* Single Entry mode: * Multiple exit types including MA cross, ATR-based bracket, risk-reward bracket, percent-based bracket, and time stop * Optional break-even adjustment * Optional independent trailing stopRisk and position managementThe strategy includes controls to:* Limit total capital deployed in DCA mode* Adjust position sizing per entry* Configure stop distances using ATR, percent, or structure* Prevent new trades or DCA adds during specific time windowsThese tools are intended to help simulate more realistic position management conditions rather than fixed, static strategies.Visualization and usabilityThe script provides:* Clear MA overlays for trend structure* Optional plotting of average entry, take profit, and next DCA level* Trade summary labels including P/L, number of entries, and drawdown in units* Optional status table showing real-time strategy stateNotes on backtesting and usage* Results depend heavily on parameter selection, market conditions, and timeframe* DCA/grid strategies can increase exposure during adverse price movement and should be tested carefully* Default settings use zero commission and slippage; users should adjust these to better reflect real trading conditions* Past performance does not guarantee future resultsThis script is intended as a configurable framework for testing MA-based trend entries combined with different position management techniques, rather than a fixed or optimized trading system.