[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 100

 
Zhunko:
WindowRedraw() redraws graphical objects. It has nothing to do with buffers.

Got it... If there is another way with redrawing?
 
kon12:

Got it... If another way with a redraw?
Show the code and you'll get an immediate answer.
 
Lisi4ka330:


Good afternoon! Please help me with the ArrayMo function (it returns the maximum of the density curve).

double ArrayMo(double& x[], int d=4) {
  double e, s=0;
  double m[][2];             // временный массив:
                             //  столбец 1 - количество значений
                             //  столбец 2 - значения
  int    i, k=ArraySize(x);
  int    n;                  // номер строки временного массива m
  int    r;                  // количество строк во временном массиве m

  if (k>0) {
    for (i=0; i<k; i++) {
      e=NormalizeDouble(x[i], d);
      n=ArraySearchDouble(m, e);
      if (n<0) {
        r=ArrayRange(m, 0);
        ArrayResize(m, r+1);
        m[r][0]++;
        m[r][1]=e;
      } else m[n][0]++;
    }
    ArraySort(m, WHOLE_ARRAY, 0, MODE_DESCEND);
    s=m[0][1];
  } else Print("ArrayMo(): Массив пуст!");

  return(s);
}

The following questions have arisen:

1.What is the purpose of creating a temporary array

m[][2]

2. It's not clear what the values of the temporary array will be taken from, and therefore it's not clear how this array may be searched:

n=ArraySearchDouble(m, e)

3. And then generally for me the truth is deeply hidden))))) Once we have ascertained that there is no value, we begin to determine the size of the array of "unclear values".

I would be very grateful for a ray of light in this story))))


I don't think the function is written quite correctly after all. The main reason is that after the announcement.

double m[][2];

it is necessary

ArrayResize(m,0);

otherwise(I quote)

int ArrayResize( void array[], int new_size)
Sets the new size in the first dimension of the array. If successful, the function returns the number of all elements contained in the array after resizing, otherwise it returns -1 and the array does not resize.
!!!Note: an array declared locally in any function, which has been resized, will remain unchanged after the function is executed. When the function is called again, such an array will have a different size than the declared one!!!!

And thus with multiple calls the function will "fall in the past")

About how the algorithm works. The array m[][2] itself is a direct representation of empirical distribution of the number of hits of variable x[i] by its different values. That is, each element of the array consists of two numbers - the number of hits on some value (the first field) and the value itself. The loop searches for the same value in the array m for each x[i], and if it is found, the number field is added, otherwise a new element is created using ArrayResize() and our x[i] is written there.

Next, once the array is filled, we just need to find the element with the maximum number of hits, i.e., by definition, the modulus of distribution x.

This is done by strings

    ArraySort(m, WHOLE_ARRAY, 0, MODE_DESCEND);
    s=m[0][1];

Although it seems to me (not sure about the multidimensional array), you could have just

    s=m[ArrayMaximum(m)][1];

All in all I can say (with all due respect to the code's author) that even when correcting all the defects, this algorithm is extremely inefficient and can often give wrong results. The reason is that we are working with the type double, which means that the probability of x[i] values being close but still distinguishable is quite high. This may not be so noticeable when the sample size is much larger (hundreds of times or more) than the total number of intervals into which x[i] is defined. However, in the many cases where this constraint is not met, there will be a lot of wrong calculations.

The more correct way to calculate the mode is this: an empirical distribution function (not to be confused with the frequency distribution) is constructed, then it is interpolated from piecewise linear to smooth, and finally the point of maximum derivative is looked for. Such an algorithm is free of the drawbacks listed above and works quite effectively even with small sample sizes. At least, I had to solve just the task of finding a mode for samples of 50-100 elements with a comparable number of intervals using MQL - and everything was OK. The only disadvantage is that interpolations usually cause a significant drop in calculation speed, of course, if we want to smooth qualitatively.

 
Hello esteemed forum members, who can I speak to about writing an EA. An EA without indicators based on doubling on a move not in our direction.
 
Glazunov:
Hello esteemed forum members, who can I speak to about writing an EA. An EA without indicators based on doubling on a move not in our direction.
here: https://www.mql5.com/ru/job
 
ilunga:
here: https://www.mql5.com/ru/job

Thank you. Maybe there are more options.
 
Glazunov:

Thank you. Maybe there are more options.
Try typing "martingale" into a website search - you'd be surprised
 
YOUNGA:
Try typing "martingale" into a website search and you'll be surprised

Already looked! But what I want is missing(
 
Glazunov:
Hello esteemed forum members, who can I speak to about writing an EA. An EA without indicators based on doubling on a move not in our direction.


Have a look here

https://www.mql5.com/ru/forum/136747

 

Hello. I've just started in MQL4.

Please advise on the OrderModify function. The manuals and examples show that this function is used for trawling, i.e. change of stop loss. I need to change only take profit on an open order. Stop loss is not set when order is opened and must also remain at 0 during modification .

How should the calculation and selection of orders look like ?

The final target should look something like this

if (OrderType()==OP_BUY && OrderOpenPrice()-Bid>kof*Point) // there is a buy, but it has gone down by kof
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+tpnew*Point,0,CLR_NONE);// we move TP lower than the previously placed

The same for sell.

Thank you for any answers.