Mohon bantuan master koding MQL4.
Bagaimana cara sorting two dimensional array dari highest ke lowest dan kemudian ambil 3 nilai yg tertingginya?
Saya sudah coba tapi masih error, mohon bantuannya....
Bagaimana cara sorting two dimensional array dari highest ke lowest dan kemudian ambil 3 nilai yg tertingginya?
Saya sudah coba tapi masih error, mohon bantuannya....
Code:
int start()
{
int tHour=0, count=0, indxcount=0, price=0, indx=0;
datetime thisbartime = 0;
double myArray[][2];
double dOpen;
for (int i=0; i<500; i++)
{
//Inside main loop, add condition here to check for Hour = 0
tHour = TimeHour(iTime(NULL,60,iBarShift(NULL,60,thisbartime)));
//start at hour zero
if(tHour == 0 )
if(thisbartime!=Time[0])
{
thisbartime=Time[0];
//then
ArrayResize(myArray, 500, 0);
}
//set up another "for loop" length = 24 candles
//use 24 as there are 24 candles in a day for H1 TF
for(int j=0; j<24; j++)
{
//populate the array with the bar index
//those are the 2 dimensions array
dOpen = Open[i];
}
//need a counter to keep track of where we are in the candle array
//going right to left so indxcount=i+j
//also we will need and int to populate the array
//count
myArray[count][0] = Open[indxcount];
myArray[count][1] = indxcount;
//then increment after each element
count++;
//then sort the array
ArraySort(myArray, WHOLE_ARRAY, 0, MODE_DESCEND);
}
}
//set up a second "for loop" with the length equal to the number of highs you want to display on the chart with lines etc.
for (int k=0; k < 3; k++)
{
//then read the array elements
price = myArray[k][0];
indx = myArray[k][1];
}
//And call the draw trend line function using price and candle index as parameters to draw the trend line
double dOpen=Open[i];
if (i==Bars-1 || myArray>Open[i+1])
{
UpColor[i]=myArray;
DownColor[i]=0.0;
}
else
{
UpColor[i]=0.0;
DownColor[i]=myArray;
}
}
return(0);
}