Hi Howard,
I am using the following code
// CustomMetricWithPenalty.afl
//
// Add a custom metric to the backtest report.
// The metric is the KRatio, multiplied by a
// penalty function based on:
// the average percentage profit or loss per trade.
// the percentage the system is exposed to the market.
// the holding period per trade.
// the percent of trades that are winners.
// the RAR value.
KRatioVal = 0;
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio)
{
bo = GetBacktesterObject();
bo.backtest();
st = bo.getperformancestats(0);
KRatioVal = 100.0 * st.getvalue("KRatio");
RRR = st.getvalue("RRR");
AvgPctGainVal = 0.01
* st.getvalue("AllAvgProfitLossPercent");
ExposureVal = 0.01 * st.getvalue("ExposurePercent");
HoldingPeriodVal = st.getvalue("AllAvgBarsHeld");
PctWinnersVal = 0.01 * st.getvalue("WinnersPercent");
RarVal = 0.01 * st.getvalue("RAR");
AvgPctGainMult = IIf(AvgPctGainVal<0.01,
0.0,
1.00);
ExposureMult = IIf(ExposureVal<0.10,
1.00-(0.50/0.10)*(0.10-ExposureVal),
IIf((ExposureVal>=0.10 AND ExposureVal<=0.20),
1.00,
IIf((ExposureVal>0.20 AND ExposureVal<0.40),
1.00-(0.50/0.20)*(ExposureVal-0.20),
0.50 )));
HoldingPeriodMult = IIf(HoldingPeriodVal<3,
1.00-(0.50/3)*(3-HoldingPeriodVal),
IIf((HoldingPeriodVal>=3 AND HoldingPeriodVal<=7),
1.00,
IIf((HoldingPeriodVal>7 AND HoldingPeriodVal<14),
1.00-(0.50/7)*(HoldingPeriodVal-7),
0.50 )));
PctWinnersMult = IIf(PctWinnersVal<0.50,
0.50,
IIf((PctWinnersVal>=0.50 AND PctWinnersVal<=0.65),
1.00-(0.50/0.15)*(0.65-PctWinnersVal),
1.00 ));
RarMult = IIf(RarVal<0.10,
0.50,
IIf((RarVal>=0.10 AND RarVal<=0.20),
1.00-(0.50/0.10)*(0.20-RarVal),
1.00 ));
ObFn = KRatioVal * AvgPctGainMult * ExposureMult
* HoldingPeriodMult * PctWinnersMult * RarMult;
bo.addcustommetric("ObjectiveFunction", ObFn);
}
// The trading system starts here
/*
fast = Optimize("fast",16,1,20,1);
slow = Optimize("slow",8,1,20,1);
MAF = DEMA(C,fast);
MAS = DEMA(C,slow);
HoldDays = Optimize("HoldDays",1,1,20,1);
Buy = Cross(MAF,MAS);
Sell = Cross(MAS,MAF) OR BarsSince(Buy)>=HoldDays;
Sell = ExRem(Sell,Buy);
*/
e = Equity();
//Plot(C,"C",colorBlack,styleCandle);
//shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
//PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),
// 0, IIf( Buy, Low, High ) );
Plot(e,"Equity",colorGreen,styleLine|styleOwnScale);
//GraphXSpace = 5;
//Figure A.7 Custom Metric with Penalty
I didn't post it at first because I was not sure if you wanted the code to
be made public.
I worked on another objective function, and I wonder... how can you put the
objective function in the walk-forward tab?
Thanks!
Louis
2008/5/9 Howard B <[EMAIL PROTECTED]>:
> Hi Louis --
>
> Please post the code you are trying to use.
>
> Yes, you can use your custom objective function when running backtests and
> automatic walk forward runs.
>
> Thanks,
> Howard
>
>
> On Fri, May 9, 2008 at 3:33 PM, Louis Préfontaine <[EMAIL PROTECTED]>
> wrote:
>
>> Hi,
>>
>> I've been trying to build a custom objective function and tried to see
>> what it would be like to use Howard's one in the Appendix A. However, after
>> running it with different symbols/markets/systems, the results is ALWAYS
>> 0.00 Anyone know why this can happen?
>>
>> BTW, is it possible to add the custom OB to the walk-forward?
>>
>> Thanks,
>>
>> Louis
>>
>>
>>
>
>