Guarda come scaricare robot di trading gratuitamente
Ci trovi su Facebook!
Unisciti alla nostra fan page
Unisciti alla nostra fan page
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5

merge sort - a merging method comparison-based sorting algorithm - libreria per MetaTrader 5
- Visualizzazioni:
- 3848
- Valutazioni:
- Pubblicato:
- 2020.12.30 08:37
-
Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance
//+------------------------------------------------------------------+ //| MergeSort.mq5 | //| 2019-2020, dimitri pecheritsa | //| 792112@gmail.com | //+------------------------------------------------------------------+ // merge sort - a merging method comparison-based sorting algorithm // // merge sort is an efficient, general-purpose, comparison-based //sorting algorithm. most implementations produce a stable sort, //which means that the order of equal elements is the same in the //input and output. merge sort is a divide and conquer algorithm that //was invented by john von neumann in 1945. // merge sort takes advantage of the ease of merging already sorted //lists into a new sorted list. it starts by comparing every two //elements (i.e., 1 with 2, then 3 with 4...) and swapping them if //the first should come after the second. it then merges each of the //resulting lists of two into lists of four, then merges those lists //of four, and so on; until at last two lists are merged into the //final sorted list. this algorithm scales well to very large lists, //because its worst-case running time is o(n log n). it is also //easily applied to lists, not only arrays, as it only requires //sequential access, not random access. however, it has additional //o(n) space complexity, and involves a large number of copies in //simple implementations. // merge sort is used in the sophisticated algorithm timsort, which //is used for the standard sort routine in the programming languages //python and java. merge sort itself is the standard routine in perl, //among others, and has been used in java. // cases: best - n log n, average - n log n, worst - n log n // memory - n, stability - yes, method - merging // //+------------------------------------------------------------------+ //| merge sort example - sort positions by ticket number | //+------------------------------------------------------------------+ #include <Mqh\Algorithms\MergeSort\ASorter.mqh> #include <Mqh\Algorithms\MergeSort\MergeSort.mqh> #include <Mqh\Algorithms\MergeSort\Functions.mqh> void OnStart(void) { //---load tickets from terminal string symbol=_Symbol; ulong tickets[]; PositionsLoad(tickets,symbol); //---sort tickets by number in accending order ArraySort(tickets,new CMergeSort<ulong,ulong>); //---print tickets PositionsPrint(tickets,(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS)); } // // output // // TSLA | 202127461 | 566.46 // TSLA | 202127496 | 567.00 // TSLA | 202128932 | 574.70 // TSLA | 202147120 | 600.33 // TSLA | 202149635 | 598.14 // TSLA | 202185008 | 616.92 // ... //+------------------------------------------------------------------+

Ea working well on EURUSD1 H1 with initial parameters, using a simple strategy based on Bollinger bands and RSI.

A sorter class to sort an array based on other arrays.

a much more efficient version of selection sort

This is a simple EA test code I made for adapting Candlepatterns.mqh