Gold and silver seven-signal blend at 0.10×
ResearchJan 2009–Oct 2026 MT5 results showed −$719.73 net and 4.16% maximum equity drawdown. The January 2025 restart earned $860.05.
BACKTESTS · 4
EQUITY · BALANCE (USD)
Metals_MultiSignal010 · XAUUSD H1 · quality 100% real ticks · drag to zoom, double-click to resetMONTHLY RETURNS
% of balance at month start| Year | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Year |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2025 | -0.0% | 0.0% | -0.0% | 0.0% | -0.1% | 0.1% | -0.1% | 0.0% | 0.1% | 0.5% | 0.0% | 0.3% | +0.9% |
TRADE STATS
| Gross profit | 1,259.92 | Gross loss | -399.87 |
| Expected payoff | 17.92 | Total deals | 96 |
| Long trades | 48 (56.3%) | Short trades | 0 (0.0%) |
| Largest win | 520.00 | Largest loss | -87.94 |
| Average win | 46.66 | Average loss | -19.04 |
| Max consec. wins | 9 | Max consec. losses | 5 |
| Balance DD max | 131.77 (0.1%) | Equity DD max | 332.03 (0.3%) |
| Leverage | 1:100 | Broker | Withheld |
All report fields (46)
| History Quality | 100% real ticks |
| Bars | 10995 |
| Ticks | 204690051 |
| Symbols | 2 |
| Total Net Profit | 860.05 |
| Balance Drawdown Absolute | 102.20 |
| Equity Drawdown Absolute | 141.87 |
| Gross Profit | 1 259.92 |
| Balance Drawdown Maximal | 131.77 (0.13%) |
| Equity Drawdown Maximal | 332.03 (0.33%) |
| Gross Loss | -399.87 |
| Balance Drawdown Relative | 0.13% (131.77) |
| Equity Drawdown Relative | 0.33% (332.03) |
| Profit Factor | 3.15 |
| Expected Payoff | 17.92 |
| Margin Level | 351468.44% |
| Recovery Factor | 2.59 |
| Sharpe Ratio | 3.28 |
| Z-Score | -0.33 (25.86%) |
| AHPR | 1.0002 (0.02%) |
| LR Correlation | 0.59 |
| OnTester result | 100860.05 |
| GHPR | 1.0002 (0.02%) |
| LR Standard Error | 233.82 |
| Total Trades | 48 |
| Short Trades (won %) | 0 (0.00%) |
| Long Trades (won %) | 48 (56.25%) |
| Total Deals | 96 |
| Profit Trades (% of total) | 27 (56.25%) |
| Loss Trades (% of total) | 21 (43.75%) |
| Largest profit trade | 520.00 |
| Largest loss trade | -87.94 |
| Average profit trade | 46.66 |
| Average loss trade | -19.04 |
| Maximum consecutive wins ($) | 9 (962.25) |
| Maximum consecutive losses ($) | 5 (-39.71) |
| Maximal consecutive profit (count) | 962.25 (9) |
| Maximal consecutive loss (count) | -131.77 (3) |
| Average consecutive wins | 2 |
| Average consecutive losses | 2 |
| Correlation (Profits,MFE) | 0.97 |
| Correlation (Profits,MAE) | -0.19 |
| Correlation (MFE,MAE) | -0.2314 |
| Minimal position holding time | 1:00:00 |
| Maximal position holding time | 528:00:00 |
| Average position holding time | 63:56:39 |
NOTES
Averages seven trading signals on gold and silver, with 10% of equity allocated across the seven votes. The votes use the gold early session and opening-range breakout, silver trend, 20-session relative strength, five-year relative value, and two opposing gold breakout rules. The opposing gold breakout votes cancel on the same inputs. The fresh 2025 test had too little prehistory for the five-year vote. A supplemental run carried cash from 2020 through 2024 to load the missing history.
Jan 2009–Oct 2026: −$719.73 net, −$3.36 per month, -0.003% compounded monthly, 4.16% maximum equity drawdown. Jan 2014–Oct 2026: −$1,972.91 net, −$12.81 per month, -0.013% compounded monthly, 3.74% maximum equity drawdown. Jan 2025–Oct 2026: +$860.05 net, +$39.09 per month, 0.039% compounded monthly, 0.33% maximum equity drawdown. Each MT5 window starts with USD 100,000. The later windows overlap the long history. The tester booked 0.0014% of closing notional, with swap and spread reflected in the net results. Tick coverage varies over time. Real gold and silver tick history begins in January 2019. The tester used generated prices during earlier periods and during later quote gaps, including gaps in gold during 2025. MT5 logged rejected trade requests (Jan 2009–Oct 2026: 881, Jan 2014–Oct 2026: 881, Jan 2025–Oct 2026: 117). These counts include retries. The matched five-year warm-up earned +$1,023.49 during the 22 active months at 0.046% compounded monthly with 0.33% maximum equity drawdown. MT5 recorded 115 market-closed rejections.
PARAMETERS
↓ Metals_MultiSignalWarmup010.set| Input | Value | Optimise (start / step / stop) | Section |
|---|---|---|---|
| TesterOnly | true | ||
| EquityLogId | 0 | ||
| Exposure | 0.1 |
View source
#property strict
#property description "Test-only broker precious-metal strategy"
const ulong LockedMagic=781019749;
const string LockedAnchor="XAUUSD";
string LegNames[]={"XAUUSD","XAGUSD"},MapNames[]={"XAUUSD","XAGUSD"},MapSymbols[]={"XAUUSD","XAGUSD"};
double LegWeights[]={1.0,1.0};
datetime MetalDay(const datetime t) { return (datetime)((long)t/86400*86400); }
int MetalSlot(const string sym) { return sym=="XAUUSD"?0:1; }
int MetalSign(const double v) { return v>0?1:(v<0?-1:0); }
double MetalTrend(const string sym,const datetime h,const int n,const bool longCash)
{
MqlRates r[]; const datetime end=MetalDay(h)-1;
int cnt=CopyRates(sym,PERIOD_D1,end,n,r);
if(cnt!=n) return 0;
double sum=0;
for(int i=0;i<n;i++) sum+=r[i].close;
int sign=MetalSign(r[n-1].close-sum/n);
return longCash?MathMax(0,sign):sign;
}
double MetalChannel(const string sym,const datetime h,const int n,const int back,const int fade)
{
MqlRates r[];int count=n+back;
if(CopyRates(sym,PERIOD_D1,MetalDay(h)-1,count,r)!=count) return 0;
for(int t=count-1;t>=n;t--)
{
double hi=r[t-n].high,lo=r[t-n].low;
for(int j=t-n+1;j<t;j++){hi=MathMax(hi,r[j].high);lo=MathMin(lo,r[j].low);}
if(r[t].close>hi) return 1-2*fade;
if(r[t].close<lo) return -(1-2*fade);
}
return 0;
}
double MetalOpenBreak(const string sym,const datetime h,const int begin,const int stop,const int flatten,const int fade)
{
MqlDateTime tm;TimeToStruct(h,tm);
if(tm.hour<=stop || tm.hour>=flatten) return 0;
MqlRates r[]; const datetime day=MetalDay(h);
int n=CopyRates(sym,PERIOD_H1,day,h-1,r);
double hi=0,lo=DBL_MAX;int seen=0,side=0;
for(int j=0;j<n;j++)
{
int k=(int)((r[j].time-day)/3600);
if(k>=begin && k<stop) {hi=MathMax(hi,r[j].high);lo=MathMin(lo,r[j].low);seen++;}
if(seen==stop-begin && k>=stop && k<flatten-1)
{
if(r[j].close>hi) side=1;
else if(r[j].close<lo) side=-1;
}
}
return side*(1-2*fade);
}
int MetalPairHistory(const datetime cutoff,const datetime from,datetime &dates[],double &gold[],double &silver[])
{
MqlRates a[],b[];
int na=CopyRates("XAUUSD",PERIOD_D1,from,cutoff-1,a);
int nb=CopyRates("XAGUSD",PERIOD_D1,from,cutoff-1,b);
if(na<=0 || nb<=0)return 0;
ArrayResize(dates,MathMin(na,nb));ArrayResize(gold,MathMin(na,nb));ArrayResize(silver,MathMin(na,nb));
int i=0,j=0,used=0;
while(i<na && j<nb)
{
datetime da=MetalDay(a[i].time),db=MetalDay(b[j].time);
if(da<db){i++;continue;}
if(db<da){j++;continue;}
dates[used]=da;gold[used]=a[i].close;silver[used]=b[j].close;i++;j++;used++;
}
return used;
}
double MetalRotation(const string sym,const datetime h,const int n,const int style)
{
datetime tt[];double a[],b[];datetime day=MetalDay(h);
int size=MetalPairHistory(day,day-(n*3+30)*86400,tt,a,b);
if(size<=n) return 0;
double x=a[size-1]/a[size-1-n]-1,y=b[size-1]/b[size-1-n]-1;
int dir=MetalSign(x-y);
if(style==0)return (sym=="XAUUSD"?0.5:-0.5)*dir;
if(sym=="XAUUSD" && dir>0 && (style!=2 || x>0)) return 1;
if(sym=="XAGUSD" && dir<0 && (style!=2 || y>0)) return 1;
return 0;
}
double MetalValue(const string sym,const datetime h,const int years)
{
MqlDateTime m;TimeToStruct(MetalDay(h),m);m.day=1;
datetime cut=StructToTime(m),tt[];double a[],b[];
int count=MetalPairHistory(cut,cut-(years*366+40)*86400,tt,a,b);
if(count<2)return 0;
MqlDateTime past;TimeToStruct(tt[count-1],past);past.year-=years;
if(past.mon==2 && past.day==29 && (past.year%4!=0 || (past.year%100==0 && past.year%400!=0)))past.day=28;
datetime limit=StructToTime(past);int i=count-1;
while(i>=0 && tt[i]>limit)i--;
if(i<0) return 0;
return (sym=="XAUUSD"?0.5:-0.5)*MetalSign(a[i]/a[count-1]-b[i]/b[count-1]);
}
double Member0(const string sym,const datetime hour)
{
if(sym!="XAUUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return (tm.hour>=1 && tm.hour<7) ? 1.0*1.0 : 0;
}
double Member1(const string sym,const datetime hour)
{
if(sym!="XAGUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return 1.0*MetalTrend(sym,hour,20,true);
}
double CachedMember1(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member1(sym,hour);dates[i]=key;} return values[i]; }
double Member2(const string sym,const datetime hour)
{
if(sym!="XAUUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return 1.0*MetalOpenBreak(sym,hour,1,8,15,0);
}
double Member3(const string sym,const datetime hour)
{
MqlDateTime tm; TimeToStruct(hour,tm);
return MetalRotation(sym,hour,20,2);
}
double CachedMember3(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member3(sym,hour);dates[i]=key;} return values[i]; }
double Member4(const string sym,const datetime hour)
{
if(sym!="XAUUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return 1.0*MetalChannel(sym,hour,60,5,0);
}
double CachedMember4(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member4(sym,hour);dates[i]=key;} return values[i]; }
double Member5(const string sym,const datetime hour)
{
if(sym!="XAUUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return 1.0*MetalChannel(sym,hour,60,5,1);
}
double CachedMember5(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member5(sym,hour);dates[i]=key;} return values[i]; }
double Member6(const string sym,const datetime hour)
{
MqlDateTime tm; TimeToStruct(hour,tm);
return MetalValue(sym,hour,5);
}
double CachedMember6(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member6(sym,hour);dates[i]=key;} return values[i]; }
bool SelectedWeight(const int slot,const string sym,const datetime hour,double &w)
{
if(hour < D'2025.01.01 00:00:00')
{
w=0.0;
return true;
}
w=(Member0(sym,hour)+CachedMember1(sym,hour)+Member2(sym,hour)+CachedMember3(sym,hour)+CachedMember4(sym,hour)+CachedMember5(sym,hour)+CachedMember6(sym,hour))/7.0;
return MathIsValidNumber(w);
}
// 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 EquityLogId = 0;
input double Exposure = 0.1;
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)
{
return canonical=="XAUUSD" || canonical=="XAGUSD";
}
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;
if(SymbolInfoString(dsSymbols[i],SYMBOL_CURRENCY_PROFIT)!="USD" || AccountInfoString(ACCOUNT_CURRENCY)!="USD") return INIT_PARAMETERS_INCORRECT;
total+=LegWeights[i];
}
if(total<=0 || _Symbol!=LockedAnchor) return INIT_PARAMETERS_INCORRECT;
if(MQLInfoInteger(MQL_TESTER) && EquityLogId>0)
{
const string fn="StrategyResearch\\monthly-"+IntegerToString((long)EquityLogId)+".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);
}
View source
#property strict
#property description "Test-only broker precious-metal strategy"
const ulong LockedMagic=781019749;
const string LockedAnchor="XAUUSD";
string LegNames[]={"XAUUSD","XAGUSD"},MapNames[]={"XAUUSD","XAGUSD"},MapSymbols[]={"XAUUSD","XAGUSD"};
double LegWeights[]={1.0,1.0};
datetime MetalDay(const datetime t) { return (datetime)((long)t/86400*86400); }
int MetalSlot(const string sym) { return sym=="XAUUSD"?0:1; }
int MetalSign(const double v) { return v>0?1:(v<0?-1:0); }
double MetalTrend(const string sym,const datetime h,const int n,const bool longCash)
{
MqlRates r[]; const datetime end=MetalDay(h)-1;
int cnt=CopyRates(sym,PERIOD_D1,end,n,r);
if(cnt!=n) return 0;
double sum=0;
for(int i=0;i<n;i++) sum+=r[i].close;
int sign=MetalSign(r[n-1].close-sum/n);
return longCash?MathMax(0,sign):sign;
}
double MetalChannel(const string sym,const datetime h,const int n,const int back,const int fade)
{
MqlRates r[];int count=n+back;
if(CopyRates(sym,PERIOD_D1,MetalDay(h)-1,count,r)!=count) return 0;
for(int t=count-1;t>=n;t--)
{
double hi=r[t-n].high,lo=r[t-n].low;
for(int j=t-n+1;j<t;j++){hi=MathMax(hi,r[j].high);lo=MathMin(lo,r[j].low);}
if(r[t].close>hi) return 1-2*fade;
if(r[t].close<lo) return -(1-2*fade);
}
return 0;
}
double MetalOpenBreak(const string sym,const datetime h,const int begin,const int stop,const int flatten,const int fade)
{
MqlDateTime tm;TimeToStruct(h,tm);
if(tm.hour<=stop || tm.hour>=flatten) return 0;
MqlRates r[]; const datetime day=MetalDay(h);
int n=CopyRates(sym,PERIOD_H1,day,h-1,r);
double hi=0,lo=DBL_MAX;int seen=0,side=0;
for(int j=0;j<n;j++)
{
int k=(int)((r[j].time-day)/3600);
if(k>=begin && k<stop) {hi=MathMax(hi,r[j].high);lo=MathMin(lo,r[j].low);seen++;}
if(seen==stop-begin && k>=stop && k<flatten-1)
{
if(r[j].close>hi) side=1;
else if(r[j].close<lo) side=-1;
}
}
return side*(1-2*fade);
}
int MetalPairHistory(const datetime cutoff,const datetime from,datetime &dates[],double &gold[],double &silver[])
{
MqlRates a[],b[];
int na=CopyRates("XAUUSD",PERIOD_D1,from,cutoff-1,a);
int nb=CopyRates("XAGUSD",PERIOD_D1,from,cutoff-1,b);
if(na<=0 || nb<=0)return 0;
ArrayResize(dates,MathMin(na,nb));ArrayResize(gold,MathMin(na,nb));ArrayResize(silver,MathMin(na,nb));
int i=0,j=0,used=0;
while(i<na && j<nb)
{
datetime da=MetalDay(a[i].time),db=MetalDay(b[j].time);
if(da<db){i++;continue;}
if(db<da){j++;continue;}
dates[used]=da;gold[used]=a[i].close;silver[used]=b[j].close;i++;j++;used++;
}
return used;
}
double MetalRotation(const string sym,const datetime h,const int n,const int style)
{
datetime tt[];double a[],b[];datetime day=MetalDay(h);
int size=MetalPairHistory(day,day-(n*3+30)*86400,tt,a,b);
if(size<=n) return 0;
double x=a[size-1]/a[size-1-n]-1,y=b[size-1]/b[size-1-n]-1;
int dir=MetalSign(x-y);
if(style==0)return (sym=="XAUUSD"?0.5:-0.5)*dir;
if(sym=="XAUUSD" && dir>0 && (style!=2 || x>0)) return 1;
if(sym=="XAGUSD" && dir<0 && (style!=2 || y>0)) return 1;
return 0;
}
double MetalValue(const string sym,const datetime h,const int years)
{
MqlDateTime m;TimeToStruct(MetalDay(h),m);m.day=1;
datetime cut=StructToTime(m),tt[];double a[],b[];
int count=MetalPairHistory(cut,cut-(years*366+40)*86400,tt,a,b);
if(count<2)return 0;
MqlDateTime past;TimeToStruct(tt[count-1],past);past.year-=years;
if(past.mon==2 && past.day==29 && (past.year%4!=0 || (past.year%100==0 && past.year%400!=0)))past.day=28;
datetime limit=StructToTime(past);int i=count-1;
while(i>=0 && tt[i]>limit)i--;
if(i<0) return 0;
return (sym=="XAUUSD"?0.5:-0.5)*MetalSign(a[i]/a[count-1]-b[i]/b[count-1]);
}
double Member0(const string sym,const datetime hour)
{
if(sym!="XAUUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return (tm.hour>=1 && tm.hour<7) ? 1.0*1.0 : 0;
}
double Member1(const string sym,const datetime hour)
{
if(sym!="XAGUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return 1.0*MetalTrend(sym,hour,20,true);
}
double CachedMember1(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member1(sym,hour);dates[i]=key;} return values[i]; }
double Member2(const string sym,const datetime hour)
{
if(sym!="XAUUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return 1.0*MetalOpenBreak(sym,hour,1,8,15,0);
}
double Member3(const string sym,const datetime hour)
{
MqlDateTime tm; TimeToStruct(hour,tm);
return MetalRotation(sym,hour,20,2);
}
double CachedMember3(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member3(sym,hour);dates[i]=key;} return values[i]; }
double Member4(const string sym,const datetime hour)
{
if(sym!="XAUUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return 1.0*MetalChannel(sym,hour,60,5,0);
}
double CachedMember4(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member4(sym,hour);dates[i]=key;} return values[i]; }
double Member5(const string sym,const datetime hour)
{
if(sym!="XAUUSD") return 0;
MqlDateTime tm; TimeToStruct(hour,tm);
return 1.0*MetalChannel(sym,hour,60,5,1);
}
double CachedMember5(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member5(sym,hour);dates[i]=key;} return values[i]; }
double Member6(const string sym,const datetime hour)
{
MqlDateTime tm; TimeToStruct(hour,tm);
return MetalValue(sym,hour,5);
}
double CachedMember6(const string sym,const datetime hour)
{ static datetime dates[2]; static double values[2]; int i=MetalSlot(sym); datetime key=MetalDay(hour); if(dates[i]!=key){values[i]=Member6(sym,hour);dates[i]=key;} return values[i]; }
bool SelectedWeight(const int slot,const string sym,const datetime hour,double &w)
{
w=(Member0(sym,hour)+CachedMember1(sym,hour)+Member2(sym,hour)+CachedMember3(sym,hour)+CachedMember4(sym,hour)+CachedMember5(sym,hour)+CachedMember6(sym,hour))/7.0;
return MathIsValidNumber(w);
}
// 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 EquityLogId = 0;
input double Exposure = 0.1;
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)
{
return canonical=="XAUUSD" || canonical=="XAGUSD";
}
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;
if(SymbolInfoString(dsSymbols[i],SYMBOL_CURRENCY_PROFIT)!="USD" || AccountInfoString(ACCOUNT_CURRENCY)!="USD") return INIT_PARAMETERS_INCORRECT;
total+=LegWeights[i];
}
if(total<=0 || _Symbol!=LockedAnchor) return INIT_PARAMETERS_INCORRECT;
if(MQLInfoInteger(MQL_TESTER) && EquityLogId>0)
{
const string fn="StrategyResearch\\monthly-"+IntegerToString((long)EquityLogId)+".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| Type | File | Notes | Size | DL | SHA-256 | Uploaded |
|---|---|---|---|---|---|---|
| FILE | Metals_MultiSignal010_monthly_equity.csv latest | Month-end marked equity by independent MT5 account. A partial month is identified by its observed broker timestamps. | 50.0 KB | 0 | b0740b47dc5c | 2026-11-29 01:23 |
| BACKTEST | Metals_MultiSignalWarmup010_warmup.html latest | The tester spent five years in cash before the 22-month trading period. Source includes this historical date guard. | 168.1 KB | 0 | 7cfa2bd7271b | 2026-11-29 01:23 |
| PARAMS | Metals_MultiSignalWarmup010.set latest | Supplemental warm-up MT5 Strategy Tester preset. Exposure 0.1×. | 94 B | 0 | d990751afe39 | 2026-11-29 01:23 |
| SOURCE | Metals_MultiSignalWarmup010.mq5 latest | Supplemental warm-up MQL5 source. Trade rules and sizing are preserved. The optional equity log uses a public identifier. | 15.1 KB | 0 | ac13c4562cf9 | 2026-11-29 01:23 |
| BACKTEST | Metals_MultiSignal010_holdfee.html latest | MT5 Strategy Tester, USD 100,000 initial capital. 48 closed trades. Native net P&L includes −$1.62 commission and −$110.65 swap. MT5 history quality: 100% real ticks. Rejected requests: 117. | 144.7 KB | 0 | 7431b4fc8430 | 2026-11-29 01:23 |
| BACKTEST | Metals_MultiSignal010_fullfee.html latest | MT5 Strategy Tester, USD 100,000 initial capital. 3,537 closed trades. Native net P&L includes −$76.31 commission and −$3,314.19 swap. MT5 history quality: 61% real ticks. Rejected requests: 881. | 3.3 MB | 0 | f84f7b2e9797 | 2026-11-29 01:23 |
| BACKTEST | Metals_MultiSignal010_continuousfee.html latest | MT5 Strategy Tester, USD 100,000 initial capital. 4,273 closed trades. Native net P&L includes −$86.66 commission and −$4,850.01 swap. MT5 history quality: 43% real ticks. Rejected requests: 881. | 3.9 MB | 0 | dad5e8064637 | 2026-11-29 01:23 |
| PARAMS | Metals_MultiSignal010.set latest | Strategy MT5 Strategy Tester preset. Exposure 0.1×. | 94 B | 0 | d990751afe39 | 2026-11-29 01:23 |
| SOURCE | Metals_MultiSignal010.mq5 latest | Strategy MQL5 source. Trade rules and sizing are preserved. The optional equity log uses a public identifier. | 15.0 KB | 0 | c6abe55104b4 | 2026-11-29 01:23 |