how to find the position that has biggest the drawdown?

Created at 15 May 2016, 01:21
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!
GD

GDPR-24_203122

Joined 02.10.2015 Blocked

how to find the position that has biggest the drawdown?
15 May 2016, 01:21


If a bot has multiple positions and I want to find which position has the biggest dd, how to do code it (on bar)?

I guess this kind of approach could be used with modifications:

 

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleMartingalecBot : Robot
     {

       private double peak;
       private List<double> drawdown = new List<double>();
       private double maxDrawdown;

      }

 

protected override void OnStart()
{

 Positions.Closed += PositionsOnClosed;

}

 

private void PositionsOnClosed(PositionClosedEventArgs args)
            {
                var position = args.Position;
                GetMaxDrawDown();
             }

 

private void GetMaxDrawDown()
             {
                peak = Math.Max(peak, Account.Balance);

                 drawdown.Add((peak - Account.Balance) / peak * 100);
                 drawdown.Sort();

                 maxDrawdown = drawdown[drawdown.Count - 1];
                 Print("Max DrawDown = {0}", Math.Round(maxDrawdown, 2));
              }

}


Replies

croucrou
17 May 2016, 16:35

Maybe you are looking for the Minimum of Position.GrossProfit?


@croucrou

GDPR-24_203122
22 May 2016, 18:07

RE:

croucrou said:

Maybe you are looking for the Minimum of Position.GrossProfit?

Croucrou, yes that would do it. 

How to get the position, with the minimum GrossProfit?

 

Should either of these be used first?:

1. foreach (var Position in Positions)

2. Position[] positions = Positions.FindAll(Label, Symbol);

 

THANKS!


Jiri
22 May 2016, 19:30

I recommend using LINQ query operations.

using System.Linq;

var position = Positions.OrderByDescending(x => x.GrossProfit).Last();

 


@Jiri

GDPR-24_203122
22 May 2016, 23:01

RE:

tmc. said:

I recommend using LINQ query operations.

using System.Linq;

var position = Positions.OrderByDescending(x => x.GrossProfit).Last();

 

Great, thanks a lot!