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

 

1.I have such a question, how can I delete an element of an array through memory, at the moment I delete an element by shifting the array mathematically through a loop, is it possible in mql4? If it is possible please give an example of how this is done on a one dimensional array.

2. Also, which way would be more high-performance, taking into account: if I delete via memory, cut out a segment with unnecessary elements, the array will reduce and its number will decrease by the value of deleted items, and in the following use of the array, we will have to restore the array to its original state; if I delete via a mathematical method, the processing of the cycle, which involves constant calculations to assign values to variables, which in turn affects the program?

 
Seric29:

1.I have such a question, how can I delete an element of an array through memory, at the moment I delete an element by shifting the array mathematically through a loop, is it possible in mql4? If it is possible please give an example of how this is done on a one dimensional array.

2. Also, which way will be more high-performance, taking into account that if you delete via memory, cut out an array with unnecessary elements, the array will reduce and its number will decrease by the value of deleted items, and in the following use of an array, we will have to restore the array to its original state; if you delete via a mathematical method, the processing of the cycle, which involves constant calculations to assign values to variables, which in turn affects the program?

Simply copy the array "into itself" and reduce the size of the array by the number of elements it doesn't need.

To insert a single element, simply increase the size, copy again "to itself" and paste the desired value into the free space.

 
Alexey Viktorov:

Simply copy the array "into itself" and reduce the size of the array by the number of unnecessary elements.

To insert a single element, simply increase the size, copy again "to itself" and paste the desired value in the free space.

I tried to insert a 3-dimensional array into the copy function, there are no errors, so this function can work with arrays of different dimensions or simply has duplicates for different dimensions. As it turns out, this function can be used instead of a shift function, no need to write your own, I wish I had thought of that earlier, how risky it is to copy an array to itself, it's written that the result may not be defined.

 
Seric29:

I tried to insert a 3-dimensional array into the copy function, no errors, so this function can work with arrays of different dimensions or simply has duplicates for different dimensions. As it turns out, this function can be used instead of a shift function, no need to write your own, I wish I had thought of that earlier, how risky it is to copy an array to itself, it's written that the result may not be defined.

When copying a multidimensional array, you have to consider the dimensionality of the second and subsequent dimensions. This determines how much you have to shift when copying. Simply put, as I understood in my experiments, all the values of the multidimensional array are lined up in "one row" and then lined up again in "column by..."

All in all, I can't retell the theory now. I'll have to check it again, if I need to use it.

 
Alexey Viktorov:

When copying a multidimensional array, the dimensionality of the second and subsequent dimensions must be taken into account. This determines how much shifting is needed when copying. Simply put, as I understood in my experiments, all values of a multidimensional array are lined up in "one row" and then lined up again in "column by...".

In general I can't recount the theory now. Again it will have to be checked if there is a need to use it.

In C++, there is no difference between this

   вывести в консоль massiv[0][0][0]
   или так
   вывести в консоль massiv[0]

in any of these cases there will be an output. Because they lie in one memory block and C++ accesses them directly, while in our shell memory access is closed and there's no way to correctly pass arrays of different dimension into a function, or address them this way, the only nuance is that in C++ multidimensional arrays are located in dynamic memory, maybe even scattered, although nobody has seen the electronic map. So, to copy multidimensional arrays by the concept in itself is a very subtle matter or it may not work correctly?

 
How can I programmatically determine whether I have logged into my account using my investment password or my trading password?
 

I have a code that is not executed in MQL5 in my indicator

void KValues(int i)
  {
   vhigh = 0; vlow = High[i];
   int limit = i + (int)kperiod;
   for(int a = i; a < limit; a++)
     {
      vhigh = ((price == STO_LOWHIGH ? High[a] : Close[a]) > vhigh ? (price == STO_LOWHIGH ? High[a] : Close[a]) : vhigh);
      vlow  = ((price == STO_LOWHIGH ? Low[a] : Close[a]) < vlow ? (price == STO_LOWHIGH ? Low[a] : Close[a]) : vlow);
     };
  }

The point is that ifprice == STO_LOWHIGH everything works correctly, but ifprice == STO_CLOSECLOSE the function assigns to static variables only

vhigh = 0; vlow = High[i];

... bypassing the loop

 
Alexandr Sokolov:

I have a code that is not executed in MQL5 in my indicator

The point is that ifprice == STO_LOWHIGH everything works correctly, but if price == STO_CLOSECLOSE the function assigns to static variables only

... bypassing the loop

Something is wrong with parentheses. In my opinion, they are not necessary here at all. None of them are necessary at all.

Or at least move the highlighted ones before the question mark to the left.

void KValues(int i)
  {
   vhigh = 0; vlow = High[i];
   int limit = i + (int)kperiod;
   for(int a = i; a < limit; a++)
     {
      vhigh = ((price == STO_LOWHIGH ? High[a] : Close[a]) > vhigh ? (price == STO_LOWHIGH ? High[a] : Close[a]) : vhigh);
      vlow  = ((price == STO_LOWHIGH ? Low[a] : Close[a]) < vlow ? (price == STO_LOWHIGH ? Low[a] : Close[a]) : vlow);
     };
  }

In general, you just need to understand that ?: operator is equivalent to if else

You have one condition twice. A condition like this would be enough

vhigh = price == STO_LOWHIGH ? High[a] : Close[a];
vlow  = price == STO_LOWHIGH ? Low[a] : Close[a];
Or I don't understand what you were trying to get at.
 
Alexey Viktorov:

There's something wrong with the brackets. In my opinion, they are not needed here at all. None of them are.

Or at least move the highlighted ones to the left before the question mark.

In general, you just need to understand that ?: operator is equivalent to if else

You have one condition twice. Such a condition would be enough.

Or I don't understand what you were trying to get at.

I want to get normal maxHigh and minLow stochastics within period K by Low/High and Close/Close

Low/High during initialization works fine, but Close/Close does not

 
Alexey Viktorov:

There's something wrong with the brackets. In my opinion, they are not needed here at all. None of them are.

Or at least move the highlighted ones to the left before the question mark.

In general, you just need to understand that ?: operator is equivalent to if else

You have one condition twice. Such a condition is enough.

Or I don't understand what you were trying to get at.

I didn't get it right away, but if you mean this.

void KValues(int i)
  {
   vhigh = 0; vlow = High[i];
   int limit = i + (int)kperiod;
   for(int a = i; a < limit; a++)
     {
      vhigh = ((price == STO_LOWHIGH) ? High[a] : Close[a] > vhigh ? (price == STO_LOWHIGH) ? High[a] : Close[a] : vhigh);
      vlow  = ((price == STO_LOWHIGH) ? Low[a] : Close[a] < vlow ? (price == STO_LOWHIGH) ? Low[a] : Close[a] : vlow);
     };
  }

it doesn't solve my problem.

Reason: