Join today
Strategies / Trend / Rule Based MA Band

Rule Based MA Band: an 8 and 40 day SMA trend filter

The strategy buys when the 8 day SMA is more than 3% above the 40 day SMA and sells when it falls more than 3% below. The 3% band is there to avoid flipping on small crosses. Position size is fully invested and compounding, starting from 100,000.

TrendLong onlySwingDAX 40Daily
n/aProfit factor
1,001,428Net profit EUR
45.33%Win rate
75Trades
-442,242Max drawdown
13,352Avg trade

Best run of 31. DAX 40, Daily, spread 3, from run sweeps:2026-09-16-DAX40-D-opt.tsv:7.

Entry rules, long

  1. Members only

Exit rules

  1. Members only
  2. No stop loss or target

Test conditions

PeriodUp to 2026-09-16
InstrumentDAX 40, Daily
Spread3 points
Starting capital1,000,000
CostsSpread only. Commissions and overnight financing are not included.
BarsUp to 200,000 bars, fewer where the instrument has less history
Last tested2026-09-17

Parameters

startingCapital
Account size at the start; profits are reinvested
100000
slowPeriod
Slow SMA length
40
fastPeriod
Fast SMA length
8
entryFactor
Buy when the fast SMA is 3% above the slow SMA
1.03
exitFactor
Sell when the fast SMA is 3% below the slow SMA
0.97

Every run

Markets and timeframes tested

MarketTimeframePFTradesWin %NetMax DD
DAX 40Best runDailyn/a 7545.331,001,428 EUR-442,242
S&P 500Dailyn/a 5251.922,696,651 EUR-474,949
Nasdaq 100Dailyn/a 7055.711,927,541 EUR-567,382
Dow JonesDailyn/a 5651.791,207,794 EUR-141,591
GoldDailyn/a 5541.82688,733 EUR-296,382
Nasdaq 1001 hourn/a 1942.11514,204 EUR-109,265
Nasdaq 1004 hoursn/a 3243.75430,189 EUR-111,923
Nikkei 225Dailyn/a 6238.71337,233 USD-156,841
Nasdaq 10030 minn/a 757.14322,945 EUR-150,562
FTSE 100Dailyn/a 4843.75288,825 EUR-160,310
S&P 50030 minn/a 475.00266,591 EUR-112,894
DAX 404 hoursn/a 2556.00236,733 EUR-46,261
Nikkei 2254 hoursn/a 2343.48236,358 USD-61,322
DAX 4030 minn/a 757.14214,681 EUR-71,410
S&P 5004 hoursn/a 1735.29187,078 EUR-81,376
DAX 401 hourn/a 1942.11180,192 EUR-54,479
Nikkei 2251 hourn/a 1553.33160,519 USD-60,819
Nikkei 22530 minn/a 1050.00139,020 USD-67,234
Brent Crude15 minn/a 2653.85133,582 EUR-69,885
Nasdaq 10015 minn/a 450.00120,330 EUR-89,517
Gold1 hourn/a 785.71113,950 EUR-46,065
Brent Crude10 minn/a 1163.64112,513 EUR-67,522
S&P 50015 minn/a 333.3393,977 EUR-60,940
DAX 4015 minn/a 333.3390,983 EUR-40,965
S&P 5001 hourn/a 1650.0065,974 EUR-43,648
Dow Jones15 minn/a 333.3365,816 EUR-46,465
FTSE 1004 hoursn/a 1546.6765,627 EUR-43,405
Dow Jones4 hoursn/a 560.0048,699 EUR-39,048
FTSE 10030 minn/a 475.0044,763 EUR-35,158
Dow Jones1 hourn/a 560.0033,124 EUR-31,973
FTSE 10015 minn/a 250.0026,849 EUR-22,889

Charts

Results by run

Net profit against max drawdown

Net profitMax drawdown
0-1.0M-500K2.5M5.0MS&P 500 · DailyNasdaq 100 · DailyDow Jones · DailyDAX 40 · DailyGold · DailyNasdaq 100 · 1 hourNasdaq 100 · 4 hoursNikkei 225 · DailyNasdaq 100 · 30 minFTSE 100 · DailyS&P 500 · 30 minDAX 40 · 4 hoursNikkei 225 · 4 hoursDAX 40 · 30 minS&P 500 · 4 hoursDAX 40 · 1 hour

The code

ProBuilder, rewritten to house standard

Every file in the library uses the same header, the same section order and the same variable names. The numbers above were produced by the original version before the rewrite, and the rewrite has not yet been compiled in ProRealTime.

// ============================================================
// Rule Based MA Band
// ProRealAlgos Strategy Library  |  prorealalgos.com
// Type: Trend
// Direction: Long only
// Timeframe tested: Daily
// ============================================================

// --- Settings ---
DEFPARAM CumulateOrders = false
DEFPARAM PreloadBars = 10000

// --- Parameters ---
startingCapital = 100000  // account size at the start; profits are reinvested
slowPeriod = 40           // slow SMA length
fastPeriod = 8            // fast SMA length
entryFactor = 1.03        // buy when the fast SMA is 3% above the slow SMA
exitFactor = 0.97         // sell when the fast SMA is 3% below the slow SMA

// --- Indicators ---
// Fully invested: size is current equity divided by price, so it compounds.
accountEquity = startingCapital + StrategyProfit
positionSize = accountEquity / close

slowMA = Average[slowPeriod](close)
upperBand = slowMA*entryFactor
lowerBand = slowMA*exitFactor
fastMA = Average[fastPeriod](close)

14 more lines: the entry and exit rules.

Read this first

Known weaknesses

  • Size grows with every gain because the system stays fully invested, which inflates both profits and drawdowns. The best run had EUR 442,241.61 drawdown.
  • Only 75 trades on the best run, and several intraday runs had 4 to 7 trades, so samples are small.
  • There is no stop loss. A drop only exits once the 8 SMA is 3% below the 40 SMA.
  • Only sweep data exists, so profit factor was not recorded.

Indicators used

SMA

How to load it

  1. Copy the code with the copy button above the code block.
  2. In ProRealTime, open a chart of the instrument and timeframe you want to test, then open ProOrder > New trading system and choose "Create with programming".
  3. Paste the code, give the system a name and save it.
  4. Click "Backtest", set your own spread and position size, and run it before you consider trading it live.

Questions

About this strategy

Can it run in ProOrder?

Yes, but the compounding share based sizing needs a broker account that allows it. Check the position size logic before going live.

Which markets were tested?

All 30 runs were profitable, led by S&P 500 Daily at EUR 2,696,650.83 and Nasdaq 100 Daily at EUR 1,927,541.43. These figures reflect compounding from 100,000, not 1 contract.

How much capital does it need?

The code starts from 100,000 and reinvests all profit. On DAX 40 Daily the max drawdown was EUR 442,241.61, so expect large swings in account value.

Why daily bars?

The 8 and 40 day averages are built to catch trends lasting weeks to months. On intraday bars they produce very few trades.

Related

Strategies like this one

Bollinger Squeeze

Uses the same indicator.

14.30 PF · 86 trades

Buy After Price Fall

Best run on the same market, DAX 40.

1.88 PF · 312 trades

Long-Term Moving Average Cross

Also a trend strategy.

12.31 PF · 61 trades

Long term trend followers, the ProRealAlgos community waitlist is open.

The ProRealAlgos community gets the full rules, the complete code and the automated portfolio.

Past backtest results do not guarantee future results. This is not financial advice. Curated and maintained by ProRealAlgos. ProRealTime™ is a trademark of ProRealTime SAS. prorealalgos.comStatsDocs