OPENSTRATS

FX daily Hodrick–Prescott trend

Research

Compares five-day and twenty-day moving averages of causally filtered daily closes. MT5 fills with separately estimated exit commission.

SYM AUDUSD,EURGBP,EURUSD,GBPJPY,GBPUSD,USDJPYTF D1TEST 2020-01-01 → 2024-12-31UPDATED VIEWS 0DOWNLOADS 0#trend

BACKTESTS · 13

7 of 13
NET PROFIT · USD
+738
from 100,000 USD
RETURN
+0.7%
CAGR
+0.1%
5.0 yrs
PROFIT FACTOR
1.06
SHARPE
0.06
MAX DD
-4.0%
equity, relative
RECOVERY
0.18
TRADES
68
38.2% win

EQUITY · BALANCE (USD)

FX_HPTrend · EURUSD Daily · quality 99% real ticks · drag to zoom, double-click to reset

MONTHLY RETURNS

% of balance at month start
YearJanFebMarAprMayJunJulAugSepOctNovDecYear
2020-0.3%·-1.2%-0.5%-0.5%0.7%-0.2%1.3%-0.6%-0.1%-0.8%·-2.1%
20210.8%0.2%-0.5%0.0%·0.5%·0.4%-0.4%0.2%-0.2%0.6%+1.8%
2022-0.3%-1.1%0.6%-0.3%0.5%-0.9%0.7%-0.5%-0.7%-0.2%··-2.3%
20232.2%-0.2%-0.0%·0.4%0.3%0.2%-0.1%·1.2%·-0.1%+3.8%
2024-0.1%0.4%-0.1%·0.2%-0.1%-0.1%-0.3%-0.1%-0.6%0.5%-0.2%-0.3%

TRADE STATS

Gross profit13,902.86Gross loss-13,164.74
Expected payoff10.85Total deals136
Long trades34 (29.4%)Short trades34 (47.1%)
Largest win2,416.94Largest loss-1,227.11
Average win534.73Average loss-313.45
Max consec. wins3Max consec. losses5
Balance DD max2,678.41 (2.7%)Equity DD max4,073.10 (4.0%)
Leverage1:100Brokerafx Markets Ltd
All report fields (46)
History Quality99% real ticks
Bars1560
Ticks115498485
Symbols1
Total Net Profit738.12
Balance Drawdown Absolute2 678.41
Equity Drawdown Absolute3 393.04
Gross Profit13 902.86
Balance Drawdown Maximal2 678.41 (2.68%)
Equity Drawdown Maximal4 073.10 (4.05%)
Gross Loss-13 164.74
Balance Drawdown Relative2.68% (2 678.41)
Equity Drawdown Relative4.05% (4 073.10)
Profit Factor1.06
Expected Payoff10.85
Margin Level33201.05%
Recovery Factor0.18
Sharpe Ratio0.06
Z-Score1.91 (94.39%)
AHPR1.0001 (0.01%)
LR Correlation0.74
OnTester result0
GHPR1.0001 (0.01%)
LR Standard Error838.43
Total Trades68
Short Trades (won %)34 (47.06%)
Long Trades (won %)34 (29.41%)
Total Deals136
Profit Trades (% of total)26 (38.24%)
Loss Trades (% of total)42 (61.76%)
Largest profit trade2 416.94
Largest loss trade-1 227.11
Average profit trade534.73
Average loss trade-313.45
Maximum consecutive wins ($)3 (1 301.99)
Maximum consecutive losses ($)5 (-1 504.31)
Maximal consecutive profit (count)2 416.94 (1)
Maximal consecutive loss (count)-1 935.41 (4)
Average consecutive wins1
Average consecutive losses2
Correlation (Profits,MFE)0.85
Correlation (Profits,MAE)0.61
Correlation (MFE,MAE)0.3402
Minimal position holding time48:00:00
Maximal position holding time1392:00:00
Average position holding time460:08:49

NOTES

Compares five-day and twenty-day moving averages of causally filtered daily closes. Each endpoint uses the latest 120 observations and a smoothing parameter of 1,600. The tested notional is 0.30 times equity.

HPTrend, Jan 2020–Oct 2026. Fixed-fill exit-fee estimates give +$3,967.14 on $100,000, +0.047% compounded monthly. The original MT5 statement booked +$4,004.72 with zero exit commission. Estimated maximum equity drawdown bounds are 4.04% to 4.08%.

HPTrend, Jan 2025–Oct 2026. Fixed-fill exit-fee estimates give +$3,284.88 on $100,000, +0.147% compounded monthly. The original MT5 statement booked +$3,294.89 with zero exit commission. Estimated maximum equity drawdown bounds are 1.89% to 1.90%.

Six FX pairs were tested. The attached calendar windows overlap.

InputValueOptimise (start / step / stop)Section
Exposure0.30
TesterOnlytrue
FX_HPTrend.mq5159 lines · 5.5 KB · 2026-11-29 ↓ download
View source
// Causal endpoint HP crossover, adapted from Kakushadze & Serur, section 8.1.
// Fixed daily research horizons: 120 observations, HP lambda 1600, SMA 5/20.
// Each endpoint is estimated using a window ending at that historical close.
#property strict
#property version "1.00"
#include <Trade/Trade.mqh>

#define HP_WINDOW 120
#define FAST 5
#define SLOW 20
#define OBSERVATIONS (HP_WINDOW + SLOW - 1)

const double LAMBDA = 1600.0;
const ulong MAGIC = 324786501;
input double Exposure = 0.30; // Entry notional as a multiple of equity
input bool TesterOnly = true;

CTrade trade;
double weights[HP_WINDOW];
datetime signalBar = 0, completedBar = 0, nextAttempt = 0;
int target = 0;

bool IsMajorCurrency(const string currency)
{
   return StringFind("|USD|EUR|JPY|GBP|CHF|CAD|AUD|NZD|", "|" + currency + "|") >= 0;
}

void BuildEndpointWeights()
{
   // Solve (I + lambda D'D)w = e_last once. D is the second-difference matrix.
   // The symmetric system has two nonzero subdiagonals, as does its Cholesky factor.
   double diag[HP_WINDOW], sub1[HP_WINDOW], sub2[HP_WINDOW], rhs[HP_WINDOW];
   for(int i = 0; i < HP_WINDOW; i++)
   {
      const int dist = (i < HP_WINDOW-1-i ? i : HP_WINDOW-1-i);
      const double a = 1 + LAMBDA * (dist == 0 ? 1 : dist == 1 ? 5 : 6);
      sub2[i] = i > 1 ? LAMBDA / diag[i-2] : 0;
      sub1[i] = 0;
      if(i > 0)
      {
         const double b = (i == 1 || i == HP_WINDOW-1 ? -2 : -4) * LAMBDA;
         sub1[i] = (b - sub2[i] * sub1[i-1]) / diag[i-1];
      }
      diag[i] = MathSqrt(a - sub1[i]*sub1[i] - sub2[i]*sub2[i]);
      rhs[i] = i == HP_WINDOW-1 ? 1.0 / diag[i] : 0;
   }
   for(int i = HP_WINDOW-1; i >= 0; i--)
   {
      double v = rhs[i];
      if(i+1 < HP_WINDOW) v -= sub1[i+1] * weights[i+1];
      if(i+2 < HP_WINDOW) v -= sub2[i+2] * weights[i+2];
      weights[i] = v / diag[i];
   }
}

bool Signal(int &side)
{
   double prices[OBSERVATIONS];
   if(CopyClose(_Symbol, PERIOD_D1, 1, OBSERVATIONS, prices) != OBSERVATIONS)
      return false;
   double slowSum = 0, fastSum = 0;
   for(int end = 0; end < SLOW; end++)
   {
      double endpoint = 0;
      for(int j = 0; j < HP_WINDOW; j++)
         endpoint += weights[j] * prices[end+j];
      slowSum += endpoint;
      if(end >= SLOW - FAST) fastSum += endpoint;
   }
   const double delta = fastSum/FAST - slowSum/SLOW;
   side = delta > 0 ? 1 : delta < 0 ? -1 : 0;
   return true;
}

bool EntryLots(const double price, double &lots)
{
   const string account = AccountInfoString(ACCOUNT_CURRENCY);
   const double contract = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE);
   double notional = contract;
   if(SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE) != account)
   {
      if(SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT) == account)
         notional = contract * price;
      else
      {
         // Translate one lot's quote-currency notional into account currency.
         double profit = 0;
         if(!OrderCalcProfit(ORDER_TYPE_BUY, _Symbol, 1, price, price*1.01, profit))
            return false;
         notional = MathAbs(profit) * 100;
      }
   }
   const double step = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
   if(notional <= 0 || step <= 0) return false;
   const double desired = AccountInfoDouble(ACCOUNT_EQUITY) * Exposure / notional;
   lots = NormalizeDouble(MathFloor(MathMin(desired, SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX))/step + 1e-10) * step, 8);
   if(lots < SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN)) lots = 0;
   return true;
}

bool Filled(const bool sent)
{
   if(sent && trade.ResultRetcode() == TRADE_RETCODE_DONE) return true;
   PrintFormat("HP trade retry: %u %s", trade.ResultRetcode(), trade.ResultRetcodeDescription());
   return false;
}

bool AlignPosition(const int side)
{
   // Re-read current state on retry; never close another strategy's position.
   bool holding = false;
   for(int i = PositionsTotal() - 1; i >= 0; i--)
   {
      const ulong ticket = PositionGetTicket(i);
      if(ticket == 0 || PositionGetString(POSITION_SYMBOL) != _Symbol) continue;
      if((ulong)PositionGetInteger(POSITION_MAGIC) != MAGIC) return true;
      const int direction = PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY ? 1 : -1;
      if(direction == side) holding = true;
      else if(!Filled(trade.PositionClose(ticket))) return false;
   }
   if(holding || side == 0) return true;
   MqlTick tick;
   if(!SymbolInfoTick(_Symbol, tick) || tick.bid <= 0 || tick.ask <= 0) return false;
   double lots = 0;
   if(!EntryLots(side > 0 ? tick.ask : tick.bid, lots)) return false;
   if(lots == 0) return true;
   return Filled(side > 0 ? trade.Buy(lots, _Symbol) : trade.Sell(lots, _Symbol));
}

int OnInit()
{
   if(TesterOnly && !MQLInfoInteger(MQL_TESTER))
   {
      Print("HP research EA requires Strategy Tester with default settings.");
      return INIT_FAILED;
   }
   if(Exposure <= 0 || Exposure > 1 ||
      !IsMajorCurrency(SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE)) ||
      !IsMajorCurrency(SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT)))
      return INIT_PARAMETERS_INCORRECT;
   trade.SetExpertMagicNumber(MAGIC);
   if(!trade.SetTypeFillingBySymbol(_Symbol)) return INIT_FAILED;
   BuildEndpointWeights();
   return INIT_SUCCEEDED;
}

void OnTick()
{
   const datetime bar = iTime(_Symbol, PERIOD_D1, 0);
   if(bar <= 0 || bar == completedBar || TimeCurrent() < nextAttempt) return;
   nextAttempt = TimeCurrent() + 60;
   if(signalBar != bar)
   {
      if(!Signal(target)) return;
      signalBar = bar;
   }
   if(AlignPosition(target)) completedBar = bar;
}

FILES

every upload is kept
TypeFileNotesSizeDLSHA-256Uploaded
BACKTESTFX_HPTrend_GBPUSD_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $-4,103.34 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $-4,113.76 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.115.0 KB0799a24dac3a52026-11-29 08:14
BACKTESTFX_HPTrend_GBPUSD_2020-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2020-01-01 through 2026-10-31. MT5 booked $-2,073.51 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $-2,110.61 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.154.7 KB016e1598621932026-11-29 08:14
BACKTESTFX_HPTrend_AUDUSD_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $-2,833.54 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $-2,845.58 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.120.0 KB04c9ef351562b2026-11-29 08:14
BACKTESTFX_HPTrend_AUDUSD_2020-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2020-01-01 through 2026-10-31. MT5 booked $7,586.73 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $7,544.92 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.152.0 KB03a81e7fe29342026-11-29 08:14
BACKTESTFX_HPTrend_USDJPY_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $-4,131.32 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $-4,142.05 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.119.4 KB03a54323ca9032026-11-29 08:14
BACKTESTFX_HPTrend_USDJPY_2020-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2020-01-01 through 2026-10-31. MT5 booked $5,666.55 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $5,630.41 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.148.3 KB09a54cabaeb422026-11-29 08:14
BACKTESTFX_HPTrend_EURGBP_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $-2,504.73 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $-2,516.93 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.116.1 KB0532a0571573a2026-11-29 08:14
BACKTESTFX_HPTrend_EURGBP_2020-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2020-01-01 through 2026-10-31. MT5 booked $-14,164.49 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $-14,204.58 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.156.8 KB09b04b9fe26d12026-11-29 08:14
BACKTESTFX_HPTrend_GBPJPY_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $-7,365.72 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $-7,377.93 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.117.5 KB0f7492d270cb72026-11-29 08:14
BACKTESTFX_HPTrend_GBPJPY_2020-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2020-01-01 through 2026-10-31. MT5 booked $-9,824.24 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $-9,862.88 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.161.1 KB05faba783a9752026-11-29 08:14
BACKTESTFX_HPTrend_EURUSD_2020-01-01_to_2025-01-01_early.html latestFX_HPTrend on EURUSD, Jan 2020–Dec 2024. The original MT5 statement booked +$738.12 with zero exit commission. Repricing the same fills for the 0.0014% exit fee gives +$710.19. Daily host, MT5 real-tick mode. Includes native settings, results and every deal. Order-request rows are omitted.143.1 KB0c89ffd53b0972026-11-29 01:22
BACKTESTFX_HPTrend_EURUSD_2025-01-01_to_2026-11-01_holdout.html latestFX_HPTrend on EURUSD, Jan 2025–Oct 2026. The original MT5 statement booked +$3,294.89 with zero exit commission. Repricing the same fills for the 0.0014% exit fee gives +$3,284.88. Daily host, MT5 real-tick mode. Includes native settings, results and every deal. Order-request rows are omitted.116.0 KB08af8603dfa3d2026-11-29 01:22
BACKTESTFX_HPTrend_EURUSD_2020-01-01_to_2026-11-01_full.html latestFX_HPTrend on EURUSD, Jan 2020–Oct 2026. The original MT5 statement booked +$4,004.72 with zero exit commission. Repricing the same fills for the 0.0014% exit fee gives +$3,967.14. Daily host, MT5 real-tick mode. Includes native settings, results and every deal. Order-request rows are omitted.156.5 KB0e31e7a36fc3c2026-11-29 01:22
FILEhp-trend-test-windows.csv latestAll measured windows, separately reported by source, size, instrument, tick model and commission treatment. Native P&L and fixed-fill fee estimates have separate columns.6.1 KB0b76c575b0eed2026-11-29 01:22
PARAMSFX_HPTrend.set latestTest inputs from the matching source. The public preset uses tester mode and a neutral journal token where supported.66 B0cb862bfc1b5c2026-11-29 01:22
SOURCEFX_HPTrend.mq5 latestOriginal MQL5 source, matched to the frozen SHA-256.5.5 KB0fa9e5247c3392026-11-29 01:22

MORE FX STRATEGIES

all FX →