[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 366

 

Good afternoon!

Can you please tell me how to find 3 maxima (or minima) on a graph for a given period, remember them and use them for further calculations?

Or give me a link to the code.

I searched for the code on the forum, but it didn't work through a search.

Thank you.

 
LOA:

Good afternoon!

Can you please tell me how to find 3 maxima (or minima) on a graph for a given period, remember them and use them for further calculations?

Or give me a link to the code.

I searched for the code on the forum, but it didn't work through a search.

Thank you.


For example, I have set a period of one day on the Eurobucks. Open M15. Take a look at the screenshot below. Boundaries of the day are indicated by red vertical lines. The fractal indicator shows that there are more than three minimums and maximums in this interval. So how does the code you are looking for figure out which of these extrema you are looking for?

 
LOA:

Good afternoon!

Can you please tell me how to find 3 maxima (or minima) on a graph for a given period, remember them and use them for further calculations?

Or give me a link to the code.

I searched for the code on the forum, but it didn't work through search.

Thanks.

https://docs.mql4.com/ru/series/iHighest

https://docs.mql4.com/ru/series/iLowest
 

Vladimir and Vadim, thank you very much for your reply!

One maximum I find...

1.

mas_UP[]//array of upper extrema.

int index = iHighest(NULL,0,2,MODE_HIGH,20,i);
      double MAX = mas_UP[index];//первый максимум

2. or like this (with fractals)

int size_up=ArrayRange(mas_UP,0);
      for (s=i;s<=size_up;s++);
      int index=ArrayMaximum(mas_UP);
      double MAX = UP[s];

But how to proceed? I find it difficult (I am still learning)

I can think of a way of zeroing out the element that was found as a maximum and then scrolling through the same array again - it will find the second maximum, then the third one.....

if (MAX>0)
      int n=n+1; //счётчик экстремумов
      mas_UP[index]=0;

But I'm not sure that's the case.

 
LOA:

Vladimir and Vadim, thank you very much for your reply!

One max I find...

1.

2. or so (with fractals)

But how to proceed? I am at a loss (I am still learning).

I can think of a way to zero out the element that was found as a maximum, and then scroll through the same array again - find the second maximum, then the third.....

But I'm not sure that's the case.


So do you want the last three maxima on a given interval, or some other maxima?
 
drknn:

So do you want the last three maxima in a given interval, or any other maxima?


Three highs over the period, not the latest. Or rather, not necessarily the most recent.

 
LOA:


Three maxima in a period, not the last. Or rather, not necessarily the last ones.


Oh. Well, I'll give you the full challenge.

There is a given time interval. Three sample maxima from this interval are needed.

To solve this problem you will need the following things:

- An algorithm for recognizing the boundaries of a given interval

- An algorithm for finding maxima

- An algorithm for recognizing the desired maxima from the maxima found.

P.S.

Since you do not know beforehand what maxima will be needed and how exactly the maxima will be identified, you will not find the ready-made code. This means that solving the above problems in sequence will give you exactly the code you need.

 
drknn:


Oh, boy. Well, I'll give you the whole problem.

There is a given time interval. You need three sample maxima from this interval.

To solve this problem you will need the following things:

- An algorithm for recognizing the boundaries of a given interval

- An algorithm for finding maxima

- An algorithm for recognizing the proper maxima from the maxima found.


Correctly formulated problem is almost a solution. Thank you.

With the first one I can handle, the second - also. But the last point - I honestly do not know, but I will think.

int n=0;//счётчик максимумов
      if (MAX>0)
      int n=n+1;
      mas_UP[index]=0;

Is this option the right idea, or should I dig in a different direction, i.e.

zero out the array element that was found as a maximum, and then scroll through the same array again - we will find the second maximum, then the third.....

 
LOA:


A correctly formulated problem is almost a solution. Thank you.

I can deal with the first one, the second one too. The last point - I honestly do not know, but I will think about it.

Is this the right idea, or do I dig in a different direction, i.e.

zero the element of array, which was found as maximum, and then scroll through the same array again - we will find the second maximum, then the third.....


Don't be at all interested in the code right now - make an algorithm - how exactly should the program? Otherwise you will stagnate. Any program is a dumbass - it needs precise instructions. In order to do this, we need to know exactly what the program is supposed to do. And only then can we choose how to put it into program code.
 
drknn:

You may not be interested in the code at all now - make an algorithm - exactly how the program should be done. Otherwise you will stagnate in place. Any program is a dumbass - it needs precise instructions. In order to do this, we need to know exactly what the program is supposed to do. And only then can we choose how to put it into program code.

Ok. We will have the algorithm tomorrow, because it's already half past two in the morning in St. Petersburg and we are out of energy.