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);
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.