OPENSTRATS

USDJPY intraday momentum

Research

Follows a standardized USDJPY price move over 48 hourly observations during the specified broker-hour session. MT5 results with booked exit commission.

SYM USDJPYTF H1TEST 2014-01-01 → 2026-10-31UPDATED VIEWS 1DOWNLOADS 0#trend

BACKTESTS · 17

8 of 17
NET PROFIT · USD
+376,253
from 100,000 USD
RETURN
+376.3%
CAGR
+12.9%
12.8 yrs
PROFIT FACTOR
1.17
SHARPE
1.12
MAX DD
-29.5%
equity, relative
RECOVERY
5.78
TRADES
5926
37.6% win

EQUITY · BALANCE (USD)

FX_USDJPY_Trend660 · USDJPY H1 · quality 100% real ticks · drag to zoom, double-click to reset

MONTHLY RETURNS

% of balance at month start
YearJanFebMarAprMayJunJulAugSepOctNovDecYear
2014-11.7%-1.2%4.3%-0.1%-0.9%-1.9%5.9%-4.6%-4.0%6.6%1.5%9.6%+1.5%
2015-12.5%9.7%-6.9%-2.0%4.9%8.5%1.0%12.4%-1.8%-5.2%0.9%7.6%+14.4%
2016-7.2%11.8%-12.4%1.2%-6.7%3.9%3.4%-8.7%7.2%6.5%14.8%-13.2%-4.1%
20175.8%-0.8%7.5%0.1%-3.4%2.1%-2.9%-2.1%-5.8%-8.8%4.0%-5.3%-10.4%
20183.9%2.1%-5.5%4.5%-5.1%-1.4%7.5%5.5%1.8%1.3%2.5%-0.1%+17.4%
2019-8.5%4.9%2.7%-1.9%2.4%-7.8%5.9%3.3%2.2%2.8%1.0%0.0%+6.0%
20200.4%11.2%4.7%-6.3%-3.3%11.5%6.7%2.6%0.9%2.9%7.7%-2.3%+41.3%
2021-2.3%0.3%-6.2%2.5%3.9%-0.2%3.4%-8.2%-3.0%4.1%6.0%-3.4%-4.1%
20226.6%-1.1%1.6%5.0%14.3%11.3%-0.1%9.4%-8.0%5.0%0.9%-3.4%+47.3%
20230.9%5.4%-6.3%2.5%3.4%-6.0%-5.9%7.8%-2.3%3.7%-1.3%1.9%+2.5%
20245.7%-2.8%4.8%5.9%-1.3%2.4%-6.4%8.0%-6.7%11.8%0.7%2.9%+25.9%
2025-5.8%7.0%-0.5%5.0%-0.9%-5.1%10.0%-0.6%4.9%-0.5%0.7%2.6%+16.7%
20268.9%4.2%5.2%-4.5%-0.3%-4.1%16.9%2.6%7.9%-9.4%··+27.8%

TRADE STATS

Gross profit2,530,843.04Gross loss-2,154,590.17
Expected payoff63.49Total deals9971
Long trades3209 (39.5%)Short trades2717 (35.3%)
Largest win62,465.00Largest loss-21,893.89
Average win1,135.93Average loss-582.64
Max consec. wins18Max consec. losses23
Balance DD max58,746.82 (28.2%)Equity DD max65,052.79 (29.5%)
Leverage1:100Brokerafx Markets Ltd
All report fields (46)
History Quality100% real ticks
Bars79720
Ticks451667590
Symbols1
Total Net Profit376 252.87
Balance Drawdown Absolute16 113.28
Equity Drawdown Absolute17 648.42
Gross Profit2 530 843.04
Balance Drawdown Maximal58 746.82 (10.98%)
Equity Drawdown Maximal65 052.79 (12.06%)
Gross Loss-2 154 590.17
Balance Drawdown Relative28.22% (37 141.51)
Equity Drawdown Relative29.48% (39 135.61)
Profit Factor1.17
Expected Payoff63.49
Margin Level1261.97%
Recovery Factor5.78
Sharpe Ratio1.12
Z-Score-20.60 (99.74%)
AHPR1.0003 (0.03%)
LR Correlation0.91
OnTester result476252.8700000001
GHPR1.0003 (0.03%)
LR Standard Error42 342.15
Total Trades5926
Short Trades (won %)2717 (35.33%)
Long Trades (won %)3209 (39.51%)
Total Deals9971
Profit Trades (% of total)2228 (37.60%)
Loss Trades (% of total)3698 (62.40%)
Largest profit trade62 465.00
Largest loss trade-21 893.89
Average profit trade1 135.93
Average loss trade-582.64
Maximum consecutive wins ($)18 (34 441.71)
Maximum consecutive losses ($)23 (-3 811.93)
Maximal consecutive profit (count)63 509.91 (2)
Maximal consecutive loss (count)-40 668.72 (12)
Average consecutive wins2
Average consecutive losses4
Correlation (Profits,MFE)0.66
Correlation (Profits,MAE)0.50
Correlation (MFE,MAE)-0.1716
Minimal position holding time0:59:34
Maximal position holding time36:00:00
Average position holding time2:14:21

NOTES

Follows a standardized USDJPY price move over 48 hourly observations during the specified broker-hour session. The main source uses 4.00× exposure. The window ledger gives the evidence for each sizing variant.

USDJPY_Trend4, Jan 2014–Oct 2026. MT5 booked +$145,065.18 on $100,000, +0.584% compounded monthly, with 19.14% maximum relative equity drawdown.

USDJPY_Trend4, Jan 2025–Oct 2026. MT5 booked +$26,692.47 on $100,000, +1.081% compounded monthly, with 9.64% maximum relative equity drawdown.

The earlier 5.24× test lost money. The 8.00× version is represented by bar-model measurements.

InputValueOptimise (start / step / stop)Section
TesterOnlytrue
AuditToken0
Exposure4.0
FX_USDJPY_Trend4.mq5560 lines · 21.6 KB · 2026-11-29 ↓ download
View source
#property strict
#property version "1.00"
const ulong LockedMagic=2707737325319;
const string LockedAnchor="USDJPY";
string LegNames[]={"USDJPY"};
double LegWeights[]={1.0};
string DSUniverse[]={"AUDUSD","EURUSD","GBPUSD","NZDUSD","USDCAD","USDCHF","USDJPY"};
string MapNames[]={"EURUSD","GBPUSD","AUDUSD","NZDUSD","USDJPY","USDCHF","USDCAD","EURGBP","EURJPY","EURCHF","EURCAD","EURAUD","EURNZD","GBPJPY","GBPCHF","GBPCAD","GBPAUD","GBPNZD","AUDJPY","AUDCHF","AUDCAD","AUDNZD","NZDJPY","NZDCAD","CADJPY","CADCHF","CHFJPY"};
string MapSymbols[]={"EURUSD","GBPUSD","AUDUSD","NZDUSD","USDJPY","USDCHF","USDCAD","EURGBP","EURJPY","EURCHF","EURCAD","EURAUD","EURNZD","GBPJPY","GBPCHF","GBPCAD","GBPAUD","GBPNZD","AUDJPY","AUDCHF","AUDCAD","AUDNZD","NZDJPY","NZDCAD","CADJPY","CADCHF","CHFJPY"};
datetime MapFirstH1[]={1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388646000,1388646000,1388646000,1388610000,1388610000,1388610000,1388610000,1388610000,1388610000,1388646000,1388610000,1388610000};
datetime DSFirstH1(const string broker) { for(int j=0;j<ArraySize(MapSymbols);j++) if(MapSymbols[j]==broker) return MapFirstH1[j]; return 0; }
string DSBrokerSymbol(const string canonical);
// Native broker-time H1 rules. Called at a new H1 open; all referenced prices
// come from completed H1 bars except explicit opening quotes for entry presence.
#ifndef DEEP_INTRADAY_SIGNALS_MQH
#define DEEP_INTRADAY_SIGNALS_MQH

bool IRRead(const string sym,const datetime start,MqlRates &bar)
{
   MqlRates a[1];
   if(CopyRates(sym,PERIOD_H1,start,1,a)!=1 || a[0].time!=start) return false;
   bar=a[0];
   return bar.open>0;
}
bool IRHasOpen(const string sym,const datetime day,const int hour)
{
   MqlRates x;
   return IRRead(sym,day+3600*hour,x);
}
bool IRRange(const string sym,const datetime day,const int begin,const int end,
             double &hi,double &lo,double &move)
{
   MqlRates a[];
   const int n=CopyRates(sym,PERIOD_H1,day+3600*begin,day+3600*end-1,a);
   if(n!=end-begin || n<=0) return false;
   hi=a[0].high; lo=a[0].low;
   for(int i=0;i<n;i++)
   {
      if(a[i].time!=day+3600*(begin+i) || a[i].low<=0 || a[i].close<=0) return false;
      hi=MathMax(hi,a[i].high); lo=MathMin(lo,a[i].low);
   }
   move=a[n-1].close-a[0].open;
   return hi>lo;
}
int IRRegion(const string region,const string currency)
{
   string list=region=="asia" ? "|AUD|NZD|JPY|" : region=="europe" ? "|EUR|GBP|CHF|" : "|USD|CAD|";
   return StringFind(list,"|"+currency+"|")>=0 ? 1 : 0;
}
int IRSgn(const double a) {return a>0 ? 1 : a<0 ? -1 : 0;}

bool IRCalendar(const string &part[],const string sym,const datetime day,const int hour,int &side)
{
   const int n=ArraySize(part);
   const int enter=(int)StringToInteger(part[n-4]), end=(int)StringToInteger(part[n-3]);
   if(hour<enter || hour>=end || !IRHasOpen(sym,day,enter)) return true;
   MqlDateTime clock; TimeToStruct(day,clock);
   bool use=false;
   if(part[1]=="monday") use=clock.day_of_week==1;
   if(part[1]=="friday") use=clock.day_of_week==5;
   if(part[1]=="month" && clock.day_of_week>0 && clock.day_of_week<6)
   {
      int count=1;
      const int step=part[2]=="first2" ? -1 : 1;
      for(int i=1;i<=5;i++)
      {
         MqlDateTime d; TimeToStruct(day+step*i*86400,d);
         if(d.mon!=clock.mon) break;
         if(d.day_of_week>0 && d.day_of_week<6) count++;
         if(count>2) break;
      }
      use=count<=2;
   }
   if(use)
   {
      string base=SymbolInfoString(sym,SYMBOL_CURRENCY_BASE),quote=SymbolInfoString(sym,SYMBOL_CURRENCY_PROFIT);
      side=(base=="USD" ? 1 : quote=="USD" ? -1 : 0)*(part[n-1]=="up" ? 1 : -1);
   }
   return true;
}

bool IRHistory(const string sym,const datetime at,const int n,MqlRates &bars[])
{
   return CopyRates(sym,PERIOD_H1,(datetime)(at-1),n,bars)==n && bars[n-1].time<at;
}
double IRMedian(double &values[])
{
   ArraySort(values);
   const int n=ArraySize(values);
   return n%2==1 ? values[n/2] : 0.5*(values[n/2-1]+values[n/2]);
}
bool IRIsSqueeze(const string sym,const datetime day)
{
   double ranges[13];int n=0;
   // Sparse/reopened sessions need 12 observed hourly bars to qualify as one day.
   // Extend back to the start of available data if market closures are unusually long.
   const datetime earliest=(datetime)SeriesInfoInteger(sym,PERIOD_H1,SERIES_FIRSTDATE);
   if(earliest<=0) return false;
   for(datetime end=day-1; n<13 && end>=earliest; end-=86400)
   {
      MqlRates bars[];
      int count=CopyRates(sym,PERIOD_H1,end-86399,end,bars);
      if(count<12) continue;
      double hi=bars[0].high,lo=bars[0].low;
      for(int i=1;i<count;i++) {hi=MathMax(hi,bars[i].high);lo=MathMin(lo,bars[i].low);}
      ranges[n++]=hi-lo;
   }
   if(n<8) return false;
   double reference[];ArrayResize(reference,n-1);
   for(int i=1;i<n;i++) reference[i-1]=ranges[i];
   return ranges[0]<0.85*IRMedian(reference);
}
int IRSma(const string sym,const datetime at,const int fast,const int slow)
{
   MqlRates bars[];
   if(!IRHistory(sym,at,slow,bars)) return 0;
   double f=0,s=0;
   for(int i=0;i<slow;i++) {s+=bars[i].close;if(i>=slow-fast) f+=bars[i].close;}
   f/=fast;s/=slow;
   const double close=bars[slow-1].close;
   return f>s && close>f ? 1 : f<s && close<f ? -1 : 0;
}
int IRZ(const string sym,const datetime at,const int n,const double trigger)
{
   MqlRates bars[];
   if(!IRHistory(sym,at,n+1,bars)) return 0;
   double mean=0,ss=0;
   for(int i=0;i<n;i++) mean+=bars[i].close;
   mean/=n;
   for(int i=0;i<n;i++) ss+=MathPow(bars[i].close-mean,2);
   if(ss<=0) return 0;
   const double z=(bars[n].close-mean)/MathSqrt(ss/n);
   return z>=trigger ? 1 : z<=-trigger ? -1 : 0;
}
int IRShock(const string sym,const datetime at,const double threshold)
{
   MqlRates bars[];if(!IRHistory(sym,at,25,bars)) return 0;
   double widths[];ArrayResize(widths,24);
   for(int i=0;i<24;i++) widths[i]=bars[i].high-bars[i].low;
   double bench=IRMedian(widths),w=bars[24].high-bars[24].low;
   if(bench<=0 || w<=0 || w/bench<threshold) return 0;
   const double x=(bars[24].close-bars[24].low)/w;
   return x>=.8 ? 1 : x<=.2 ? -1 : 0;
}
int IRSeasonal(const string sym,const datetime day,const int enter,const int end,const int weeks)
{
   MqlDateTime now;TimeToStruct(day,now);
   if(now.day_of_week==0 || now.day_of_week==6) return 0;
   double sample[];ArrayResize(sample,weeks);int count=0;
   for(int w=1;w<=weeks;w++)
   {
      datetime past=day-(datetime)(w*7*86400);
      MqlRates a,b;
      if(IRRead(sym,past+3600*enter,a) && IRRead(sym,past+3600*end,b))
         sample[count++]=MathLog(b.open/a.open);
   }
   if(count<weeks-2) return 0;
   double mean=0,ss=0;
   for(int i=0;i<count;i++) mean+=sample[i];
   mean/=count;
   for(int i=0;i<count;i++) ss+=MathPow(sample[i]-mean,2);
   const double sd=MathSqrt(ss/count);
   return mean>.15*sd ? 1 : mean<-.15*sd ? -1 : 0;
}
int IRRelative(const string sym,const datetime day,const int begin,const int end,const double gap)
{
   string currencies[]={"EUR","GBP","JPY","CHF","AUD","NZD","CAD","USD"};
   string base=SymbolInfoString(sym,SYMBOL_CURRENCY_BASE),quote=SymbolInfoString(sym,SYMBOL_CURRENCY_PROFIT);
   int pos=StringFind(sym,base+quote);if(pos<0) return 0;
   string prefix=StringSubstr(sym,0,pos),suffix=StringSubstr(sym,pos+6);
   double value[8];bool valid[8];ArrayInitialize(valid,false);int n=1;
   valid[7]=true;value[7]=0;
   for(int i=0;i<7;i++)
   {
      string name=prefix+currencies[i]+"USD"+suffix;
      bool custom=false;int sign=1;
      if(!SymbolExist(name,custom)) {name=prefix+"USD"+currencies[i]+suffix;sign=-1;}
      if(!SymbolExist(name,custom) || !SymbolSelect(name,true)) continue;
      double hi,lo,move;MqlRates a,b;
      if(IRRange(name,day,begin,end,hi,lo,move) && IRRead(name,day+3600*begin,a) && IRRead(name,day+3600*(end-1),b))
      {
         valid[i]=true;value[i]=sign*MathLog(b.close/a.open);n++;
      }
   }
   if(n<5) return 0;
   double rankb=0,rankq=0;
   for(int i=0;i<8;i++)
   {
      if(!valid[i] || (currencies[i]!=base && currencies[i]!=quote)) continue;
      int below=0,equal=0;
      for(int j=0;j<8;j++) if(valid[j])
      {if(value[j]<value[i]) below++;else if(value[j]==value[i]) equal++;}
      const double rank=(below+0.5*(equal+1))/n;
      if(currencies[i]==base) rankb=rank;
      if(currencies[i]==quote) rankq=rank;
   }
   if(rankb==0 || rankq==0) return 0;
   double diff=rankb-rankq;
   return diff>=gap ? 1 : diff<=-gap ? -1 : 0;
}

bool H1Target(const string rule,const string sym,const datetime barOpen,int &side)
{
   side=0;
   string part[];
   const int n=StringSplit(rule,'_',part);
   if(n<2) return false;
   const datetime day=(datetime)(((long)barOpen/86400)*86400);
   const int hour=(int)((barOpen-day)/3600);
   if(!SeriesInfoInteger(sym,PERIOD_H1,SERIES_SYNCHRONIZED))
   {
      // Start history synchronization on a newly selected tester symbol.
      MqlRates warm[1]; if(CopyRates(sym,PERIOD_H1,0,1,warm)!=1) return false;
   }
   if(part[0]=="region" && n==6)
   {
      const int enter=(int)StringToInteger(part[2]), end=(int)StringToInteger(part[3]);
      if(hour>=enter && hour<end && IRHasOpen(sym,day,enter))
      {
         const int local=IRRegion(part[1],SymbolInfoString(sym,SYMBOL_CURRENCY_BASE))
                        -IRRegion(part[1],SymbolInfoString(sym,SYMBOL_CURRENCY_PROFIT));
         side=local*(part[4]=="sell" ? -1 : 1);
      }
      return true;
   }
   if(part[0]=="calendar" && (n==6 || n==7))
      return IRCalendar(part,sym,day,hour,side);
   if(part[0]=="impulse" && n==7)
   {
      const int enter=(int)StringToInteger(part[3]), end=(int)StringToInteger(part[4]);
      if(hour<enter || hour>=end || !IRHasOpen(sym,day,enter)) return true;
      double hi,lo,move;
      if(IRRange(sym,day,(int)StringToInteger(part[1]),(int)StringToInteger(part[2]),hi,lo,move) &&
         MathAbs(move)>=(hi-lo)*StringToDouble(part[5])/100.0)
         side=IRSgn(move)*(part[6]=="follow" ? 1 : -1);
      return true;
   }
   if(part[0]=="range" && n==7)
   {
      const int begin=(int)StringToInteger(part[1]), end=(int)StringToInteger(part[2]);
      const int last=(int)StringToInteger(part[3]);
      if(hour<=end || hour>=last) return true;
      double hi,lo,move;
      if(!IRRange(sym,day,begin,end,hi,lo,move)) return true;
      if(part[5]=="squeeze" && !IRIsSqueeze(sym,day)) return true;
      const double mid=(hi+lo)/2;
      for(int h=end+1;h<=hour;h++)
      {
         MqlRates b;
         if(!IRHasOpen(sym,day,h) || !IRRead(sym,day+3600*(h-1),b)) continue;
         int d=0;
         if(part[4]=="break") d=b.close>hi ? 1 : b.close<lo ? -1 : 0;
         else if(b.low<lo && b.close>lo && b.close<=mid && b.high<=hi) d=1;
         else if(b.high>hi && b.close<hi && b.close>=mid && b.low>=lo) d=-1;
         if(d!=0)
         {
            if(part[6]=="session" || hour<h+StringToInteger(part[6])) side=d;
            break;
         }
      }
      return true;
   }
   if(part[0]=="sma" && n==5)
   {
      int enter=(int)StringToInteger(part[3]), last=(int)StringToInteger(part[4]);
      if(hour>=enter && hour<last && IRHasOpen(sym,day,enter))
         side=IRSma(sym,day+3600*enter,(int)StringToInteger(part[1]),(int)StringToInteger(part[2]));
      return true;
   }
   if((part[0]=="z" || part[0]=="vol") && n==6)
   {
      bool z=part[0]=="z";
      int enter=(int)StringToInteger(part[z?3:2]), last=(int)StringToInteger(part[z?4:3]);
      int holding=z ? 3 : (int)StringToInteger(part[4]);
      if(hour<enter || hour>=last) return true;
      for(int h=enter;h<=hour;h++)
      {
         if(!IRHasOpen(sym,day,h)) continue;
         datetime at=day+3600*h;
         int event=z ? IRZ(sym,at,(int)StringToInteger(part[1]),StringToDouble(part[2])/10)
                     : IRShock(sym,at,StringToDouble(part[1])/100);
         if(event!=0)
         {
            if(hour<h+holding) side=event*(part[5]=="follow" ? 1 : -1);
            break;
         }
      }
      return true;
   }
   if(part[0]=="seasonal" && n==4)
   {
      int enter=(int)StringToInteger(part[2]), end=(int)StringToInteger(part[3]);
      if(hour>=enter && hour<end && IRHasOpen(sym,day,enter))
         side=IRSeasonal(sym,day,enter,end,(int)StringToInteger(part[1]));
      return true;
   }
   if(part[0]=="relative" && n==7)
   {
      int enter=(int)StringToInteger(part[3]), end=(int)StringToInteger(part[4]);
      if(hour>=enter && hour<end && IRHasOpen(sym,day,enter))
         side=IRRelative(sym,day,(int)StringToInteger(part[1]),(int)StringToInteger(part[2]),
                         StringToDouble(part[5])/100)*(part[6]=="follow" ? 1 : -1);
      return true;
   }
   return false;
}
#endif

double Component0[]={1.0};
bool SelectedWeight(const int leg,const string sym,const datetime hour,double &weight)
{
   weight=0;
   int side=0;
   if(Component0[leg]>0)
   {
      side=0;
      if(!H1Target("z_48_15_12_19_follow",sym,hour,side) || side< -1 || side>1) return false;
      weight+=side*Component0[leg];
   }
   return true;
}
// Shared MT5 execution for explicitly frozen, per-symbol H1-opening targets.
// The assembler declares LegNames, the maximum LegWeights, the
// broker symbol map, default exposure, and the SelectedWeight() callback.
#include <Trade/Trade.mqh>
input bool TesterOnly = true;
input ulong AuditToken = 0; // Unique tag for the tester's monthly equity file.
input double Exposure = 4.0;
CTrade dsTrade;
string dsSymbols[];
bool dsDone[],dsReady[];
int dsSides[];
double dsVolumes[];
datetime dsHour=0, dsWake=0;
double dsOpeningEquity=0;
bool dsFinished=false;
uint dsErrors=0;
int dsMonthlyFile=INVALID_HANDLE;
datetime dsMonthStart=0,dsNextMonth=0,dsLastTick=0,dsFirstMonthTick=0;
double dsLastMarkedEquity=0,dsLastMarkedBalance=0;

void DSWriteMonth(const bool finalRow,const double ending)
{
   if(dsMonthlyFile==INVALID_HANDLE || dsLastTick<=0) return;
   FileWrite(dsMonthlyFile,TimeToString(dsMonthStart,TIME_DATE),TimeToString(dsFirstMonthTick,TIME_DATE|TIME_SECONDS),
             TimeToString(dsLastTick,TIME_DATE|TIME_SECONDS),DoubleToString(dsLastMarkedEquity,2),
             DoubleToString(dsLastMarkedBalance,2),finalRow?DoubleToString(ending,2):"");
   FileFlush(dsMonthlyFile);
   PrintFormat("Research tester monthly equity %s %.2f",TimeToString(dsMonthStart,TIME_DATE),dsLastMarkedEquity);
}

void DSObserveMonth(const datetime now)
{
   if(dsMonthlyFile==INVALID_HANDLE) return;
   if(now>=dsNextMonth)
   {
      DSWriteMonth(false,0);
      MqlDateTime t;
      if(!TimeToStruct(now,t)) return;
      t.day=1; t.hour=0; t.min=0; t.sec=0;
      dsMonthStart=StructToTime(t); dsFirstMonthTick=now;
      if(t.mon==12) { t.year++; t.mon=1; } else t.mon++;
      dsNextMonth=StructToTime(t);
   }
   dsLastTick=now;
   dsLastMarkedEquity=AccountInfoDouble(ACCOUNT_EQUITY);
   dsLastMarkedBalance=AccountInfoDouble(ACCOUNT_BALANCE);
}

string DSBrokerSymbol(const string canonical)
{
   for(int i=0;i<ArraySize(MapNames);i++)
      if(MapNames[i]==canonical) return MapSymbols[i];
   return "";
}

bool DSAllowed(const string canonical)
{
   if(canonical=="BTCUSD" || canonical=="SOLUSD" || canonical=="ETHUSD") return true;
   if(StringLen(canonical)!=6) return false;
   const string base=StringSubstr(canonical,0,3), quote=StringSubstr(canonical,3);
   const string fx="|USD|EUR|GBP|JPY|CHF|CAD|AUD|NZD|";
   return base!=quote && StringFind(fx,"|"+base+"|")>=0 && StringFind(fx,"|"+quote+"|")>=0;
}

bool DSSized(const string sym,const int side,const MqlTick &tick,const double allocation,double &lots)
{
   lots=0;
   if(side==0) return true;
   const double price=(tick.bid+tick.ask)/2;
   const double contract=SymbolInfoDouble(sym,SYMBOL_TRADE_CONTRACT_SIZE);
   const double step=SymbolInfoDouble(sym,SYMBOL_VOLUME_STEP);
   if(price<=0 || contract<=0 || step<=0 || dsOpeningEquity<=0) return false;
   const string account=AccountInfoString(ACCOUNT_CURRENCY);
   const string base=SymbolInfoString(sym,SYMBOL_CURRENCY_BASE);
   const string quote=SymbolInfoString(sym,SYMBOL_CURRENCY_PROFIT);
   double notional=contract;
   if(base!=account)
   {
      if(quote==account) notional=contract*price;
      else
      {
         double move=0;
         if(!OrderCalcProfit(ORDER_TYPE_BUY,sym,1.0,price,price*1.01,move) || move<=0) return false;
         notional=move*100;
      }
   }
   double raw=dsOpeningEquity*Exposure*allocation/notional;
   const double bound=SymbolInfoDouble(sym,SYMBOL_VOLUME_LIMIT);
   if(bound>0) raw=MathMin(raw,bound);
   lots=NormalizeDouble(MathFloor(raw/step+1e-10)*step,8);
   if(lots<SymbolInfoDouble(sym,SYMBOL_VOLUME_MIN)) lots=0;
   return true;
}

bool DSFilled(const bool sent,const string symbol)
{
   const uint rc=dsTrade.ResultRetcode();
   if(sent && (rc==TRADE_RETCODE_DONE || rc==TRADE_RETCODE_DONE_PARTIAL)) return true;
   dsErrors++;
   if(dsErrors<=8 || dsErrors%500==0)
      PrintFormat("Research execution %s: %u %s (events %u)",symbol,rc,dsTrade.ResultRetcodeDescription(),dsErrors);
   return false;
}

bool DSAlign(const string sym,int side,const double lots)
{
   // Return true only after actual position volume has been confirmed.
   if(lots==0) side=0;
   const bool hedge=AccountInfoInteger(ACCOUNT_MARGIN_MODE)==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING;
   double owned=0;
   ulong reduceTicket=0;
   double reduceLots=0;
   if(!dsTrade.SetTypeFillingBySymbol(sym)) return false;
   for(int i=PositionsTotal()-1;i>=0;i--)
   {
      const ulong ticket=PositionGetTicket(i);
      if(ticket==0 || PositionGetString(POSITION_SYMBOL)!=sym) continue;
      if((ulong)PositionGetInteger(POSITION_MAGIC)!=LockedMagic)
      {
         if(!hedge) return true; // Shared net position cannot be attributed safely.
         continue;
      }
      const int held=PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY?1:-1;
      const double v=PositionGetDouble(POSITION_VOLUME);
      if(held!=side)
      {
         DSFilled(dsTrade.PositionClose(ticket),sym);
         return false;
      }
      owned+=v;
      if(v>reduceLots) { reduceTicket=ticket; reduceLots=v; }
   }
   const double step=SymbolInfoDouble(sym,SYMBOL_VOLUME_STEP);
   const double maximum=SymbolInfoDouble(sym,SYMBOL_VOLUME_MAX);
   const double minimum=SymbolInfoDouble(sym,SYMBOL_VOLUME_MIN);
   if(step<=0 || maximum<=0 || minimum<=0) return false;
   const double diff=NormalizeDouble(lots-owned,8);
   if(MathAbs(diff)<minimum-step*0.01) return true;
   double qty=MathMin(MathAbs(diff),maximum);
   qty=NormalizeDouble(MathFloor(qty/step+1e-8)*step,8);
   if(qty<minimum) return true;
   if(hedge && diff<0)
   {
      if(qty>=reduceLots-step*0.01)
         DSFilled(dsTrade.PositionClose(reduceTicket),sym);
      else
         DSFilled(dsTrade.PositionClosePartial(reduceTicket,qty),sym);
      return false;
   }
   const bool buy=(side>0)==(diff>0);
   DSFilled(buy?dsTrade.Buy(qty,sym):dsTrade.Sell(qty,sym),sym);
   return false;
}

int OnInit()
{
   if((TesterOnly && !MQLInfoInteger(MQL_TESTER)) || Exposure<=0 || !MathIsValidNumber(Exposure)) return INIT_PARAMETERS_INCORRECT;
   const int n=ArraySize(LegNames);
   if(n==0 || n!=ArraySize(LegWeights) || ArraySize(MapNames)!=ArraySize(MapSymbols)) return INIT_PARAMETERS_INCORRECT;
   ArrayResize(dsSymbols,n); ArrayResize(dsDone,n); ArrayResize(dsReady,n);
   ArrayResize(dsSides,n); ArrayResize(dsVolumes,n);
   double total=0;
   for(int i=0;i<n;i++)
   {
      dsSymbols[i]=DSBrokerSymbol(LegNames[i]);
      if(!DSAllowed(LegNames[i]) || dsSymbols[i]=="" || LegWeights[i]<=0 || !SymbolSelect(dsSymbols[i],true)) return INIT_PARAMETERS_INCORRECT;
      total+=LegWeights[i];
   }
   if(total<=0 || _Symbol!=LockedAnchor) return INIT_PARAMETERS_INCORRECT;
   if(MQLInfoInteger(MQL_TESTER) && AuditToken>0)
   {
      const string fn="AFXResearch\\monthly-"+IntegerToString((long)AuditToken)+".csv";
      dsMonthlyFile=FileOpen(fn,FILE_WRITE|FILE_CSV|FILE_ANSI|FILE_COMMON,',');
      if(dsMonthlyFile==INVALID_HANDLE) { PrintFormat("Research tester monthly file error %d",GetLastError()); return INIT_FAILED; }
      FileWrite(dsMonthlyFile,"month","first_tick","last_tick","marked_equity","marked_balance","final_tester_equity");
   }
   dsTrade.SetExpertMagicNumber(LockedMagic);
   dsTrade.SetAsyncMode(false);
   return INIT_SUCCEEDED;
}

void OnTick()
{
   const datetime now=TimeCurrent();
   DSObserveMonth(now);
   const datetime hour=(datetime)(((long)now/3600)*3600);
   if(hour!=dsHour)
   {
      dsHour=hour;
      dsWake=0;
      dsFinished=false;
      dsOpeningEquity=AccountInfoDouble(ACCOUNT_EQUITY);
      ArrayInitialize(dsDone,false);
      ArrayInitialize(dsReady,false);
   }
   if(dsFinished || now<dsWake) return;
   bool all=true;
   for(int i=0;i<ArraySize(dsSymbols);i++)
   {
      if(dsDone[i]) continue;
      MqlTick tick;
      const string sym=dsSymbols[i];
      if(!SymbolInfoTick(sym,tick) || tick.time<hour || tick.time>now || tick.bid<=0 ||
         tick.ask<tick.bid || iTime(sym,PERIOD_H1,0)!=hour) { all=false; continue; }
      if(!dsReady[i])
      {
         double weight=0;
         if(!SelectedWeight(i,sym,hour,weight) || !MathIsValidNumber(weight) ||
            MathAbs(weight)>LegWeights[i]+1e-8) { all=false; continue; }
         const int side=weight>0?1:(weight<0?-1:0);
         if(!DSSized(sym,side,tick,MathAbs(weight),dsVolumes[i])) { all=false; continue; }
         dsSides[i]=side;
         dsReady[i]=true;
      }
      dsDone[i]=DSAlign(sym,dsSides[i],dsVolumes[i]);
      if(!dsDone[i]) all=false;
   }
   if(dsMonthlyFile!=INVALID_HANDLE)
   {
      dsLastMarkedEquity=AccountInfoDouble(ACCOUNT_EQUITY);
      dsLastMarkedBalance=AccountInfoDouble(ACCOUNT_BALANCE);
   }
   dsFinished=all;
   dsWake=now+(now-hour<30?1:30);
}

double OnTester()
{
   const double ending=TesterStatistics(STAT_INITIAL_DEPOSIT)+TesterStatistics(STAT_PROFIT);
   DSWriteMonth(true,ending);
   return ending;
}

void OnDeinit(const int reason)
{
   if(dsMonthlyFile!=INVALID_HANDLE) FileClose(dsMonthlyFile);
   PrintFormat("Research execution ended, trade error responses=%u.",dsErrors);
}

FILES

every upload is kept
TypeFileNotesSizeDLSHA-256Uploaded
FILEMT5_monthly_marked_equity.csv latestNative MT5 calendar-month equity and balance across available runs. Equity includes floating P&L. Source, symbol, date and test-window keys distinguish multiple presets and independent cash accounts.256.8 KB0ab45a1c84b062026-11-29 08:14
BACKTESTFX_USDJPY_Trend660_USDJPY_2014-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2014-01-01 through 2026-10-31. MT5 booked $376,252.87 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $338,900.63 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.2.0 MB06978520d1e232026-11-29 08:14
BACKTESTFX_USDJPY_Trend524_USDJPY_2026-11-01_2026-11-25_november_MT5.html latestreal-tick mode. 2026-11-01 through 2026-11-24. MT5 booked $1,989.97 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $1,930.29 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.101.5 KB046e6fabdb0622026-11-29 08:14
BACKTESTFX_USDJPY_Trend524_USDJPY_2014-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2014-01-01 through 2026-10-31. MT5 booked $262,328.39 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $236,180.36 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.2.0 MB0b48e2688bd172026-11-29 08:14
BACKTESTFX_USDJPY_Trend524_USDJPY_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $38,175.30 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $35,635.81 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.371.1 KB0bb39c7755c222026-11-29 08:14
BACKTESTFX_USDJPY_Trend650_USDJPY_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $48,316.61 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $45,048.92 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.380.4 KB0e4fa04cbfe582026-11-29 08:14
BACKTESTFX_USDJPY_Trend650_USDJPY_2014-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2014-01-01 through 2026-10-31. MT5 booked $364,266.56 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $327,998.69 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.2.0 MB0280b5ca22fc02026-11-29 08:14
BACKTESTFX_USDJPY_Trend700_USDJPY_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $52,238.26 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $48,671.54 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.380.9 KB04a46caf7f77a2026-11-29 08:14
BACKTESTFX_USDJPY_Trend700_USDJPY_2014-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2014-01-01 through 2026-10-31. MT5 booked $405,852.98 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $365,759.70 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.2.0 MB0f7f8fc1f89042026-11-29 08:14
BACKTESTFX_USDJPY_Trend2_USDJPY_2014-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2014-01-01 through 2026-10-31. MT5 booked $75,668.46 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $68,197.85 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.1.4 MB0a2da56cd699d2026-11-29 08:14
BACKTESTFX_USDJPY_Trend2_USDJPY_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $13,341.20 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $12,465.07 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.291.8 KB008f909eee6112026-11-29 08:13
BACKTESTFX_USDJPY_Trend4_USDJPY_2014-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2014-01-01 through 2026-10-31. MT5 booked $174,841.88 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $157,180.35 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.1.9 MB0857377fad44f2026-11-29 08:13
BACKTESTFX_USDJPY_Trend4_USDJPY_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $28,690.00 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $26,821.00 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.358.0 KB0bf1207daf7492026-11-29 08:13
BACKTESTFX_USDJPY_Trend6_USDJPY_2014-01-01_2026-11-01_full_MT5.html latestreal-tick mode. 2014-01-01 through 2026-10-31. MT5 booked $310,526.65 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $279,247.23 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.2.0 MB0081dcc96283f2026-11-29 08:13
BACKTESTFX_USDJPY_Trend6_USDJPY_2025-01-01_2026-11-01_holdout_MT5.html latestreal-tick mode. 2025-01-01 through 2026-10-31. MT5 booked $44,309.78 with zero commission. The fixed-fill replay of the 0.0014% exit fee estimates $41,336.22 net without resizing. Every deal and 4 original chart images are included. Orders table omitted to reduce file size.378.2 KB0adff19fc15302026-11-29 08:13
FILEusdjpy-session-momentum-exit-commission-replay.csv latestSeparate H1 replays with the 0.0014% exit commission on net position reductions, estimated spread and slippage, and either zero financing or a 3% annual financing stress. Each window starts from $100,000. Daily historical broker swap rates are unavailable.2.8 KB00cc5ab5e8e2c2026-11-29 01:24
BACKTESTFX_USDJPY_Trend524_USDJPY_2008-01-01_to_2014-01-01_earlier.html latestFX_USDJPY_Trend524 on USDJPY, Jan 2008–Dec 2013. The original MT5 statement booked −$38,701.96 with zero exit commission. Repricing the same fills for the 0.0014% exit fee gives −$42,999.43. H1 host, MT5 real-tick mode. Includes native settings, results and every deal. Order-request rows are omitted.939.1 KB0f33f27342a3a2026-11-29 01:22
BACKTESTFX_USDJPY_Trend4_USDJPY_2025-01-01_to_2026-11-01_holdfee.html latestFX_USDJPY_Trend4 on USDJPY, Jan 2025–Oct 2026. MT5 booked +$26,692.47 including its 0.0014% exit commission. H1 host, MT5 real-tick mode. Includes native settings, results and every deal. Order-request rows are omitted.361.2 KB0def10416ea442026-11-29 01:22
BACKTESTFX_USDJPY_Trend4_USDJPY_2014-01-01_to_2026-11-01_fullfee.html latestFX_USDJPY_Trend4 on USDJPY, Jan 2014–Oct 2026. MT5 booked +$145,065.18 including its 0.0014% exit commission. H1 host, MT5 real-tick mode. Includes native settings, results and every deal. Order-request rows are omitted.1.9 MB09706879356da2026-11-29 01:22
FILEusdjpy-session-momentum-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.15.0 KB049216fb813892026-11-29 01:22
FILEusdjpy-session-momentum-additional-implementations.zip latestAdditional original MQL5 source files and corresponding tester presets for FX_USDJPY_Trend2, FX_USDJPY_Trend524, FX_USDJPY_Trend6, FX_USDJPY_Trend650, FX_USDJPY_Trend660, FX_USDJPY_Trend700, FX_USDJPY_Trend800. Each variant’s evidence basis appears in the window CSV.47.9 KB0ef75c48f0b6a2026-11-29 01:22
PARAMSFX_USDJPY_Trend4.set latestTest inputs from the matching source. The public preset uses tester mode and a neutral journal token where supported.92 B05a597b9ffe0e2026-11-29 01:22
SOURCEFX_USDJPY_Trend4.mq5 latestOriginal MQL5 source, matched to the frozen SHA-256.21.6 KB0f393e5e7a6462026-11-29 01:22

MORE FX STRATEGIES

all FX →