Max draw down coding.

Created at 26 Apr 2013, 08:17
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
kricka's avatar

kricka

Joined 13.03.2013

Max draw down coding.
26 Apr 2013, 08:17


Hi,

please give me the right way to code the max draw down so it is inline with the way you calculate the back testing draw down.

Account.Balance is used I would think and based on historical high and declining low.

Thanks..


@kricka
Replies

cAlgo_Fanatic
26 Apr 2013, 11:31

Please see this sample for Max DrawDown.

In the example this is the function that calculates it which is called when the position closes, in the OnPositionClosed event:

        private void GetMaxDrawDown()
        {
            peak = Math.Max(peak, Account.Balance);
            Array.Resize(ref drawdown, drawdown.Length + 1);
            int i = drawdown.Length - 1;
            drawdown[i] = (peak - Account.Balance) / peak * 100;

            for (i = 0; i < drawdown.Length; i++)
                maxDrawdown = Math.Max(maxDrawdown, drawdown[i]);

            Print("Max DrawDown = {0}", Math.Round(maxDrawdown, 2));
            
        }

 


@cAlgo_Fanatic

kricka
26 Apr 2013, 17:22

Hi,

tried to compile /forum/calgo-reference-samples/823 and came up with an error. Please correct so I can test and use the sample.

Thanks..


@kricka

cAlgo_Fanatic
26 Apr 2013, 18:01

Can you please recopy the code and let us know if you get the error? Also, let us know what error you are getting.


@cAlgo_Fanatic

kricka
26 Apr 2013, 18:38

I've tried recopy. Here is the Error message.

Error: Usage of the generic type System.Collection.Generic.List <T> needs type argument 1

 

It point to the below line:

private List drawdown = new List(); 

 


@kricka

cAlgo_Development
30 Apr 2013, 12:50

OK, code is corrected. Refresh the page and try again please.


@cAlgo_Development