Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1496

 
maxvoronin74 #:

Thanks for the tip. I didn't know. I'm inserting this line just in case.

Do I understand your joke correctly that rates have all prices averaged and take the bar into account, but ticks do not? That's why I took tick to use an arbitrary time interval, not bar prices. CopyRates in my similar formula filled the copied variable with the maximum value of ulong type for the hour interval. I could not solve this problem either.

Everything is wrong.

MqlRates is a structure, and you treat it as a variable.

MqlTick is also a structure.

You are trying to combine warm and soft, so the compiler does not understand you.

Neither do I)))))

Perhaps I could suggest something useful, but it is not clear from your code what you are trying to find.

 
Aleksandr Slavskii #:

It's all wrong.

MqlRates is a structure, and you treat it as a variable.

MqlTick is also a structure.

You are trying to combine warm and soft, so the compiler does not understand you.

Neither do I))))

Perhaps I could suggest something useful, but it is not clear from your code what you are trying to find.

The task is to modify WPR (Williams Percent Range) so that to get the difference of WPR values for an arbitrary period of time, regardless of bars.
 
maxvoronin74 #:
The task is to modify WPR (Williams Percent Range) so that to get the difference of WPR values for an arbitrary period of time, regardless of bars.

It is possible (but not certain) that this is what you wanted to get.

   MqlTick ticks[];
   int copied = CopyTicksRange(Symbol(), ticks, COPY_TICKS_INFO, t0, t1);
   double bid[];
   for(int i = 0; i < copied; i++)
      bid[i] = ticks[i].bid;
   double PrevClose = bid[copied - 1]; // Получаем последний элемент массива как значение PrevClose
   double highestHigh = ArrayMaximum(bid, 0, copied); // Находим максимальное значение в массиве ticks
   double lowestLow = ArrayMinimum(bid, 0, copied); // Находим минимальное значение в массиве ticks
 
Aleksandr Slavskii #:
double lowestLow = ArrayMinimum(bid, 0, copied);

Thank you. Here is what I got, if I understood the lesson correctly:

MqlTick ticks[];
int copied=CopyTicksRange(Symbol(),ticks,COPY_TICKS_INFO,t0,t1);
double bid_arr[];
double ask_arr[];
for(int i = 0; i < copied; i++)
{
   bid_arr[i] = ticks[i].bid;
   ask_arr[i] = ticks[i].ask;
}
double highestBid = ArrayMaximum(bid_arr, 0, copied-1);
double lowestBid = ArrayMinimum(bid_arr, 0, copied-1);
double highestAsk = ArrayMaximum(ask_arr, 0, copied-1);
double lowestAsk = ArrayMinimum(ask_arr, 0, copied-1);
double highestHigh = (highestBid+highestAsk)/2; // Средняя наибольшего ask и наибольшего bid элемента
double lowestLow = (lowestBid+lowestAsk)/2; // Средняя наименьшего ask и наименьшего bid элемента
double PrevClose = (bid_arr[copied-1]+ask_arr[copied-1])/2; // Средняя ask и bid последнего элемента
double WPR_Past = -100 * (NormalizeDouble((highestHigh - PrevClose) / (highestHigh - lowestLow),_Digits)); // Формула предыдущего WPR
But, unfortunately, on the line bid_arr[i] = ticks[i].bid; the Expert Advisor got off the chart because of array out of range in 'namemyexpert.mq5' (204,12).
 
maxvoronin74 #:

Thank you. Here's what came out, if I've learnt my lesson correctly:

Since we are looping through all ticks anyway, we can not copy in this loop, but look for the maximum-minimums at once.

By the way, if we copy, it would be good to first set the sizes of the arrays where we copy, the loop will not do it for us, we will fly out of the array at the first iteration. Only CopyTicksRange will resize the target array itself.

 
JRandomTrader #:

Since we cycle through all ticks anyway, we can not copy in this cycle, but look for those maximum-minimums at once.

By the way, if we copy, it would be good to first set the sizes of the arrays where we copy, the loop will not do it for us, we will fly out of the array at the first iteration. Only CopyTicksRange will resize the target array itself.

I am a perfectionist, sorting separate elements of an array of structures is like hitting glass with Styrofoam.
About the unallocated array, I have a good reason. It's one o'clock in the morning and my wife is in my ear saying "it's time to sleep, it's time to sleep". ))))))
 
Aleksandr Slavskii #:
I'm a perfectionist, sorting individual elements of an array of structures is like hitting glass with Styrofoam.
About not distributed array, I have a good reason. The time is one o'clock in the morning and my wife is in my ear with the words "it's time to sleep, it's time to sleep". ))))))
What, night or morning one fig).
Yes, you are right about looking for the maximum at once. It's much more convenient that way. I'm a bit dumb this morning.
 
JRandomTrader #:

Since we cycle through all ticks anyway, we can not copy in this cycle, but look for those maximum-minimums at once.

By the way, if we copy, it would be good to first set the sizes of the arrays where we copy, the loop will not do it for us, we will fly out of the array at the first iteration. Only CopyTicksRange will resize the target array itself.

Sorry. My inattention. Corrected. Thanks. I forgot that the ArrayMaximum value is an index, not a price. But it's fixed now.

MqlTick ticks[];
int copied=CopyTicksRange(Symbol(),ticks,COPY_TICKS_INFO,t0,t1);
double bid_arr[];
ArrayResize(bid_arr,copied,100000);
double ask_arr[];
ArrayResize(ask_arr,copied,100000);
for(int i = 0; i < copied; i++)
{
   bid_arr[i] = ticks[i].bid;
   ask_arr[i] = ticks[i].ask;
}
int IndMaxBid = ArrayMaximum(bid_arr, 0, copied-1); // Индекс элемента массива bid_arr с максимальной ценой
double highestBid = bid_arr[IndMaxBid]; // Самая высокая цена bid за период
int IndMinBid = ArrayMinimum(bid_arr, 0, copied-1); // Индекс элемента массива bid_arr с минимальной ценой
double lowestBid = bid_arr[IndMinBid]; // Самая низкая цена bid за период
int IndMaxAsk = ArrayMaximum(ask_arr, 0, copied-1); // Индекс элемента массива ask_arr с максимальной ценой
double highestAsk = ask_arr[IndMaxAsk]; // Самая высокая цена ask за период
int IndMinAsk = ArrayMinimum(ask_arr, 0, copied-1); // Индекс элемента массива ask_arr с минимальной ценой
double lowestAsk = ask_arr[IndMinAsk]; // Самая низкая цена ask за период
double highestHigh = (highestBid+highestAsk)/2; // Средняя наибольшего ask и наибольшего bid элемента
double lowestLow = (lowestBid+lowestAsk)/2; // Средняя наименьшего ask и наименьшего bid элемента
double PrevClose = (bid_arr[copied-1]+ask_arr[copied-1])/2; // Средняя ask и bid последнего элемента
double WPR_Past = -100 * (NormalizeDouble((highestHigh - PrevClose) / (highestHigh - lowestLow),_Digits)); // Формула предыдущего WPR

Since ArrayMaximum didn't work with the ticks array, I tried alternative calculations, with if in a loop. Why is that better?

 
maxvoronin74 #:

Why is it better?

   MqlTick ticks[];
   int copied = CopyTicksRange(Symbol(), ticks, COPY_TICKS_INFO, t0, t1);
   double highestHigh = 0, lowestLow = DBL_MAX;
   for(int i = 0; i < copied; i++)
     {
      if(highestHigh < ticks[i].ask) // Находим максимальное значение в массиве ticks
         highestHigh = ticks[i].ask;
      if(lowestLow > ticks[i].bid) // Находим минимальное значение в массиве ticks
         lowestLow = ticks[i].bid;
     }
 
Aleksandr Slavskii #:
Thank you.
Reason: