Please note that this is still a ‘work-in-progress’ and I’m no expert on this – just trying to learn more about Custom Criteria. So if you have any ideas or thoughts about Custom Criteria, I encourage you to add these to this thread.
If you have any ideas for custom optimization criteria, also add them to this thread, and perhaps we can code them.
General information
MultiCharts allows you to optimize on 18 different optimization criteria, such as percentage profitable, profit factor, maximum intraday drawdown and win/loss ratio. These criteria are already quite suited for optimization, but if want to use something more exotic, you could write your own Custom Criteria.
Custom Criteria can be found through the following:
Right click the chart -> Format Signals -> Optimize -> choose Genetic and press Ok -> Go to the tab Algorithm-specific Properties, and choose Custom Criteria and click ‘Edit…’.
Custom Criteria aren’t written in EasyLanguage but use Microsoft Jscript. See MSDN for more information about this, and here you can find a very accessible tutorial. More information about the Math class and it's method can be found here.
Some handy things to know about Jscript and Custom Criteria:
- Jscript is case sensitive; the variable ‘TotalTrades’ is something different than ‘totalTrades’;
If you made an error, you’ll either receive an error message with the line number at which the error occurred or the Custom Criteria shows “-“ in the Optimization Report;
Code can be commented out with double slashes, for example:
// this line is commented out
To comment out large parts of code, you can use /* */, for example:
/* this
whole
section
is commented out */
Note: The /* ... */ can not be nested. For example, this will give an syntax error:
/* commented
out
/* another comment /*
section */
The following is a list of available reserved words which can be used in Custom Criteria (besides creating your own Jscript variables):
Code: Select all
The reserved words supported in Multicharts optimization:
StrategyPerformance.NetProfit
StrategyPerformance.GrossProfit
StrategyPerformance.GrossLoss
StrategyPerformance.TotalTrades
StrategyPerformance.PercentProfitable
StrategyPerformance.WinningTrades
StrategyPerformance.LosingTrades
StrategyPerformance.AvgTrade
StrategyPerformance.AvgWinningTrade
StrategyPerformance.AvgLosingTrade
StrategyPerformance.WinLossRatio
StrategyPerformance.MaxConsecWinners
StrategyPerformance.MaxConsecLosers
StrategyPerformance.AvgBarsInWinningTrades
StrategyPerformance.AvgBarsInLosingTrades
StrategyPerformance.MaxStrategyDrawDown
StrategyPerformance.ProfitFactor
StrategyPerformance.ReturnOnAccount
The reserved words supported in Portfolio optimization:
* NetProfit
* GrossProfit
* GrossLoss
* TotalTrades
* PercentProfitable
* WinningTrades
* LosingTrades
* MaxStrategyDrawDown
Accessing trade properties if pyramiding is turned on:
Code: Select all
Numeric OpenEntriesCount- number of open entries
Numeric OpenEntryDate(Numeric entry_index=0) - date of entry order execution. entry_index - entry number.
Numeric OpenEntryTime(Numeric entry_index=0) - time of entry order execution. entry_index - entry number.
Numeric OpenEntryPrice(Numeric entry_index=0) - price of entry order execution. entry_index - entry number.
Numeric OpenEntryContracts(Numeric entry_index=0) - number of entry order contracts. entry_index - entry number.
Numeric OpenEntryProfit(Numeric entry_index=0) - current entry profit. entry_index - entry number.
Numeric OpenEntryMaxProfit(Numeric entry_index=0) - maximum potential entry profit which was achieved. entry_index - entry number.
Numeric OpenEntryMinProfit(Numeric entry_index=0) - minimum potential entry profit which was achieved. entry_index - entry number.
Numeric OpenEntryProfitPerContract(Numeric entry_index=0) - current entry profit per contract. entry_index - entry number.
Numeric OpenEntryMaxProfitPerContract(Numeric entry_index=0) - maximum potential entry profit per contract which was achieved. entry_index - entry number.
Numeric OpenEntryMinProfitPerContract(Numeric entry_index=0) - minimum potential entry profit per contract which was achieved. entry_index - entry number.
Numeric OpenEntryComission(Numeric entry_index=0) - value of entry comission. entry_index - entry number.
Examples
Taken from the default Custom Criteria:
The following 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.
Code: Select all
if (StrategyPerformance.MaxStrategyDrawDown != 0) {
return StrategyPerformance.NetProfit / (-StrategyPerformance.MaxStrategyDrawDown);
}
Code: Select all
return StrategyPerformance.WinningTrades - StrategyPerformance.LosingTrades;
Code: Select all
if (StrategyPerformance.GrossLoss != 0) {
return StrategyPerformance.GrossProfit / StrategyPerformance.GrossLoss;
}
Code: Select all
if (StrategyPerformance.TotalTrades != 0) {
return StrategyPerformance.WinningTrades / StrategyPerformance.TotalTrades;
}
If you find this thread helpful, in any way, please show your support by hitting the "Thanks" button. Thanks!