Finding Max and Min of account balance in all history

Created at 28 Mar 2017, 13:26
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!
LS

LSR2412

Joined 07.11.2014

Finding Max and Min of account balance in all history
28 Mar 2017, 13:26


Hi,

I need a bit help with finding Max and Min Balance of account in all history (since opening account). I have robots which are on and off, and not trading all time, but in them I would like to have Max and Min Balance accesed, to use it for some calculations.

Many thanks


@LSR2412
Replies

whis.gg
28 Mar 2017, 16:10

Hi, try this.

double maximumBalance = double.MinValue;
double minimumBalance = double.MaxValue;

foreach (var historicalTrade in History)
{
    maximumBalance = Math.Max(historicalTrade.Balance, maximumBalance);
    minimumBalance = Math.Min(historicalTrade.Balance, minimumBalance);
}

 


@whis.gg

whis.gg
28 Mar 2017, 16:12

Or using System.Linq

double maximumBalance = History.Max(x => x.Balance);
double minimumBalance = History.Min(x => x.Balance);

 


@whis.gg

LSR2412
28 Mar 2017, 16:22

thank you very much, this made my day :)

2nd solution works like charm, just what I needed...thanks


@LSR2412