I made this little test code which copies the sizes of all candles in an array and sorts the array. Currently I am doing this with a normal loop. I was wondering if there is another way which might be more efficient using CopyRates(). The whole topic with CopyRates(), CopyBuffer() is a bit confusing sometimes and maybe someone can tell me how to use it in this case if necessary.
By the way, I am using the value in the middle of the sorted array as a volatility reference to measure if a candle is large. For me it is more suitable than using the ATR as a volatility reference.
void test() {
int allBars=iBars(_Symbol,_Period);
if (allBars<=0) return;
double buffer[];
if (ArrayResize(buffer,allBars)<0) return;
int limit=ArraySize(buffer);
for (int i=0;i<limit;i++) {
buffer[i]=iHigh(_Symbol,_Period,i)-iLow(_Symbol,_Period,i);
}
if (!ArraySort(buffer)) return;
Print(allBars," sorted.");
}
I made this little test code which copies the sizes of all candles in an array and sorts the array. Currently I am doing this with a normal loop. I was wondering if there is another way which might be more efficient using CopyRates(). The whole topic with CopyRates(), CopyBuffer() is a bit confusing sometimes and maybe someone can tell me how to use it in this case if necessary.
By the way, I am using the value in the middle of the sorted array as a volatility reference to measure if a candle is large. For me it is more suitable than using the ATR as a volatility reference.