S&P 500 weekly volatility target 0.30×
ResearchLong test −$17,435.96 net, 23.88% maximum equity drawdown. Shorter test $664.23 net, 4.95% maximum equity drawdown.
BACKTESTS · 2
EQUITY · BALANCE (USD)
IDX_SP500_Vol030 · SP500 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.8% | -2.0% | 0.0% | 0.0% | 0.0% | · | 1.3% | 0.1% | -0.1% | 0.1% | -1.4% |
| 2026 | 0.0% | 0.4% | 0.0% | 0.1% | 0.1% | 0.3% | -0.0% | 0.0% | 0.0% | 1.3% | · | · | +2.1% |
TRADE STATS
| Gross profit | 4,479.94 | Gross loss | -3,815.71 |
| Expected payoff | 1.63 | Total deals | 589 |
| Long trades | 407 (67.3%) | Short trades | 0 (0.0%) |
| Largest win | 595.06 | Largest loss | -720.55 |
| Average win | 16.35 | Average loss | -28.69 |
| Max consec. wins | 109 | Max consec. losses | 32 |
| Balance DD max | 2,830.60 (2.8%) | Equity DD max | 4,980.75 (5.0%) |
| Leverage | 1:100 | Broker | afx Markets Ltd |
All report fields (46)
| History Quality | 100% real ticks |
| Bars | 9885 |
| Ticks | 86684036 |
| Symbols | 1 |
| Total Net Profit | 664.23 |
| Balance Drawdown Absolute | 2 830.60 |
| Equity Drawdown Absolute | 4 461.07 |
| Gross Profit | 4 479.94 |
| Balance Drawdown Maximal | 2 830.60 (2.83%) |
| Equity Drawdown Maximal | 4 980.75 (4.95%) |
| Gross Loss | -3 815.71 |
| Balance Drawdown Relative | 2.83% (2 830.60) |
| Equity Drawdown Relative | 4.95% (4 980.75) |
| Profit Factor | 1.17 |
| Expected Payoff | 1.63 |
| Margin Level | 33905.25% |
| Recovery Factor | 0.13 |
| Sharpe Ratio | 0.11 |
| Z-Score | -13.04 (99.74%) |
| AHPR | 1.0000 (0.00%) |
| LR Correlation | 0.60 |
| OnTester result | 100664.23 |
| GHPR | 1.0000 (0.00%) |
| LR Standard Error | 642.20 |
| Total Trades | 407 |
| Short Trades (won %) | 0 (0.00%) |
| Long Trades (won %) | 407 (67.32%) |
| Total Deals | 589 |
| Profit Trades (% of total) | 274 (67.32%) |
| Loss Trades (% of total) | 133 (32.68%) |
| Largest profit trade | 595.06 |
| Largest loss trade | -720.55 |
| Average profit trade | 16.35 |
| Average loss trade | -28.69 |
| Maximum consecutive wins ($) | 109 (1 557.47) |
| Maximum consecutive losses ($) | 32 (-221.62) |
| Maximal consecutive profit (count) | 1 557.47 (109) |
| Maximal consecutive loss (count) | -2 437.98 (20) |
| Average consecutive wins | 9 |
| Average consecutive losses | 4 |
| Correlation (Profits,MFE) | 0.46 |
| Correlation (Profits,MAE) | 0.58 |
| Correlation (MFE,MAE) | -0.3600 |
| Minimal position holding time | 20:59:29 |
| Maximal position holding time | 11444:28:30 |
| Average position holding time | 4981:27:54 |
NOTES
This weekly index-versus-cash allocation implements the volatility rule in section 6.5 of Kakushadze and Serur’s 151 Trading Strategies. Use the standard deviation of 21 daily log returns ending before the new period. The long weight is the lesser of one and 10% divided by annualized realized volatility, multiplied by the exposure in the preset.
Compile the supplied source and use MT5 Strategy Tester on SP500 H1. Each test starts with USD 100,000, uses 1:100 account leverage, real-tick mode and a fixed 100 ms execution delay. The EA resizes on a new broker date or a change of target. Net results include the broker’s spread, booked swaps and closing commissions under its 0.0014% exit schedule. The source is tester-only.
The 2025 history stops in July and resumes in September. August has no broker H1 quotes. Whole-period cash and reported maximum equity drawdown describe the simulated path. Intraperiod losses through the outage are unobserved. A whole-span compounded monthly return cannot be verified.
The long test lost money. Early broker history includes intermittent daily prints in the H1 series. The January 2025 reset overlaps the long test and begins with fresh capital.
| Requested period, inclusive | Net USD | Max equity DD | Trades | Eligible months | Swaps USD | Exit fees USD | Rejections |
|---|---|---|---|---|---|---|---|
| 2012-09-01 to 2026-10-31 | −$17,435.96 | 23.88% | 3,125 | 163/170 | −$47,518.91 | $6.04 | 66,701 |
| 2025-01-01 to 2026-10-31 | $664.23 | 4.95% | 407 | 19/22 | −$3,108.59 | $1.52 | 10,511 |
The monthly CSV reports native month-end equity and leaves missing months blank. Eligible monthly changes are based on equity including open positions. The website’s deal-balance chart uses realized balances. All maximum drawdowns above are the tester’s relative equity drawdowns.
PARAMETERS
↓ IDX_SP500_Vol030.set| Input | Value | Optimise (start / step / stop) | Section |
|---|---|---|---|
| TesterOnly | true | ||
| AuditToken | 0 | ||
| Exposure | 0.30 |
View source
#property strict
#property version "1.00"
#define DEFAULT_EXPOSURE 0.30
const string LockedAnchor="SP500";
const ulong LockedMagic=2230563485;
const bool MonthlyRebalance=false;
string LegNames[]={"SP500"};
string MapNames[]={"SP500"};
string MapSymbols[]={"SP500"};
double LegWeights[]={1.0};
datetime ixSizedDate[];
double ixSizedWeight[],ixPendingWeight[];
// Index-versus-cash volatility allocation from Kakushadze & Serur, section 6.5.
// The locked broker symbols are populated by assemble.py. Every source refuses non-tester use.
datetime ixPeriod(const datetime hour)
{
MqlDateTime t;
TimeToStruct(hour,t);
t.hour=0; t.min=0; t.sec=0;
if(MonthlyRebalance) { t.day=1; return StructToTime(t); }
return StructToTime(t)-(datetime)(((t.day_of_week+6)%7)*86400);
}
bool ixComponent(const string sym,const datetime cut,const int lookback,double &result,bool &eligible)
{
result=0; eligible=false;
// A cutoff identifies the first midnight in the new week/month. Only earlier D1 bars qualify.
MqlRates r[];
const int warm=ArraySize(LegNames)>1?64:lookback+1;
const int got=CopyRates(sym,PERIOD_D1,cut-1,warm,r);
if(got<0 || !SeriesInfoInteger(sym,PERIOD_D1,SERIES_SYNCHRONIZED)) return false;
if(got<warm) return true;
if(r[got-1].time>=cut || r[got-1].close<=0) return false;
if(ArraySize(LegNames)>1 && (cut-r[got-1].time)>7*86400) return true;
double sum=0, sum2=0;
for(int a=got-lookback;a<got;a++)
{
if(r[a].close<=0 || r[a-1].close<=0) return false;
const double x=MathLog(r[a].close/r[a-1].close);
sum+=x; sum2+=x*x;
}
const double variance=(sum2-sum*sum/lookback)/(lookback-1);
if(variance<=0) return true;
result=MathMin(1.0,0.10/MathSqrt(252.0*variance)); eligible=true;
return true;
}
bool SelectedWeight(const int id,const string sym,const datetime hour,double &weight)
{
static datetime cached=0;
static double weights[];
const datetime cut=ixPeriod(hour);
if(cut!=cached)
{
const int n=ArraySize(LegNames);
ArrayResize(weights,n);
int eligible=0;
for(int j=0;j<n;j++)
{
bool use=false;
if(!ixComponent(LegNames[j],cut,21,weights[j],use)) return false;
if(use) eligible++;
}
if(n>1)
{
for(int j=0;j<n;j++) weights[j]=eligible>=2?weights[j]/eligible:0;
}
cached=cut;
}
weight=weights[id];
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;
input double Exposure = DEFAULT_EXPOSURE;
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)
{
for(int i=0;i<ArraySize(LegNames);i++) if(canonical==LegNames[i]) return true;
return false;
}
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 int digits=(int)SymbolInfoInteger(sym,SYMBOL_DIGITS);
const double ref=NormalizeDouble(price*1.01,digits);
double movement=0, margin=0;
const ENUM_ORDER_TYPE sideType=side>0?ORDER_TYPE_BUY:ORDER_TYPE_SELL;
if(ref<=price || !OrderCalcProfit(ORDER_TYPE_BUY,sym,1.0,price,ref,movement) || movement<=0 ||
!OrderCalcMargin(sideType,sym,1.0,price,margin) || margin<=0)
{
static int failures=0;
failures++;
if(failures<=3 || failures%10000==0) PrintFormat("Index USD sensitivity or margin unavailable %s events=%d",sym,failures);
return false;
}
const double notional=movement*price/(ref-price);
// Reserve at least 20% of account equity even if the contract margin rate changes.
double raw=MathMin(dsOpeningEquity*Exposure*allocation/notional,0.80*dsOpeningEquity*allocation/margin);
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(!MQLInfoInteger(MQL_TESTER) || !TesterOnly || AccountInfoString(ACCOUNT_CURRENCY)!="USD") return INIT_FAILED;
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(ixSizedDate,n); ArrayResize(ixSizedWeight,n); ArrayResize(ixPendingWeight,n);
ArrayInitialize(ixSizedDate,0); ArrayInitialize(ixSizedWeight,0);
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);
// Research weights rebalance at first executable bar per broker date or weight change.
const datetime today=hour-hour%86400;
if(ixSizedDate[i]==today && MathAbs(weight-ixSizedWeight[i])<1.e-9)
{ dsDone[i]=true; continue; }
if(!DSSized(sym,side,tick,MathAbs(weight),dsVolumes[i])) { all=false; continue; }
ixPendingWeight[i]=weight;
dsSides[i]=side;
dsReady[i]=true;
}
dsDone[i]=DSAlign(sym,dsSides[i],dsVolumes[i]);
if(dsDone[i]) { ixSizedDate[i]=hour-hour%86400; ixSizedWeight[i]=ixPendingWeight[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 | IDX_SP500_Vol030_monthly_equity.csv latest | Native intratest USD equity marks by requested calendar month. Empty cells indicate missing observations or an ineligible monthly change. The platform’s deal-balance charts use a different series. | 17.7 KB | 0 | 8e1006e97c17 | 2026-11-29 01:21 |
| BACKTEST | IDX_SP500_Vol030_2025-01-01_to_2026-10-31.html latest | MT5 real-tick mode. 19 eligible months of 22 requested. Financing −$3,108.59. Closing fees $1.52. | 385.5 KB | 0 | b717a42e34ec | 2026-11-29 01:21 |
| BACKTEST | IDX_SP500_Vol030_2012-09-01_to_2026-10-31.html latest | MT5 real-tick mode. 163 eligible months of 170 requested. Financing −$47,518.91. Closing fees $6.04. | 2.2 MB | 0 | 7371bedb7d04 | 2026-11-29 01:21 |
| PARAMS | IDX_SP500_Vol030.set latest | Tested economic inputs. The internal monthly recording identifier has been reset to zero. | 94 B | 0 | 631283e4551a | 2026-11-29 01:21 |
| SOURCE | IDX_SP500_Vol030.mq5 latest | Original compiled-and-tested MQL5 source. The EA requires MT5 Strategy Tester and a USD account. | 11.9 KB | 0 | 70afffa5c868 | 2026-11-29 01:21 |
Other sizes of this rule
This page is the 0.30× exposure. The main research page is the 1.00× baseline: S&P 500 weekly volatility target 1.00×. Figures scale with the multiplier. They are Strategy Tester simulations, not live results.