- docs.mql4.com
Thank you, but the problem is when I change int to double so it reports errors
double num_array[5][2];
Is that not obvious? You are using the value of the "num_array_??" to serve as an index into the "pairs" array, so it has to result in a valid integer index.
Your original question was how to easily sort arrays of floating-point data-type. The answer is use "ArraySort".
Your question was not—"Can I index an array with a floating point value?" To which the answer would have been—No!
The two things are completely different and irrespective of each other.
What is it that you are trying to achieve? Explain in more detail so that we can give you advice.
Thank you for your quick responses.
I solved the problem, but it's my solution as a beginner not a programmer.
#define nl "\n" int OnInit() { EventSetMillisecondTimer(500); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { EventKillTimer(); } void OnTimer() { double eu,gu,uj,ac,an,num_array_de2[5][2],num_array_as2[5][2]; string pairs[]={"EURUSD", "GBPUSD", "USDJPY", "AUDCAD", "AUDNZD"}; string sp=" ",sp1=" ",sp2=" ",sp3=" "; int num_array_de[5][2],num_array_as[5][2]; eu=iRSI("EURUSD",_Period,14,PRICE_CLOSE,0);eu=NormalizeDouble(eu,2); gu=iRSI("GBPUSD",_Period,14,PRICE_CLOSE,0);gu=NormalizeDouble(gu,2); uj=iRSI("USDJPY",_Period,14,PRICE_CLOSE,0);uj=NormalizeDouble(uj,2); ac=iRSI("AUDCAD",_Period,14,PRICE_CLOSE,0);ac=NormalizeDouble(ac,2); an=iRSI("AUDNZD",_Period,14,PRICE_CLOSE,0);an=NormalizeDouble(an,2); ArrayInitialize(num_array_de,2);ArrayInitialize(num_array_de2,2); ArrayInitialize(num_array_as,2);ArrayInitialize(num_array_as2,2); num_array_de2[0][0]=eu;num_array_de[0][1]=0;num_array_as2[0][0]=eu;num_array_as[0][1]=0; num_array_de2[1][0]=gu;num_array_de[1][1]=1;num_array_as2[1][0]=gu;num_array_as[1][1]=1; num_array_de2[2][0]=uj;num_array_de[2][1]=2;num_array_as2[2][0]=uj;num_array_as[2][1]=2; num_array_de2[3][0]=ac;num_array_de[3][1]=3;num_array_as2[3][0]=ac;num_array_as[3][1]=3; num_array_de2[4][0]=an;num_array_de[4][1]=4;num_array_as2[4][0]=an;num_array_as[4][1]=4; ArraySort(num_array_de,WHOLE_ARRAY,0,MODE_DESCEND);ArraySort(num_array_de2,WHOLE_ARRAY,0,MODE_DESCEND); ArraySort(num_array_as,WHOLE_ARRAY,0,MODE_ASCEND);ArraySort(num_array_as2,WHOLE_ARRAY,0,MODE_ASCEND); Comment(nl+"RSI descending"+sp+"RSI ascending"+nl+"-----------------------"+sp1+"----------------------"+nl+ pairs[num_array_de[0][1]]+sp2+num_array_de2[0][0]+sp3+pairs[num_array_as[0][1]]+sp2+num_array_as2[0][0]+nl+ pairs[num_array_de[1][1]]+sp2+num_array_de2[1][0]+sp3+pairs[num_array_as[1][1]]+sp2+num_array_as2[1][0]+nl+ pairs[num_array_de[2][1]]+sp2+num_array_de2[2][0]+sp3+pairs[num_array_as[2][1]]+sp2+num_array_as2[2][0]+nl+ pairs[num_array_de[3][1]]+sp2+num_array_de2[3][0]+sp3+pairs[num_array_as[3][1]]+sp2+num_array_as2[3][0]+nl+ pairs[num_array_de[4][1]]+sp2+num_array_de2[4][0]+sp3+pairs[num_array_as[4][1]]+sp2+num_array_as2[4][0]); }
Ok, I'll explain. The first screen is a working example(the first code I posted), but it shows integers only. I need to see the decimal places and have everything correctly sorted as it is in the first screen.
Thank you, but the problem is when I change int to double so it reports errors
// cast the double to an int before using as an index // pairs[(int)num_array_de[0][1]]
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, can anyone advise how to make code to sort floating point variables as simple as this example for integers? Thanks