strange indicator behaviour

 

Hi,

my indicator show a strange behaviour as the values of the Data-Window and the curves that are shown are not what it has calculated??

The structure of my indicator is as follows:

double indi[][20];
...
int start()  {
        static datetime tLastCalcBar=-1;
   int sz,b,iBarToCalc,counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars-1;

        if ( tLastCalcBar != Time[0] ) { 
                iBarToCalc = iBarShift(NULL, 0, tLastCalcBar);
                tLastCalcBar = Time[0];

                if ( counted_bars == 0 ) {// initialize indi[][]
                        sz = shiftBuffer(iBarToCalc, indi, Bars); // => indi[Bars][20]
                        b = Bars - 1;
                        iniIndi(indi, b); // => int iniIndi(double& i[][], int bar);  set the initial values 
                        iBarToCalc = b-2; // continue with the next empty bar
                        counted_bars = 1; // not to be caught in an endlessloop
                } else { // normal shift of the array
                        sz = shiftBuffer(iBarToCalc, indi);
                }

                for( b=iBarToCalc+1;b>0;b--){ // calc. one bar more (iBarToCalc+1) than necessary
                        buffer1[b] = buff1(indi[b+1][a]);
                        bubber2[b] = buff2(indi[b+1][b],indi[b+1][c]);
                        // ...
                } // end for( b=iBarToCalc+1;b>0;b--){
                // make every 10 min printout ot the buffers
                b=1;
                if ( Minute()%10 == 1 ) // m1-Chart at 11,21,31 print 10',20',30',..
                        Print(TimeToStr(Time[b]),"  b1 ",DoubleToStr(buffer1[b],Digits),"  b2 ",DoubleToStr(buffer2[b],Digits),"  b3 ",DoubleToStr(buffer3[b],Digits));
                
        } // end tLastCalcBar != Time[0] ) {
        // now the actual bar[0]
        b=0;
        buffer1[b] = buff1(indi[b+1][a]);
        bubber2[b] = buff2(indi[b+1][b],indi[b+1][c]);
        //...
        return(0);
}


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); // add or remove org. size always at the end
   if ( newSize > 0 ) ArrayResize(b, newSize); 
   int sz = ArrayRange(b,0);
   if ( ArrayResize(b, sz+add) <= 0) { Alert("DisableTrading(ArrayResize("+sz+add+") failed: " + GetLastError() );  return(-1); }
   // now b[sz]=>b[0], b[sz-1]=>b[1], ..
   ArraySetAsSeries(b, true);           // now b[sz]=>b[0], b[sz-1]=>b[1], ..
   // eliminate b[sz], last now as before b[sz-1]
   if ( ArrayResize(b, sz)   <= 0) { Alert("DisableTrading(ArrayResize(" +sz+ ") failed: " + GetLastError() );  return(-1); }
   return(sz);   // return new (and old) size
}


So what happens?
During last night every 10 min it printed out the buffer values (s.b. under printed)
But this morning the values of the Data-Window and the curves of the buffer (s.b. under Data-Window pre) differ totally from what was printed during the night.
At least the curves correspond to the values of the Data-Window.
But when I force the indicator to re-calc all its values by "open properties" and "OK" the are exactly as the were printed during the night, s.b. under Data-Window post.

Here the value example of 5:40 and 5:50 this morning at about 9:00:


Data-Window
pre
printed Data-Window post Data-Window
pre
printed Data-Window post








29.03.13
29.03.13 29.03.13
29.03.13

05:40
05:40 05:50
05:50

1,28265
1,28265 1,28253
1,28253

1,28268
1,28268 1,28255
1,28255

1,28262
1,28262 1,28251
1,28251

1,28267
1,28267 1,28252
1,28252

24
24 18
18
buffer1 -0,77 1,86 1,85 3,15 0,14 0,13
buffer2 0,34 0,02 0,02 0,32 -0,03 -0,03
buffer3 4,20 1,03 1,03 4,84 0,34 0,33


As you can see pre-recalc. at 5:40 buffer3=4.20, printed at that time was 1.03 and post-recalc. the Data-Windows now shows 1.03.

At least this tells me the calculation should be correct, but why mt4 (build 451) shows s.th. else?

Dos anybody has had similar experiences and knows what to do?


Thanks in advance,

Gooly

 
        static datetime tLastCalcBar=-1;
   int sz,b,iBarToCalc,counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars-1;

        if ( tLastCalcBar != Time[0] ) { 
                iBarToCalc = iBarShift(NULL, 0, tLastCalcBar);
                tLastCalcBar = Time[0];
  1. Drop your tLastCalcBar junk - unnecessary - as I previous posted.
  2. Drop your decrement - unnecessary - as I previous posted. Why did you start a new thead.
  3. Just do it like a normal indicator and add the buffer resize code - as I previous posted.
    double indi[][20];
    ...
    int start()  {
    //        static datetime tLastCalcBar=-1;
       int sz,b,iBarToCalc,counted_bars=IndicatorCounted();
    //---- check for possible errors
       if(counted_bars<0) return(-1);
    //---- last counted bar will be recounted
    // if(counted_bars>0) counted_bars--;
       int limit=Bars-counted_bars-1;
    
    //        if ( tLastCalcBar != Time[0] ) { 
    //                iBarToCalc = iBarShift(NULL, 0, tLastCalcBar);
    //                tLastCalcBar = Time[0];
    //
    //                if ( counted_bars == 0 ) {// initialize indi[][]
    //                      sz = shiftBuffer(iBarToCalc, indi, Bars); // => indi[Bars][20]
                            sz = shiftBuffer(0, indi, Bars); // => indi[Bars][20]
    //                        b = Bars - 1;
    //                        iniIndi(indi, b); // => int iniIndi(double& i[][], int bar);  set the initial values 
    //                        iBarToCalc = b-2; // continue with the next empty bar
    //                        counted_bars = 1; // not to be caught in an endlessloop
    //                } else { // normal shift of the array
    //                        sz = shiftBuffer(iBarToCalc, indi);
    //                }
    //
    //                for( b=iBarToCalc+1;b>0;b--){ // calc. one bar more (iBarToCalc+1) than necessary                
                      for( b=limit       ;b>0;b--){ // calc. all bars.

 
WHRoeder:
  1. Drop your tLastCalcBar junk - unnecessary - as I previous posted.
  2. Drop your decrement - unnecessary - as I previous posted. Why did you start a new thead.
  3. Just do it like a normal indicator and add the buffer resize code - as I previous posted.

Hi, WHRoeder

I want to check the way to be able to have more buffers than an indicator allows and I want to be able to transfer them into an EA, that's why I choose this way!

add 1) may be you haven't looked carfully, instead of your

for(int iBar = iBarShift(NULL,0, rcsAnalyzed); iBar >= 0; iBar--){  ... } rcsAnalyzed = Time[0];

I use (rcsAnayzed =>  tLastBarCalc, iBar => b):

if ( tLastCalcBar != Time[0] ) { // calBr[0] 
                iBarToCalc = intMin( BarsBack, iBarShift(NULL, 0, tLastCalcBar) );
for( b=iBarToCalc+1;b>0;b--){..} tLastCalcBar = Time[0];

it's pretty much the same - no?

add 2) Decremented is only b, the not-yet-calculated bars, this is exactly what you do yourself (..; iBar--) - so what do you mean?

add 3) Again I am using you suggestion!! Only that I added the option to have array-sizes less than Bars and to keep the size of the arrays constant.
Changing the size of an array cut or adds only at the end. I checked that and it worked.

So I did mainly what you proposed, I don' see your point.

Gooly

 
gooly:

I want to check the way to be able to have more buffers than an indicator allows and I want to be able to transfer them into an EA, that's why I choose this way!

So I did mainly what you proposed, I don' see your point.
  1. More buffers is irrelevant. You rewrote my ResizeBuffer() routine. You have your buffers. Your way does not work.
  2. I've tried 1, twice You just won't listen. You need to fill them out properly.
  3. You can not access the additional indicator buffers in the EA via iCustom(). If you really need them you'll have to move indicator into the EA like I posted. Or split the indicator into pieces.