Recalculation of an indicator

 

Hi,

I want to programm an indicator which works with the function IndicatorCounted(), so that not every tick all values would be recalculated.

But in some special times it is necessary to recalucate all values. How can I reset the IndicatorCounted() function, like putting the indicator on the chart again?

 

Or another idea, how can I put all values from one indicator-buffer in another indicator-buffer??

 
sunshineh:

Hi,

I want to programm an indicator which works with the function IndicatorCounted(), so that not every tick all values would be recalculated.

But in some special times it is necessary to recalucate all values. How can I reset the IndicatorCounted() function, like putting the indicator on the chart again?

   bool bla.bla.bla;
   int counted_bars = IndicatorCounted();
   
   if (bla.bla.bla)
      {
      counted_bars = 0;
      }

I don't understand your next question.

 

Thanks. I wanted to recalculte because I wanted to chance the color of my indicator buffer at special conditions.

Therefore I have an indicator buffer 1 in red and another indicator buffer 2 in green. If my conditions changes, I want to put all my values from my red-buffer in my green buffer.

So perhaps I don't have to recalculate, but only to copy my buffer.

 
sunshineh:

Thanks. I wanted to recalculte because I wanted to chance the color of my indicator buffer at special conditions.

Therefore I have an indicator buffer 1 in red and another indicator buffer 2 in green. If my conditions changes, I want to put all my values from my red-buffer in my green buffer.

So perhaps I don't have to recalculate, but only to copy my buffer.

So copy all the values from one buffer to the other using a loop BUT also set the first buffer to a null value so that it doesn't print.

Alternatively just change the colour of the buffer. Normally people only change the colour of a piece of the indicator, so they need two buffers. If you want to change the whole buffer you should be able to just change the colour (which is much faster than copying the whole 100,000 bars (or however many there are in your chart).

 
sunshineh:

Thanks. I wanted to recalculte because I wanted to chance the color of my indicator buffer at special conditions.

Therefore I have an indicator buffer 1 in red and another indicator buffer 2 in green. If my conditions changes, I want to put all my values from my red-buffer in my green buffer.

So perhaps I don't have to recalculate, but only to copy my buffer.

Stewart has the same problem https://www.mql5.com/en/forum/139547 copying buffer is waste of time if you just want to change color.
 

Change the whole indicator's colour

This indicator code has been tested and works.

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Aqua

double wiggly[];

//+------------------------------------------------------------------------------------------+
int init(){
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, wiggly);
   return(0);
}
//+------------------------------------------------------------------------------------------+
int start(){
   static bool rise=false;

   int limit= Bars - IndicatorCounted() -1;
   if( limit < 1 )
       limit = 1;

   // This is just a test harness to show how to change the WHOLE indicator colour on demand.
   // To change only part of a line then you need to use two buffers, one for each colour.
   if( Close[1] > Open[1] ){
      if( !rise ){
         rise=true;
         SetIndexStyle(0,DRAW_LINE,EMPTY,EMPTY,Aqua);   // THIS IS THE IMPORTANT LINE
      }
   }
   else{
      if( rise ){
         rise=false;
         SetIndexStyle(0,DRAW_LINE,EMPTY,EMPTY,DeepPink);   // THIS IS THE IMPORTANT LINE TOO!
      }
   }
   
   // just some random wiggly indicator 
   for( int n=limit; n>=0; n-- ){
      wiggly[n] = (Time[n] % 7)*(1.0 + MathRand()/(3276.7));
   }

   return(0);
}
//+------------------------------------------------------------------------------------------+
 
 
onewithzachy:
Another sample https://www.mql5.com/en/forum/139547

Was that in the middle of a change?

      if (fast >= slow)
        {
        Fast_Above[pos] = fast;
        Fast_Below[pos] = fast; // EMPTY_VALUE
        Slow_Below[pos] = slow;
        Slow_Above[pos] = slow; // EMPTY_VALUE
        }
        else
        {
        Fast_Above[pos] = EMPTY_VALUE;
        Fast_Below[pos] = fast;
        Slow_Below[pos] = EMPTY_VALUE;
        Slow_Above[pos] = slow;
        }

The commented EMPTY_VALUEs in the top part of the if statement look suspect.

 
dabbler:

Was that in the middle of a change?

The commented EMPTY_VALUEs in the top part of the if statement look suspect.

It draws none, the lines not visibly crossed.
Reason: