Sort results high to low

Created at 13 Feb 2020, 22:12
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!
MA

Marin0ss

Joined 07.06.2014

Sort results high to low
13 Feb 2020, 22:12


Hi Ctrader Community,

I need some help sorting some results. I want to print, export (filewrite) and email the results from High to Low.

Can anyone give me a solution or advise how to do this? Would like to have them sorted in all 3 export ways.

Thanks!

 


            _fileWriter.WriteLine("{0}; EUR; USD; GBP; CHF; AUD; CAD; NZD", DateTime.Now);
            _fileWriter.WriteLine("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}", DateTime.Now, H4_EURJPYresult, H4_USDJPYresult, H4_GBPJPYresult, H4_CHFJPYresult, H4_AUDJPYresult, H4_CADJPYresult, H4_NZDJPYresult);


            Print("EUR = {0}", H4_EURJPYresult);
            Print("USD = {0}", H4_USDJPYresult);
            Print("GBP = {0}", H4_GBPJPYresult);
            Print("CHF = {0}", H4_CHFJPYresult);
            Print("AUD = {0}", H4_AUDJPYresult);
            Print("CAD = {0}", H4_CADJPYresult);
            Print("NZD = {0}", H4_NZDJPYresult);

            var emailBody = string.Format("EUR = {0}\nUSD = {1}\nGBP = {2}\nCHF = {3}\nAUD = {4}\nCAD = {5}\nNZD = {6}", H4_EURJPYresult, H4_USDJPYresult, H4_GBPJPYresult, H4_CHFJPYresult, H4_AUDJPYresult, H4_CADJPYresult, H4_NZDJPYresult);
            Notifications.SendEmail("email", "email", "Results", emailBody);

 


@Marin0ss
Replies

firemyst
14 Feb 2020, 18:19

Add them to a Dictionary<string,double> object (assuming the results are doubles), sort the dictionary, and then loop over it.

Examples:

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        // Example dictionary.
        var dictionary = new Dictionary<string, int>(5);
        dictionary.Add("cat", 1);
        dictionary.Add("dog", 0);
        dictionary.Add("mouse", 5);
        dictionary.Add("eel", 3);
        dictionary.Add("programmer", 2);

        // Order by values.
        // ... Use LINQ to specify sorting by value.
        var items = from pair in dictionary
                    orderby pair.Value ascending
                    select pair;

        // Display results.
        foreach (KeyValuePair<string, int> pair in items)
        {
            Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
        }

        // Reverse sort.
        // ... Can be looped over in the same way as above.
        items = from pair in dictionary
                orderby pair.Value descending
                select pair;
    }
}

 


@firemyst