Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1208

 
Maxim Kuznetsov:

But don't sort the data at random, without a global goal.

From the current project: we take a (short) array, the output is an index of elements in the right order:

void BubleSortIndex5(double &data[5],int &index[5])
{
   for(int i=0;i<5;i++)
      index[i]=i;
   for(int i=0;i<4;i++) {
      for(int j=1;j<5;j++) {
         if (data[index[i]]>data[index[j]]) {
            int tmp=index[i];
            index[i]=index[j];
            index[j]=tmp;
         }
      }
   }
}


for larger arrays we need to change sorting algorithm (bubbling doesn't work for larger arrays) - change it.

The main message is: don't touch the source data. Operate either with references or, even better, with array indices. Otherwise, the information will be lost, which will be badly needed later.

Thank you very much .

".....Operate either with links or, even better, with array ind ices. Otherwise information is lost, which will be needed later...."

This is the first time I've heard of reference operations. I would be grateful if you could tell me where I could read about it, in order to understand the difference between operating with references and operating with source data I don't remember such a topic in Kovalev's textbook.

 

Colleagues, please advise why the sound stops playing when the desired volume of the candle.

The sound file is in the SOUNDS folder, when I set the alert the file is playing normally, but there is no sound in the indicator.

Or, do you need a special folder with sounds for indicators?


/---- The main loop of indicator calculation

for(bar=limit; bar>=0 && !IsStopped(); bar--)
{
Range=(high[bar]-low[bar])/_Point;
IndBuffer[bar]=Range;

if(Range<5)
{
if (prev_calculated > 0 && Flag==0)
{
Flag=1;
}
}
if(Range>=Threshold){
clr=0;
if (prev_calculated > 0 && Flag==1 )
{
Flag=0;

PlaySound("zummer");


}
}

 
ANDREY:

Thank you very much for your quick response. In my case, each value of an array element is unique and exists in a single instance. That is, value 5, like other values, is not repeated.

In my case value 5 may not exist in an unsorted array. It means, some cells in unsorted array may be empty.
But if value 5 is not in unsorted array, then I cannot specify value 5 as second parameter in ArrayBsearch() function. Only values which necessarily exist in unsorted array get into this function.
Thank you for your help.

Why do you needArrayBsearch() if you don't intend to sort arrays? To find a number, all you need is a simple alternate comparison of the number you're looking for with the numbers in the cells of the array. If the number you're looking for isn't there, just return a fake number.

//+------------------------------------------------------------------+
//|                                                  FindInArray.mq4 |
//|                                       Copyright 2020, © Cyberdev |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, © Cyberdev"
#property version   "1.00"
#property strict

#property script_show_inputs

#define  size1 2 
#define  size2 10

input double value = 5;
input int index = 0;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int vIndex = -1;

bool searshValue(double & array2D[2][], const int _len, const int _index, const double _value) {
  int i;
  for(i = 0; i < _len; i++) {
    if(NormalizeDouble(array2D[_index][i], _Digits) == NormalizeDouble(_value, _Digits)) {
      vIndex = i;
      return true;
    }
  }
  return false;
}

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {
  double array[size1][size2] = {
    {10,9,8,7,6,5,4,3,2,1}, 
    {10,3,8,9,2,1,1,8,8,6}
  };
  
  if(searshValue(array, size2, index, value)) 
    Print("value1 array["+(string)index+"]["+(string)vIndex+"]: ", array[index][vIndex]);
  else
    Print("Value: "+(string)value+" not found!");
}
//+------------------------------------------------------------------+
 
Mihail Matkovskij:

Then why do you needArrayBsearch() if you don't want to sort arrays at all? To find a number you just need to compare the number you are looking for with the numbers in the cells of the array, one by one. If the number you're looking for isn't there, just return a fake number.

Thank you very much. Thanks to you I've learned useful information and enhanced my knowledge of MQL4

 
ANDREY:

Thank you very much. Thanks to you I have learned valuable information and broadened my horizons and knowledge about MQL4.

Glad I could help.

 
Mihail Matkovskij:

Then why do you needArrayBsearch() if you don't want to sort arrays at all? To find a number, all you need is a simple alternate comparison of the number you are looking for with the numbers in the cells of the array. If the number you're looking for isn't there, just return a false number.

Do I understand correctly that the function

searshValue ()

Not from MQL4 or even from MQL5 ?

 
Mihail Matkovskij:

Glad to be of help.

I wish there were more people like you...... who were happy to help

 
ANDREY:

Do I understand correctly that the function

Not from MQL4 or even MQL5 ?

Look carefully at the examplehttps://www.mql5.com/ru/forum/160683/page1208#comment_17279150 . You didn't find anything there ?

This function:

bool searshValue(double & array2D[2][], const int _len, const int _index, const double _value) {
  int i;
  for(i = 0; i < _len; i++) {
    if(NormalizeDouble(array2D[_index][i], _Digits) == NormalizeDouble(_value, _Digits)) {
      vIndex = i;
      return true;
    }
  }
  return false;
}
You should be a little more careful!
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
  • 2020.07.09
  • www.mql5.com
В этой ветке я хочу начать свою помощь тем, кто действительно хочет разобраться и научиться программированию на новом MQL4 и желает легко перейти н...
 

Hello, I need help, I have an account opened on this platform through a brokerage company that does not want to withdraw my funds, what should I do?

 
Ботагоз Битабарова:

Hello! I need help, on this platform opened an account for me, through a brokerage company that does not want to withdraw my funds, what to do?

This resource has nothing to do with brokerage companies.

Reason: