Introsort_pfn/sort_MqlRates.mq5

38 lines
3.5 KiB
MQL5
Raw Permalink Normal View History

2025-09-19 20:20:45 +00:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| sort_MqlRates.mq5 |
//| Copyright <EFBFBD> 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);
}
//+------------------------------------------------------------------+