Template to have Drawdown < x %
Created at 08 Jun 2022, 16:55
KU
Template to have Drawdown < x %
08 Jun 2022, 16:55
Hi,
Looking for help to write a basic template to keep drawdown under a set percentage.
[Parameter("Max Drawdown Percentage", MinValue = 0.01, MaxValue = 4.5)]
public int MaxDD { get; set; }
Using that parameter I wish to have it optimize in back-testing for any percentage below 4.5%.
I would also like to use historical data which is where I am really struggling to figure out....
I would like the Account.Balance to update before every new trade is taken.
If there is an easier way than this to write it, maybe by adding an IF condition instead I would be open to that as well.
I am just unsure how to get it to use the current Account.Balance before entering new trades.
amusleh
09 Jun 2022, 09:30 ( Updated at: 09 Jun 2022, 09:40 )
Hi,
Here is an example:
The above bot calculates drawdown based on account equity, and uses it for optimization fitness.
You can change the Account.Equity to Account.Balance if you want to use balance drawdown.
You can check on "GetFitness" method if drawdown is above a fixed value then return 0.
@amusleh