Simple MA Cross Strategy by cryptosquanch

By cryptosquanch

Performance Metrics

Description

Simple MA Cross Strategy is an open-source moving-average crossover framework for trend entries, with optional MA confluence, cooldowns, time-of-day blocks, three exit models, and an optional always-in flip mode. It is published as a configurable testing tool, not as a finished trading system. The default settings are explained below so you can see exactly what produced the backtest on the chart.HOW IT WORKSEntriesA long signal is a confirmed bar-close crossover of Primary MA #1 above Primary MA #2. A short signal is the opposite crossunder. Both averages have their own type (SMA, EMA, SMMA/RMA, WMA, VWMA, HMA), length and source. Signals are evaluated only on closed bars, and the script uses no future-looking data and no pyramiding.Why the components are combinedA plain two-MA cross trades every wiggle in a range. The optional pieces each address one specific weakness of that, and each can be switched off so you can measure what it adds:- MA #4 directional confluence: a long-term average (default SMMA 1000) acts as a regime filter. Longs are only allowed while MA #4 sits below both entry MAs, and shorts only while it sits above them. This keeps the fast cross trading in the direction of the larger trend.- MA #4 distance filter (optional): rejects crosses that happen too close to MA #4, where direction is usually unclear.- Delayed confirmation (optional): after a signal, the setup must hold for X more candles before entry and is cancelled if it reverses.- Re-entry cooldown and chop protection (optional): if an opposite cross appears within X bars of the last one, the event is treated as chop. The strategy can exit and pause new entries for a set number of bars.- Time blocks: up to three windows (with time-zone selection) where new entries are blocked, or open trades are closed.Exit models1) Exit on MA 1+2 Cross (default): the trade closes on the opposite cross of the two entry MAs.2) Exit on MA 1+3 Cross: the trade closes when MA #1 crosses a separate Exit MA, with an optional lockout for the first X bars after entry.3) SL / TP Engine: stop-loss by structure lookback, fixed pips, percent or ATR. Take-profit by risk:reward, fixed pips, percent or ATR. Optional trailing activates only after the base target is touched, with a choice of TP-level or breakeven floor.Always-in mode (optional)When enabled, the strategy does not wait for a fresh cross while flat. It enters in the direction of the current MA regime (MA #1 above MA #2 = long, below = short). Combined with "Exit on MA 1+2 Cross", every opposite cross closes the trade and the next bar re-enters the other way, so the strategy stays in the market except when filters, cooldowns or time blocks prevent it.On-chart toolsLive entry/stop/target/trail lines, a live trade box, historical win/loss boxes, entry and exit labels with trade details, an optional status panel explaining why a setup is blocked, and alert options for entries, exits and filter events. Optimizer mode hides drawings for faster testing.DEFAULT SETTINGS AND STRATEGY PROPERTIES (used for the published chart)- Chart: OANDA:USDJPY, 1 hour. Strategy Tester date range Jan 2023 to Nov 2026.- Entry MAs: HMA 4 crossing HMA 60, close source.- Exit: Exit on MA 1+2 Cross. MA #4 confluence ON (SMMA 1000). Distance filter, delayed entry, cooldowns and chop protection OFF. Always-in mode OFF.- Time blocks ON, New York time: 16:45-18:15 (around the daily rollover, when spreads usually widen) and 08:15-09:30 (around scheduled US data releases).- Initial capital: 10,000 USD.- Order size: 0.10 lot = 10,000 units of USD per trade (about 1x the account in notional terms). Margin is set to 5% (20:1), which is a common retail forex leverage cap.- Commission: 0.005% of trade value per side.- Slippage: 5 ticks per fill (0.5 pip on OANDA USDJPY). Together, commission and slippage roughly represent a typical retail spread of about 1 pip round trip.- Risk: this default setup has no fixed stop. Trades close on the opposite cross. In the test period the largest single loss was about 144 USD, roughly 1.4% of starting equity. If you want a hard per-trade risk cap, switch the exit to the SL / TP Engine.WHAT THE BACKTEST SHOWSWith the settings above, the strategy made about 990 trades over the test period. After costs the net result was small and only slightly positive (about +3%), with a maximum drawdown of about 7.6% and a profit factor close to 1.0. The long side did better than the short side over this period, which was mostly a rising market for USDJPY. Treat this as a demonstration of the framework, not as evidence of an edge. Different instruments, timeframes and settings will give very different results, and past results do not predict future performance. Trading costs matter a lot with fast MAs. Test with your own broker's spread and commission before drawing conclusions.HOW TO USE IT1. Add it to a chart and set the Pips/Units value for your instrument (0.01 for JPY pairs, 0.0001 for most other FX pairs).2. Set Strategy Properties (capital, commission, slippage) to match your broker.3. Start with only the entry MAs and one exit model, then turn the filters on one at a time and compare the Strategy Tester results.4. Use the status panel and labels to see why a trade was taken or blocked.This script is for research and education. It is not financial advice.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView