//+------------------------------------------------------------------+
//| SelectionSort.mq5 |
//| 2019-2021, dimitri pecheritsa |
//| mql5.com/en/users/dmipec |
//+------------------------------------------------------------------+
//| selection sort - array sorting algorithm |
//+------------------------------------------------------------------+
//| best: n^2, average: n^2, worst: n^2 |
//| memory: 1, stable: no, method: selection |
//| note: stable with o(n) extra space or when using linked lists. |
//+------------------------------------------------------------------+
//| in computer science, selection sort is an in-place comparison |
//|sorting algorithm. it has an o(n2) time complexity, which makes |
//|it inefficient on large lists, and generally performs worse than |
//|the similar insertion sort. selection sort is noted for its |
//|simplicity and has performance advantages over more complicated |
//|algorithms in certain situations, particularly where auxiliary |
//|memory is limited. |
//| the time efficiency of selection sort is quadratic, so there |
//|are a number of sorting techniques which have better time |
//|complexity than selection sort. one thing which distinguishes |
//|selection sort from other sorting algorithms is that it makes the |
//|minimum possible number of swaps, n − 1 in the worst case. |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| script program start function |
//| [use] a selection sort example. sort deals by symbol |
//+------------------------------------------------------------------+
#include <Mqh\Algorithms\SelectionSort\SelectionSort.mqh>
#include <Mqh\Algorithms\SelectionSort\Functions.mqh>
void OnStart(void)
{
//--- load deals from the terminal starting from the beginning of
//2021 till current day. they will be treated as the items array by
//the sorter
ulong deals[];
DealsLoad(deals,D'2021.01.01',0);
//--- create the keys array which contains the symbols of each deal
//from the deals array, which is the basis for sorting
string symbols[];
DealsKeySymbol(deals,symbols);
//--- sort deals by symbols in descending order with the selection
//sort algorithm
ArraySort(symbols,deals,new CSelectionSort<string,ulong>,false);
//--- check the result of sorting by printing a table of symbols.
//your table will look different
DealsPrint(deals);
}
//--------------------------------------------------------------------
// deal | symbol
//--------------------------------------------------------------------
// 170477949 | XAUUSD
// 170764903 | XAUUSD
// 170764902 | XAUUSD
// 170252156 | XAUUSD
// 170541532 | XAUUSD
// 172313700 | BTCUSD
// 172313699 | BTCUSD
// 172313666 | BTCUSD
// 172313530 | BTCUSD
// 172313512 | BTCUSD
// 172313511 | BTCUSD
// 172313502 | BTCUSD
// 172313501 | BTCUSD
// 172313500 | BTCUSD
// 172313493 | BTCUSD
// 172313490 | BTCUSD
// 172313488 | BTCUSD
// 172313474 | BTCUSD
// 172313453 | BTCUSD
// 172313412 | BTCUSD
// 171147845 | BTCUSD
// 171145409 | BTCUSD
// 171145256 | BTCUSD
// 171145029 | BTCUSD
// 171011667 | BTCUSD
// 170983807 | BTCUSD
// 170720576 | BTCUSD
// 170429897 | BTCUSD
// 169998112 | BTCUSD
// 169998099 | BTCUSD
// 169990154 | BTCUSD
//--------------------------------------------------------------------
#33104LibrariesMetaTrader 5👁 4168 views
selection sort - array sorting algorithm
D
Author
DMITRII PECHERITSAPublished date
Jan 20, 2021
📚Related Articles
← View other articles →#77531Libraries
CSetupLedger: a per-setup win rate ledger for Expert Advisors
Why I wrote it My scalper trades two setups. A bullish order block and the bearish mirror of it. The Strategy Tester gave me one profit factor for both of them. I spent two weeks t...
Ali AkbarView detail →
#77488Libraries
Position sizing from risk, using the broker's own tick value and volume step
Every lot size calculator that assumes one pip is worth ten dollars is wrong on gold, wrong on indices, wrong on JPY crosses and wrong on any account not denominated in USD which i...
Ralph Ivan SimeonView detail →
#77156Libraries
PropFirm Defense
A prop firm account runs under a second rulebook MetaTrader 5 knows nothing about: a maximum loss measured from a fixed starting balance, a daily limit that resets at an hour the b...
Bruno Nunes Myrrha RibeiroView detail →