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.
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]; // Получаем последний элемент массива как значение PrevClosedouble highestHigh = ArrayMaximum(bid, 0, copied); // Находим максимальное значение в массиве ticksdouble 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).
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.
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.
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?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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.
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.
It is possible (but not certain) that this is what you wanted to get.
double lowestLow = ArrayMinimum(bid, 0, copied);
Thank you. Here is what I got, if I understood the lesson correctly:
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).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.
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'm a perfectionist, sorting individual elements of an array of structures is like hitting glass with Styrofoam.
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.
Since ArrayMaximum didn't work with the ticks array, I tried alternative calculations, with if in a loop. Why is that better?
Why is it better?