거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Twitter에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

MultiSort - sorting algorithm - MetaTrader 5용 라이브러리

조회수:
3390
평가:
(19)
게시됨:
2020.12.26 17:01
업데이트됨:
2021.04.02 23:05
\MQL5\Scripts\ \MQL5\Include\
MultiSort.mqh (15.02 KB) 조회
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

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

//+------------------------------------------------------------------+
//| class MultiSort<TItem,TKey1,TKey2,TKey3>.                        |
//| Usage: Sorter class to sort an array based on other arrays.      |
//+------------------------------------------------------------------+
template<typename TItem,typename TKey1,typename TKey2,typename TKey3>
class MultiSort
  {
public:
   //--- method to sort items by keys
   void              SortBy(TItem& items[],
                            TKey1& keys1[],
                            TKey2& keys2[],
                            TKey3& keys3[],
                            bool   ascending_order1=true,
                            bool   ascending_order2=true,
                            bool   ascending_order3=true);
  };


Note:

Empty keys arrays are ignored by the sorter.

For example to sort position tickets by position open time (as the only sort key):

   //--- sort tickets by position open time only
   MultiSort<long,datetime,int,int> sorter;
   int empty[];

   sorter.SortBy(tickets,times,empty,empty);


Here is a complete example

//+------------------------------------------------------------------+
//|                                               MultiSort_demo.mq5 |
//|                                        Copyright © 2018, Amr Ali |
//|                             https://www.mql5.com/en/users/amrali |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018, Amr Ali"
#property description "Multi sort example - Sort position tickets by symbol then by open time then by open price in accending or descending order."
#property version   "1.000"
#property script_show_inputs

#include <MultiSort.mqh>

//--- input variables
input bool mode_asc_symbols = true;   // ascending order for symbols
input bool mode_asc_times   = true;   // ascending order for time
input bool mode_asc_prices  = true;   // ascending order for price

//--- global variables
long   tickets[]= {88806796,90462225,91039722,91200504,90389608,88429143,89452623,91487721,89323610,90439077,89355691,88943822};
string symbols[]= {"USDCAD","EURCHF","GBPCHF","EURUSD","EURUSD","EURCHF","AUDUSD","EURUSD","EURUSD","GBPCHF","EURCHF","AUDUSD"};
datetime times[]= {D'2020.12.07 09:31:40',D'2020.12.10 09:55:30',D'2020.12.07 03:16:05',D'2020.12.07 03:45:39',D'2020.12.09 14:34:42',
                   D'2020.12.08 14:00:13',D'2020.12.07 12:34:42',D'2020.12.08 17:37:28',D'2020.12.10 02:34:55',D'2020.12.09 12:00:09',
                   D'2020.12.10 17:56:09',D'2020.12.07 08:30:14'};
double  prices[]= {1.24428,1.35444,1.37244,1.28973,1.39795,1.39960,1.15292,1.19290,1.11015,1.17936,1.37226,1.34722};
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   Print("-------before sort-------");
   for(int i=0; i<ArraySize(tickets); i++)
      PrintFormat("%8i | %8s | %8s | %8.5f",tickets[i],symbols[i],(string)times[i],prices[i]);


//--- sort position tickets by symbol, open time and open price.
   MultiSort<long, string, datetime, double> multi_sorter;

   multi_sorter.SortBy(tickets,
                       symbols,
                       times,
                       prices,
                       mode_asc_symbols,
                       mode_asc_times,
                       mode_asc_prices);

   Print("-------MultiSort.SortBy(tickets,symbols,times,prices)-------");
   for(int i=0; i<ArraySize(tickets); i++)
      PrintFormat("%8i | %8s | %8s | %8.5f",tickets[i],symbols[i],(string)times[i],prices[i]);
  }
//+------------------------------------------------------------------+

/* Sample output

  -------before sort-------
  88806796 |   USDCAD | 2020.12.07 09:31:40 |  1.24428
  90462225 |   EURCHF | 2020.12.10 09:55:30 |  1.35444
  91039722 |   GBPCHF | 2020.12.07 03:16:05 |  1.37244
  91200504 |   EURUSD | 2020.12.07 03:45:39 |  1.28973
  90389608 |   EURUSD | 2020.12.09 14:34:42 |  1.39795
  88429143 |   EURCHF | 2020.12.08 14:00:13 |  1.39960
  89452623 |   AUDUSD | 2020.12.07 12:34:42 |  1.15292
  91487721 |   EURUSD | 2020.12.08 17:37:28 |  1.19290
  89323610 |   EURUSD | 2020.12.10 02:34:55 |  1.11015
  90439077 |   GBPCHF | 2020.12.09 12:00:09 |  1.17936
  89355691 |   EURCHF | 2020.12.10 17:56:09 |  1.37226
  88943822 |   AUDUSD | 2020.12.07 08:30:14 |  1.34722

  -------MultiSort.SortBy(tickets,symbols,times,prices)-------
  88943822 |   AUDUSD | 2020.12.07 08:30:14 |  1.34722
  89452623 |   AUDUSD | 2020.12.07 12:34:42 |  1.15292
  88429143 |   EURCHF | 2020.12.08 14:00:13 |  1.39960
  90462225 |   EURCHF | 2020.12.10 09:55:30 |  1.35444
  89355691 |   EURCHF | 2020.12.10 17:56:09 |  1.37226
  91200504 |   EURUSD | 2020.12.07 03:45:39 |  1.28973
  91487721 |   EURUSD | 2020.12.08 17:37:28 |  1.19290
  90389608 |   EURUSD | 2020.12.09 14:34:42 |  1.39795
  89323610 |   EURUSD | 2020.12.10 02:34:55 |  1.11015
  91039722 |   GBPCHF | 2020.12.07 03:16:05 |  1.37244
  90439077 |   GBPCHF | 2020.12.09 12:00:09 |  1.17936
  88806796 |   USDCAD | 2020.12.07 09:31:40 |  1.24428
*/


EA Fibonacci Potential Entry - MT5 EA Fibonacci Potential Entry - MT5

The 8 effective steps to build a robust day trading plan using Fibonacci retracement

Free mt5 Copier Free mt5 Copier

Copy trading has become such a critical feature of forex trading. Some people see this as a potential business opportunity, while for opensource die-hards like me, we believe in giving back to the community rather than putting a price tag on everything 'nice'. So here it comes. A free opensource trade copier, which you are freely allowed to modify and distribute according to MIT license terms. It still has limited features, but the essentials like lot normalization are there. Please note that this copier only works for trading terminals installed on the same machine. Please share back any upgrades, enhancements or bug fixes to the discussion. Enjoy!

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.

merge sort - a merging method comparison-based sorting algorithm merge sort - a merging method comparison-based sorting algorithm

an efficient, general-purpose sorting algorithm