Hi guys,
How to improve this code?
"read all the array and gimme the two minimun/maximun values (and index)"
Hi Mindexperiment,
Have you seen the function ArraySort ?

- www.mql5.com
Yess but
ArraySort( daLows ); ArrayResize( daLows, 2 ); sObjName = sId+"Support"; ObjectMove( 0, sObjName, 0, daTimes[14], daLows[1] ); ObjectMove( 0, sObjName, 1, daTimes[52], daLows[0] );
I miss the index for the time
How can I get the low index?
I wrote this function
//+------------------------------------------------------------------+ //| ArraySortByValues.mqh | //| Copyright 2014, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, MetaQuotes Software Corp." #property link "http://www.mql5.com" double ArraySortByValues( double &A[] ) { double B[]; double R[2][2]; int size = ArraySize( A ); ArrayCopy( B, A ); ArraySort( B ); for ( int i=0; i<size; i++ ) { if ( A[i] = B[0] ) { R[0][0] = i; R[0][1] = A[i]; } if ( A[i] = B[1] ) { R[1][0] = i; R[1][1] = A[i]; } } return R; }
I'm having error on "return R"....... probably this is not the right sintax, which is the right one?
I wrote this function
I'm having error on "return R"....... probably this is not the right sintax, which is the right one?
Ok, without array
//+------------------------------------------------------------------+ //| ArraySortByValues.mqh | //| Copyright 2014, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, MetaQuotes Software Corp." #property link "http://www.mql5.com" struct strTline { double dLeftPrice; int iLeftIndex; double dRightPrice; int iRightIndex; }; strTline ArraySortByValues( double &A[] ) { double B[]; strTline tLine; int size = ArraySize( A ); ArrayCopy( B, A ); ArraySort( B ); for ( int i=0; i<size; i++ ) { if ( A[i] == B[0] ) { tLine.iLeftIndex = i; tLine.dLeftPrice = A[i]; } if ( A[i] == B[1] ) { tLine.iRightIndex = i; tLine.dRightPrice = A[i]; } } return tLine; }
Now I have this error:
"possible use of uninitialized variable 'tLine' ArraySortByValues.mqh 35 11" on "return tLine;"
Ok, without array
Now I have this error:
"possible use of uninitialized variable 'tLine' ArraySortByValues.mqh 35 11" on "return tLine;"
Rid of the warning, you can:
//+------------------------------------------------------------------+ //| ArraySortByValues.mqh | //| Copyright 2014, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, MetaQuotes Software Corp." #property link "http://www.mql5.com" struct strTline { double dLeftPrice; int iLeftIndex; double dRightPrice; int iRightIndex; }; strTline ArraySortByValues( double &A[] ) { double B[]; strTline tLine={0}; int size = ArraySize ( A ); ArrayCopy ( B, A ); ArraySort ( B ); for ( int i= 0 ; i<size; i++ ) { if ( A[i] == B[ 0 ] ) { tLine.iLeftIndex = i; tLine.dLeftPrice = A[i]; } if ( A[i] == B[ 1 ] ) { tLine.iRightIndex = i; tLine.dRightPrice = A[i]; } } return tLine; }

- 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 guys,
I need to sort an array by values... or at least find the 2 minimun/maximun values of a range of data...
I have the array (series array) daLow[100] correctly populated with the last 100 Low.
This is what I have done so far:
obviously daLows, daHighs and daTimes is correctly populated but as you can see this is not an elegant way to work.
How to improve this code?
"read all the array and gimme the two minimun/maximun values (and index)"