Questions from Beginners MQL4 MT4 MetaTrader 4 - page 195

 
Artyom Trishkin:

Find the point at which price crosses the MA upwards. This will be the start of the search range.

Find the point at which price crossed the MA downwards. This would be the stop range.

Take iHighest() only in this range.

And how to implement a search for MA points, so that it searches only 2 extreme points and not to infinity. in words I understand it too, but if it's not difficult how to implement it in code.
 
GlaVredFX:
And how to implement search for MA points, so that only 2 extreme points are searched and not to infinity. I understand it too, but if it's not difficult how to implement it in the code.

One way: create a variable at global EA program level (declare a variable in EA header) - in this variable write the opening time of bar at which the last crossing was made. This will help to use the third form of call ofCopyBuffer:

The reference of start and end dates of the required time interval

int  CopyBuffer(
   int       indicator_handle,     // handle индикатора
   int       buffer_num,           // номер буфера индикатора
   datetime  start_time,           // с какой даты
   datetime  stop_time,            // по какую дату
   double    buffer[]              // массив, куда будут скопированы данные
   );

Here start_time is just the time from our variable, and stop_time is the time of the last known quote of the server.

Документация по MQL5: Доступ к таймсериям и индикаторам / CopyBuffer
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyBuffer
  • www.mql5.com
Отсчет элементов копируемых данных (индикаторный буфер с индексом buffer_num) от стартовой позиции ведется от настоящего к прошлому, то есть стартовая позиция, равная 0, означает текущий бар (значение индикатора для текущего бара). При копировании заранее неизвестного количества данных в качестве массива-приемника buffer[] желательно...
 
GlaVredFX:
And how to implement the search of points of the MA, so that it would look for only 2 outer ones, and not to infinity. In words I understand it too, but if it is not difficult how to implement it in the code.

You have to go through the loop until you find a move away from the MA.

One point, this section highlighted by the yellow rectangle, will interrupt the loop before it reaches the second crossover between the price and the MA. The maximum will be found at the first right crossover


P.S. What is the difference between the highlighted 2 areas?

 
Vitaly Muzichenko:

P.S. What is the difference between the highlighted 2 areas?

They may be different - namely the first point may be higher or lower than the second point.

This is just an example. But it does not mean that they will always be identical.



Who can throw examples of code with similar conditions..:

Current value of MA> 0 bar.
Looking for Bar number, Price<MA, found number 1 bar, write value to buffer 2
Looking fornext number Price>MA found number 2 bar, write value to buffer 1.
Stop search.
Then between the values of buffer 1 and 2 look for the lowest price Low.
If Current MA value < 0 bar
Looking for the number of bar, Price>MA, found the number of 1 bar, write the value in buffer 2
Looking fornext number Price<MA found number 2 bar, write value to buffer 1.
Stop search.
Then between the values of buffer 1 and 2 we look for the highest price High.

 
GlaVredFX:

They may be different - the first point may be higher or lower than the second point.

It's just an example. But it does not mean that they will always be the same.



Who can throw examples of code with similar conditions..:

The current value MA> 0 bar
We are looking for the bar number, Price <MA, we have found the number of 1 bar and we write the value into buffer 2
Looking fornext number Price>MA found number 2 bar, write value to buffer 1.
Stop search.
Then between the values of buffer 1 and 2 look for the lowest price Low.
If Current MA value < 0 bar
Looking for the number of bar, Price>MA, found the number of 1 bar, write the value in buffer 2
Looking fornext number Price<MA found number 2 bar, write value to buffer 1.
Stop search.
Then between the values of buffer 1 and 2 we look for the highest price High.

If we follow the image, we have to start a loop and search until the condition MA<Value is found.

Once this is found, we fill the array with High prices. We run the cycle until the condition MA>Price is found, as soon as we find this place - we break the cycle.

Well, in the array looking for peak prices

 
Vitaly Muzichenko:

If you follow the image, you should run a loop and search until the condition MA<Value is found.

Once this is found, we fill the array with High prices. We run the cycle until the condition MA>Price is found, once we have found the place, we break the cycle.

Then we look for the peak prices in the array.

You're right and I also wrote it the same way, but how to implement it in the code, you can at least give us a code example of this :


start a loop and do a search until the condition MA<Price is found.

As soon as it is found,we fill the array with prices High

Документация по MQL5: Операции с массивами / ArrayFill
Документация по MQL5: Операции с массивами / ArrayFill
  • www.mql5.com
При вызове функции ArrayFill() всегда подразумевается обычное направление индексации – слева направо, то есть изменение порядка доступа к элементам массива с помощью функции ArraySetAsSeries() не принимается во внимание. Многомерный массив при обработке функцией ArrayFill() представляется одномерным, например...
 
GlaVredFX:

That's right and that's how I wrote it, but how to implement it in Code can you at least give a code example of this :


run a loop and do a search until the condition MA<Price is found.

As soon as this condition is found,we fill the array with prices High

I can't write the code now, maybe someone else will write it - it's simple

 

This is what is needed, can someone help with this code.

int start()                           

  {

  int    i;

  double No_1;

  double No_2;

  double k=iClose(NULL,0,i);
  double h=iHigh(NULL,0,i);

  if (ma>k) ma=iMA(NULL,0,24,0,1,0,i);

  for (i=0; i< Bars; i++) {

  //---- Код поиска номер крайнего бара где  iHigh>ma

  //---- Если нашли то возвращаем номер бара No_1

            

          }

Then find next value where iLow>ma and return bar number No_2 .
Stop search and use iHighest function to find vertex between these bars
int val_index=iHighest(NULL,0,MODE_HIGH,No_2,No_1);

 
GlaVredFX:

if (ma>k) ma=iMA(NULL,0,24,0,1,0,i);

This is not MQL5 code.

 
Vladimir Karputov:

This is not MQL5 code.

This is a layout, there is no difference between 4 and 5

:)
Reason: