Watch how to download trading robots for free
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

merge sort - a merging method comparison-based sorting algorithm - library for MetaTrader 5

DMITRII PECHERITSA

Views:
690
Rating:
votes: 9
Published:
2020.12.30 08:37
\MQL5\Include\Mqh\Algorithms\MergeSort\
//+------------------------------------------------------------------+
//|                                                    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
//   ...
//+------------------------------------------------------------------+
    Simple EA using Bollinger, RSI and MA Simple EA using Bollinger, RSI and MA

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

    MultiSort - sorting algorithm MultiSort - sorting algorithm

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

    heap sort - array sorting algorithm heap sort - array sorting algorithm

    a much more efficient version of selection sort

    NTr Close All Trades NTr Close All Trades

    This script is made to close all positions