Join today
Strategies / Momentum / EMA Swing Limit Entry

EMA Swing Limit Entry on Gold

Once price has swung more than 45 pips away from its last touch of the 8 EMA, the system places a limit order back near that average. It buys pullbacks after strong up swings and sells rallies after strong down swings. Every trade carries a 30 point stop and a 25 point target.

MomentumLong & shortIntradayGold3 min
1.26Profit factor
1,894Net profit EUR
60.08%Win rate
253Trades
-596Max drawdown
7.49Avg trade

Best run of 5. Gold, 3 min, spread 0.6, from run pf:2026-09-15-GOLD-3m.tsv:1.

Entry rules, long

  1. Members only
  2. That swing high is above the 8 EMA
  3. No position is open
  4. Enter with a buy limit at the 8 EMA plus the size of its last one-bar move

Entry rules, short

  1. Members only
  2. That swing low is below the 8 EMA
  3. No position is open
  4. Enter with a sell limit at the 8 EMA minus the size of its last one-bar move

Exit rules

  1. Stop loss 30 points
  2. Members only

Test conditions

PeriodUp to 2026-09-15
InstrumentGold, 3 minutes
Spread0.6 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-15

Parameters

swingPeriod
EMA length the swing is measured from
8
seedPeriod
Bars used to seed the swing high / low on the first bar
8
swingTargetPips
Swing size in pips that arms an entry
45
baseCapital
Amount added to strategy profit before sizing
3000
riskFraction
Share of capital used in the sizing formula
0.02
capitalPerContract
Money per contract in the sizing formula
30
minPositionSize
Minimum contracts per trade
1
stopLossPoints
Protective stop in points
30
takeProfitPoints
Profit target in points
25

Every run

Markets and timeframes tested

MarketTimeframePFTradesWin %NetMax DD
GoldBest run3 min1.26 25360.081,894 EUR-596
Gold2 min1.23 20959.811,350 EUR-708
Gold5 min1.19 28558.601,516 EUR-774
Gold1 hour1.13 38958.351,644 EUR-1,199
Gold1 minn/a 6363.49620 EUR-350

Charts

Results by run

Profit factor by run

Above 1.0 made money, below 1.0 lost money.

0.00.51.01.52.01.0 = break-evenGold · 3 min1.26Gold · 2 min1.23Gold · 5 min1.19Gold · 1 hour1.13

Net profit against max drawdown

Net profitMax drawdown
0-2K-1K1K2KGold · 3 minGold · 1 hourGold · 5 minGold · 2 minGold · 1 min

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.

// ============================================================
// EMA Swing Limit Entry
// ProRealAlgos Strategy Library  |  prorealalgos.com
// Type: Momentum
// Direction: Long & short
// Timeframe tested: 3 minutes
// ============================================================

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

// --- Parameters ---
swingPeriod = 8            // EMA the swing is measured from
seedPeriod = 8             // bars used to seed the swing high / low on the first bar
swingTargetPips = 45       // swing size that arms an entry
baseCapital = 3000         // added to strategy profit before sizing
riskFraction = 0.02        // share of that capital put at risk
capitalPerContract = 30    // money per contract in the sizing formula
minPositionSize = 1        // never trade fewer contracts than this
stopLossPoints = 30        // protective stop
takeProfitPoints = 25      // profit target

// --- Indicators ---
ONCE swingHigh = Highest[seedPeriod](high)
ONCE swingLow = Lowest[seedPeriod](low)

swingMA = ExponentialAverage[swingPeriod](close)
swingTarget = swingTargetPips * PipSize

// Each touch of the EMA restarts the swing measurement.
IF high > swingMA AND low < swingMA THEN
  touchBar = BarIndex
  touchPrice = swingMA
  swingHigh = swingMA
  swingLow = swingMA
ENDIF

IF low > swingMA THEN
  barsSinceTouch = max(1, BarIndex - touchBar)
  swingHigh = Highest[barsSinceTouch](high)
  swingLow = swingMA
ENDIF

IF high < swingMA THEN
  barsSinceTouch = max(1, BarIndex - touchBar)
  swingLow = Lowest[barsSinceTouch](low)
  swingHigh = swingMA
ENDIF

IF (swingHigh - touchPrice) > swingTarget AND swingHigh > swingMA THEN
  buySetup = 1
ENDIF
IF (swingHigh - touchPrice) <= swingTarget THEN
  buySetup = 0
ENDIF

IF (touchPrice - swingLow) > swingTarget AND swingLow < swingMA THEN
  sellSetup = -1
ENDIF
IF (touchPrice - swingLow) <= swingTarget THEN
  sellSetup = 0
ENDIF

// Limit orders sit one EMA slope beyond the EMA.
slopeOffset = abs(round(swingMA - swingMA[1]))
positionSize = max(minPositionSize, round(((StrategyProfit + baseCapital) * riskFraction) / capitalPerContract))

16 more lines: the entry and exit rules.

Read this first

Known weaknesses

  • It was only tested on Gold. All four rows in the market table are Gold timeframes, so there is no evidence it works elsewhere.
  • Position size is not fixed. It grows with strategy profit (base capital 3000, risk fraction 0.02, 30 per contract), so later trades risk more than early ones.
  • The stop (30 points) is bigger than the target (25 points). A 60.08% win rate gave a profit factor of only 1.26 on Gold 3 minutes.
  • The average trade was 7.49 EUR, which leaves little room for slippage on limit fills.

Indicators used

EMA

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 trade automatically in ProOrder?

Yes. Entries are limit orders and the stop and target are coded, so it runs unattended once loaded.

How did it do on Gold?

Gold 3 minutes made 1,893.8 EUR over 253 trades. The 2 minute, 5 minute and 1 hour charts were also positive with profit factors between 1.13 and 1.23.

What drawdown did it have?

The worst drawdown on Gold 3 minutes was 596.1 EUR. Because size grows with profit, a drawdown late in a run can be larger than early on.

Why a 3 minute chart?

The 45 pip swing and 25 point target suit fast intraday moves in Gold. The 3 minute chart had the best profit factor of the timeframes tested.

Related

Strategies like this one

Monday Dip Buy

Uses the same indicator.

n/a PF · 146 trades

Triple Band Market Model

Best run on the same market, Gold.

2.27 PF · 203 trades

Turtle Soup

A similar profit factor.

1.26 PF · 867 trades

Trading Gold intraday? Join the ProRealAlgos waitlist and see how we run our systems.

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