With MetaTrader Terminal ( MQL4
), I try to have a reversed array, that I append ( prepend ) items to.
So, on every tick, myArray[0]
becomes the 'newest' value, and the previous value shifts to myArray[1]
and so on.
But its harder then it sounds.
I tried like this ->
double myArray = []; // GLOBAL Dynamic array
extern int maxArrayLength = 50; // EXTERN iterable
// -----------------------------------------------------------------------
bool prependToReversedDoubleArray( double& theArray[], double value, int maxLength ) {
int size = ArraySize( theArray ); // LOCAL size
ArraySetAsSeries( theArray, false ); // Normalize the array ( left to right )
ArrayResize( theArray, size + 1 ); // Extend array length
Alert( "test = ", size );
theArray[size] = value; // Insert the new value
ArraySetAsSeries( theArray, true ); // Reverse the array again
if ( ArraySize( theArray ) > maxLength ) {
ArrayResize( theArray, maxLength );
}
return( true );
}
prependToReversedDoubleArray( myArray, 0.1234, maxArrayLength );