Optimization by Custom Fitness Criteria

Questions about MultiCharts and user contributed studies.
ducktail
Posts: 21
Joined: 21 Feb 2011
Has thanked: 22 times
Been thanked: 7 times

Optimization by Custom Fitness Criteria

Postby ducktail » 27 Apr 2012

I'd like to optimize by adjusted profit factor.

Code: Select all

//Adjusted profit factor in EasyLanguage is as follows.
APF=((NumWinTrades -SquareRoot(NumWinTrades))*(GrossProfit/NumWinTrades))/
-((NumLosTrades +SquareRoot(NumLosTrades))*(GrossLoss/NumLosTrades))
So I'm trying to edit Custom Criteria.
QS_20120427-174921.jpg
(24.45 KiB) Downloaded 819 times
QS_20120427-174935.jpg
(46.63 KiB) Downloaded 801 times
But I don't know how to do this.
I guess the sample is not EasyLanguege.
Would you please help me.

Code: Select all

// TODO: Enter your formula to replace the samples below

/************************************* Sample 1 ******************************************/
if (StrategyPerformance.MaxStrategyDrawDown != 0) {
return StrategyPerformance.NetProfit / (-StrategyPerformance.MaxStrategyDrawDown);
}

/* This function maximizes the ratio of Net Profit to Max Drawdown. The goal of this function is to find the trading rules that have a high net profit, but a small total drawdown over the back-tested period. */

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Optimization by Custom Fitness Criteria

Postby JoshM » 27 Apr 2012

What MC version do you use Ducktail? If you're using MC8 (beta), you could use the new SetCustomFitnessValue keyword. That way, the custom criteria can be defined in EasyLanguage.

A thread with Javascript code examples for Custom Criteria can be found here.

ducktail
Posts: 21
Joined: 21 Feb 2011
Has thanked: 22 times
Been thanked: 7 times

Re: Optimization by Custom Fitness Criteria

Postby ducktail » 27 Apr 2012

JoshM, thanks a lot. That's very valuable info.
Through this info, I can edit Custom Fitness Criteria. Thanks again.
By the way, is the keyword SetCustomFitnessValue only for genetic optimization?

My code is as follows.

Code: Select all

// MultiCharts Custom Criteria: Adjusted Profit Factor

// check for errors / wrong values
if (StrategyPerformance.WinningTrades == 0 ||
StrategyPerformance.LosingTrades == 0) {
return 0;
}

var sqrtWins = Math.sqrt(StrategyPerformance.WinningTrades);
var sqrtLosses = Math.sqrt(StrategyPerformance.LosingTrades);

return ((StrategyPerformance.WinningTrades-sqrtWins)*StrategyPerformance.AvgWinningTrade)/((StrategyPerformance.LosingTrades+sqrtLosses)*-StrategyPerformance.AvgLosingTrade);

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Optimization by Custom Fitness Criteria

Postby JoshM » 28 Apr 2012

Thanks for sharing the code Ducktail. Glad you got it solved. :)
By the way, is the keyword SetCustomFitnessValue only for genetic optimization?
Good question. :) But I don't know (I'm not using the beta version yet).

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Optimization by Custom Fitness Criteria

Postby Henry MultiСharts » 30 Apr 2012

SetCustomFitnessValue keyword is designed for the custom optimization criteria that is available for both Genetic and Exhaustive optimizations.

ducktail
Posts: 21
Joined: 21 Feb 2011
Has thanked: 22 times
Been thanked: 7 times

Re: Optimization by Custom Fitness Criteria

Postby ducktail » 30 Apr 2012

Thanks Henry, JoshM.
I tried to test SetCustomFitnessValue and confirmed it works on Exhaustive optimizations.
This keyword is much easier than editting Custom Fitness Criteria.

Ming80
Posts: 24
Joined: 18 Jun 2012
Has thanked: 20 times
Been thanked: 1 time

Re: Optimization by Custom Fitness Criteria

Postby Ming80 » 19 Jun 2012

Hi Guys I've been able to use the Custom Criteria Optimization but not sure how to enable the SetCustomFitnessValue. Could anyone point out how to do this?

Also, I'm, trying to create the below 2 fitness functions without any success so far:
1) Annual Return % / Max DD %
2) Annual Return % / Avg DD %

Much appreciated if anyone could point me in the right direction on the above. Thanks.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Optimization by Custom Fitness Criteria

Postby JoshM » 22 Jun 2012

Hi Guys I've been able to use the Custom Criteria Optimization but not sure how to enable the SetCustomFitnessValue. Could anyone point out how to do this?
See the wiki entry: SetCustomFitnessValue.
Also, I'm, trying to create the below 2 fitness functions without any success so far:
1) Annual Return % / Max DD %
2) Annual Return % / Avg DD %
If you calculate the number of days in the backtest, you can use that to annualize the return and drawdown, and then put that into the custom function with SetCustomFitnessValue (haven't calculate this myself though).


Return to “MultiCharts”