AverageDownVolume = Average(Volume, AverageDownLength);
HighAvgDownVolume = Highest(AverageDownVolume, AverageDownLength);
LowAvgDownVolume = Lowest(AverageDownVolume, AverageDownLength);
RelAvgDownVolume = (AverageDownVolume - LowAvgDownVolume) /
(HighAvgDownVolume - LowAvgDownVolume);
InvRelAvgDownVolume = 1 - RelAvgDownVolume;
VolWeightedDownAvg = RelAvgDownVolume * AvgPrice +
InvRelAvgDownVolume * VolWeightedDownAvg;
If MarketPosition = 0 and Close > VolWeightedDownAvg and
VolWeightedDownAvg > VolWeightedDownAvg[1] Then
Sell ("S-July01") Next Bar NumCont Contracts at Lowest(Low,
TriggerLength) Stop;
End;
If MarketPosition = 1 and Close < VolWeightedUpAvg Then
ExitLong on Close;
If MarketPosition = -1 and Close > VolWeightedDownAvg Then
ExitShort on Close;
{Code for testing stops in Excel goes here (see Part 3 of book), with
Normalize(False). Set SurfaceChartTest(True). Disable original stops in system.}
{Code for initial market export goes here, with Normalize(True). Set
ExportSwitch(True).}
{Code for testing robustness goes here (see Part 3 of book), with Normalize(True).
Set RobustnessSwitch(True).}
{Code for exporting results for money management analysis goes here (see Part 4
of book), with Normalize(False). Set MoneyExport(True).}
CHAPTER 13 Volume-weighted Average 161