[Code] For Optimizer: allow a specific MaxDrawDown only

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
geektrader
Posts: 100
Joined: 17 Jul 2009
Location: Germany

[Code] For Optimizer: allow a specific MaxDrawDown only

Postby geektrader » 10 Feb 2010

This it not a strategy on it´s own,but something to add when optimizing your strategy with the Optimizer.

The purpose of this is to only optimize for results that have a Max Intraday Draw Down of XX Dollar (whatever you specify). Since the optimizer doesn´t allow such an option yet like MT allows it (e.g. Optimizing for best Net Profit,but with a Max Intraday Drawdown of XX), this is a "dirty hack" to still achieve that right now.

All you need to do is to add this code to your strategy (this example uses 500 Dollar as max allowed drawdown, set it to whatever you like):

At the Inputs/Variables section you add:

Code: Select all


input: LargestDrawDownAllowed(500);
var: DDCondition(false);



Before your "normal" code starts you add:

Code: Select all


DDCondition=MaxIDDrawDown > -LargestDrawDownAllowed;

if DDCondition then
begin

//Your Existing Code STARTS Here




At the VERY end of your code, you add:

Code: Select all


//Your Existing Code ENDS Here

end;

if DDCondition=false then begin
if MarketPosition = 1 Then Sell ( "ToLargeDrawDownLX" ) next bar at market;
if MarketPosition = -1 Then Buy To Cover ( "ToLargeDrawDownSX" ) next bar at market;
End;




Now start optimizing as usally (for best Net Profit or whatever you like). All the results the optimizer presents at the end, will have a Intraday Draw Down below the amount you´ve set. And you just have achieved the highest Net Profit possible with the Max Draw Down you´ve set.

P.S.: A little extra tip, in case the optimized results show you a "ToLargeDrawDown"-Exit anywhere in the "List of Trades", you need to raise your Max Allowed Drawdown. This simply means the optimizer hasn´t found any possible combination that was tradeable over the whole time-frame with only a draw down of the size you´ve specified.

Afterwards you can just remove the code if you like.
Last edited by geektrader on 05 Mar 2010, edited 1 time in total.

User avatar
Andrew Kirillov
Posts: 1589
Joined: 28 Jul 2005
Has thanked: 2 times
Been thanked: 31 times
Contact:

Postby Andrew Kirillov » 10 Feb 2010

Dear Sir,
Please take a look at Custom Criteria of MultiCharts optimization.
It allows you to use several criteria at time. I think it means your objectives.

1.
Name of property in the object StrategyPerformance Description Available in MultiCharts Available in Portfolio Optimization
NetProfit Net Profit Yes Yes
GrossProfit Gross Profit Yes Yes
Gross Loss Gross Loss Yes Yes
TotalTrades Total Trades Yes Yes
Percent Profitable % Profitable Yes Yes
Winning Trades Winning Trades Yes Yes
LosingTrades Losing Trades Yes Yes
AvgTrade Avg Trade Yes No
AvgWinningTrade Avg Winning Trade Yes No
AvgLosingTrade Avg Losing Trade Yes No
WinLossRatio Win/Loss Ratio Yes No
MaxConsecWinners Max Consecutive Winners Yes No
MaxConsecLosers Max Consecutive Losers Yes No
AvgBarsInWinningTrades Avg Bars in Winner Yes No
AvgBarsInLosingTrades Avg Bars in Loser Yes No
MaxStrategyDrawDown Max Intraday Drawdown Yes Yes
ProfitFactor Profit Factor Yes No
ReturnOnAccount Return on Account Yes No

geektrader
Posts: 100
Joined: 17 Jul 2009
Location: Germany

Postby geektrader » 10 Feb 2010

I know all those words Andrew, thanks a lot. Problem still is, you can´t FORCE the optimizer to not allow Draw Downs Bigger than what you specify. One could set a Java-Script and take into account Draw Down by a custom optimization criteria, but even with that you cannot FORCE the optimizer to not allow draw downs bigger than X. It still spits out results with a bigger draw down, just that the custom criteria is than not calculated. The only way to do this currently is the way I did it above.


Return to “User Contributed Studies and Indicator Library”