Did you bother to look at my resizeBuffer that does both? Obviously not!
Decrement unnecessary. Did you bother to look at the link? Obviously not!
Thanky you WHRoeder for having so much patience with me. I wasn't aware that you use the 'side-effect' of ArrayResize that doesn't change the content of that array if possible.
But what still bothered me was that your solution continuously increases the size of the arrays been shifted. And the size of Bars in many time is not needed. So I tied to find a solution that make me feel better.
This solution uses your idea, shifts the content but the size if the array remains the same.
Of course the correct handing of this function differs now.
externint ArraySizeWanted = 1000;
double indi[];
int start() {
staticdatetime tLastCalcBar=-1;
int sz,b,iBarToCalc,counted_bars=IndicatorCounted();
//---- check for possible errorsif(counted_bars<0) return(-1);
//---- last counted bar will be recountedif(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars-1;
if ( tLastCalcBar != Time[0] ) { // calBr[0]
iBarToCalc = MathMin( ArraySizeWanted, iBarShift(NULL, 0, tLastCalcBar) );
tLastCalcBar = Time[0];
for( b=iBarToCalc;b>0;b--){ // only up to bar[1]if ( b == iBarToCalc ) {
if ( counted_bars < 1 ) // first time, array at size 0
sz = shiftBuffer(b, indi, ArraySizeWanted );
else
sz = shiftBuffer(b, indi);
} // end ini 'oldest' Bar(s) if ( counted_bars < 1 ) { // to set the ini. content
counted_bars = 1;
b--; // => b == sz-1
indi[b] = ini();
b--;
}
indi[b] = whatever( indi[b+1], ...);
}// end foreach Bar b
}// end newBar
b=0;
indi[b] = whatever( indi[b+1], ...);
// ...
} // start()
//////////////////////////////////////////////////////////////////////////////////////////int shiftBuffer(int add, double& b[], int newSize=0){ // buffer can be 1D or 2D, Shift values B[2]=B[1]; B[1]=B[0]ArraySetAsSeries(b, false);
if ( newSize > 0 ) ArrayResize(b, newSize); // add or remove org. size always at the endint sz = ArrayRange(b,0);
if ( ArrayResize(b, sz+add) <= 0) // add [sz]=0.0
{ Alert("DisableTrading(ArrayResize("+sz+1+") failed: " + GetLastError() ); return(-1); }
ArraySetAsSeries(b, true); // now b[sz]=>b[0], b[sz-1]=>b[1], ..if ( ArrayResize(b, sz) <= 0) // eliminate b[sz], last now b[sz-1]
{ Alert("DisableTrading(ArrayResize(" +sz+ ") failed: " + GetLastError() ); return(-1); }
return(sz); // return new (and old) size
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
How many times do you need to be told.
Thanky you WHRoeder for having so much patience with me.
I wasn't aware that you use the 'side-effect' of ArrayResize that doesn't change the content of that array if possible.
But what still bothered me was that your solution continuously increases the size of the arrays been shifted.
And the size of Bars in many time is not needed.
So I tied to find a solution that make me feel better.
This solution uses your idea, shifts the content but the size if the array remains the same.
Of course the correct handing of this function differs now.
Hope you don't mind,
thanks a lot anyway!
Gooly