//+------------------------------------------------------------------+ //| sort_MqlRates.mq5 | //| Copyright © 2018, Amr Ali | //| https://www.mql5.com/en/users/amrali | //+------------------------------------------------------------------+ #include "Introsort.mqh" //+------------------------------------------------------------------+ //| custom comparison functions Less. | //+------------------------------------------------------------------+ bool asc_by_open ( MqlRates &a, MqlRates &b) { return a.open < b.open; } bool asc_by_high ( MqlRates &a, MqlRates &b) { return a.high < b.high; } bool asc_by_low ( MqlRates &a, MqlRates &b) { return a.low < b.low; } bool asc_by_close ( MqlRates &a, MqlRates &b) { return a.close < b.close; } bool asc_by_time ( MqlRates &a, MqlRates &b) { return a.time < b.time; } bool asc_by_tick_volume( MqlRates &a, MqlRates &b) { return a.tick_volume < b.tick_volume; } // Define a pointer type to custom Less function. typedef bool (*pFunc)(MqlRates &a, MqlRates &b); //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { MqlRates Rates[]; CopyRates(_Symbol, PERIOD_CURRENT, 0, 5, Rates); ArrayPrint(Rates); Introsort(Rates, (pFunc)asc_by_open); ArrayPrint(Rates); Introsort(Rates, (pFunc)asc_by_tick_volume); ArrayPrint(Rates); } //+------------------------------------------------------------------+