The core idea is that greater weight should be given to more recent results, i.e. older results should be given less weight based on their age. The following code shows this can be achieved by using Custom Fitness function. In practice, I multiply/exponentiate newer returns which has the effect of decaying older results. In this code, I am just linearly decaying the data based on bars passed.
Code: Select all
variables:
ExpProfit(0), LastNetProfit(0), LastTradeProfit(0), BarCounter(0);
BarCounter = BarCounter+1;
LastNetProfit = netprofit;
if LastNetProfit <> LastNetProfit [1] then begin
LastTradeProfit = LastNetProfit -LastNetProfit [1];
ExpProfit = ExpProfit[1] + LastTradeProfit*BarCounter;
end;
SetCustomFitnessValue(ExpProfit );