// wf-fixed-baseline.afl
// Part 32 - Lab: Run a Walk-Forward Analysis (the control)
//
// This is wf-breakout-portfolio.afl with the two Optimize() calls replaced by
// constants, and NOTHING else changed. It is the control the walk-forward
// result has to beat.
//
// Why it exists: a walk-forward run tells you what the re-optimisation
// PROCEDURE produced. On its own that number is uninterpretable, because you
// do not know what the same rules would have produced with no re-optimisation
// at all. Run this over the same span, the same watch list and the same
// settings, and you have something to compare against.
//
// The parameter values below are the mid-points of the two optimisation
// ranges, chosen before either test was run so that the comparison is not
// itself a selection. Do not "improve" them after seeing a result: the moment
// you tune the control, it stops being a control.
//
// Every assumption from wf-breakout-portfolio.afl applies here unchanged:
// daily adjusted bars, a non-point-in-time watch list carrying survivorship
// bias, signals on the close, fills at the next open with 0.05% slippage each
// way, 0.15% commission each way, a 15% maximum-loss stop exiting next bar at
// the open, 100,000 of capital, 10 positions of 10% of equity, no margin.

_SECTION_BEGIN( "Fixed-parameter baseline" );

// --- Fixed in advance, at the mid-point of the optimisation ranges ----------
BreakoutPeriod = 60;         // range was 20..100 step 5
ExitPeriod     = 30;         // range was 10..50  step 5

TrendPeriod    = 200;
TurnoverPeriod = 50;
MinTurnover    = 2000000;
StopPercent    = 15;
SlippagePct    = 0.05;
PositionPct    = 10;

SetOption( "InitialEquity",            100000 );
SetOption( "MaxOpenPositions",         10 );
SetOption( "CommissionMode",           1 );
SetOption( "CommissionAmount",         0.15 );
SetOption( "AllowPositionShrinking",   True );
SetOption( "ActivateStopsImmediately", True );
SetTradeDelays( 1, 1, 1, 1 );

BuyPrice  = Open * ( 1 + SlippagePct / 100 );
SellPrice = Open * ( 1 - SlippagePct / 100 );

SetPositionSize( PositionPct, spsPercentOfEquity );

Turnover    = Close * Volume;
AvgTurnover = MA( Turnover, TurnoverPeriod );
Liquid      = AvgTurnover > MinTurnover;

UpTrend = Close > MA( Close, TrendPeriod );

BreakoutLevel = Ref( HHV( High, BreakoutPeriod ), -1 );
ExitLevel     = Ref( LLV( Low,  ExitPeriod     ), -1 );

Buy  = Liquid AND UpTrend AND Close > BreakoutLevel;
Sell = Close < ExitLevel;

Buy  = ExRem( Buy,  Sell );
Sell = ExRem( Sell, Buy  );

PositionScore = 100 + ROC( Close, 100 );

ApplyStop( stopTypeLoss, stopModePercent, StopPercent, 2 );

_SECTION_END();
