//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |//+----------------------------------------------------------------------------+//| Версия : 12.10.2007 |//+----------------------------------------------------------------------------+//| Описание : Возвращает интервал установки сигнальных указателей |//| Параметры: |//| pr - процент относительно ценового размера окна |//+----------------------------------------------------------------------------+int GetArrowInterval(int pr=7) {
if (pr<=0) pr=7;
return((WindowPriceMax()-WindowPriceMin())/100*pr/Point);
}
Sometimes you need to sort the data in MQL4 without touching the data itself. There are no pointers in MQL4, and there are no structures either.
Here is an example of a script that sorts data by different parameters through emulation of pointers. Perhaps, someone will find this approach and the sorting function useful.
#define AMOUNT 5string Symbols[AMOUNT] = {"EURUSD", "GBPUSD", "USDJPY", "USDCHF", "EURGBP"};
int Profit[AMOUNT] = {50, -130, 90, 2000, 0};
int Pos[AMOUNT] = {3, 0, 6, 7, 1};
int SL[AMOUNT] = {20, 60, 10, 80, 100};
void SortArrayINT( int Array[], int& Positions[], bool Increase = TRUE )
{
int i, j, Tmp, Size = ArraySize(Array);
if (ArraySize(Positions) != Size)
ArrayResize(Positions, Size);
for (i = 0; i < Size; i++)
Positions[i] = i;
if (Increase)
{
for (i = 0; i < Size - 1; i++)
for (j = i + 1; j < Size; j++)
if (Array[Positions[i]] > Array[Positions[j]])
{
Tmp = Positions[j];
Positions[j] = Positions[i];
Positions[i] = Tmp;
}
}
elsefor (i = 0; i < Size - 1; i++)
for (j = i + 1; j < Size; j++)
if (Array[Positions[i]] < Array[Positions[j]])
{
Tmp = Positions[j];
Positions[j] = Positions[i];
Positions[i] = Tmp;
}
return;
}
void PrintInfo( string SortName, int Array[] )
{
int Positions[];
SortArrayINT(Array, Positions);
Print("Sort by " + SortName);
Print("SYMBOL PROFIT POS SL");
for (int i = 0; i < AMOUNT; i++)
Print(Symbols[Positions[i]] + " " + Profit[Positions[i]] + " " +
Pos[Positions[i]] + " " + SL[Positions[i]]);
Print("");
return;
}
void start()
{
PrintInfo("PROFIT", Profit); // распечатали данные, отсортированные по параметру Profit
PrintInfo("POS", Pos); // распечатали данные, отсортированные по параметру Pos
PrintInfo("SL", SL); // распечатали данные, отсортированные по параметру SLreturn;
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Alternate code:
Alternate code:
if(index>0 || index>8) return (-1);
Maybe if(index < 0 || ...) ...; ?
The second version of the code is really better ... and prettier
--
It's true ... when it's harder to maintain a size-optimized code than a blurry one.
i.e., written more broadly is sometimes easier to maintain...
--
In SQL it's upside down... code optimization
putting it into a single query even hurts
what's interesting ...
for example the SQL code of one complex query is harder to read than a few successive SQL queries
and as strange as it may seem, the performance of three simple queries is often better than the performance of one complex (seemingly optimized) query
The logic of those who write complex SQL queries... suffers... just because...
1 - inconvenient to maintain
2-slower working
--
don't apply to your code
that's just from experience...
Here's something I liked a lot... Taken from Igor Kim's thread, his first code:
... and his second:
How is it? It pleased me personally... :))Made an indicator. But when ZZCount>1 the terminal hangs up. It seems that there are no errors.
Maybe someone will find the cause?
You can be an old man, too.
Thank you very much!
Sometimes you need to sort the data in MQL4 without touching the data itself. There are no pointers in MQL4, and there are no structures either.
Here is an example of a script that sorts data by different parameters through emulation of pointers. Perhaps, someone will find this approach and the sorting function useful.
The result of the work: