Indicator Need Help - page 2

 
RaptorUK:
When does your loop exit ?


My loop exit when shift = -1, but the last value in the buffer show in comment is for shift = 0.

Anyone can help me to code the main problem? please

 

Your Comment is outside of the loop so it will show the value in the Buffer for position -1 which is not valid.

People are trying to help you to help yourself . . . start by adding useful debugging Print statements.

 
RaptorUK:

Your Comment is outside of the loop so it will show the value in the Buffer for position -1 which is not valid.

People are trying to help you to help yourself . . . start by adding useful debugging Print statements.

Thanks for your reply.

Ok, Print commands are in place, but the problem is the buffer goes to infinite, because the multiplication (p-1);

Can you help me?

//+------------------------------------------------------------------+
//|                                                      AvLife2.mq4 |


#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Gold      
#property indicator_color2 Red  

int periodo=6;

double Buffer.Avlife2[];
double Buffer.Media[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_NONE);
   SetIndexBuffer(0,Buffer.Avlife2);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Buffer.Media);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int counted_bars = IndicatorCounted();           
   
   if (counted_bars>0)
                counted_bars--;
        else
                counted_bars = 1;
        
        int limit = Bars - periodo;
        
        for (int shift=limit; shift>=0; shift--)
          {
          Buffer.Avlife2[shift]=0;
          }
        
        
        
        for (shift=limit; shift>=0; shift--)
          {
                  int i=periodo+1;
             
        while(i>1){
             Buffer.Avlife2[shift] = Buffer.Avlife2[shift] + Close[shift+i];
             i--;
             }
          
          Print(Buffer.Avlife2[shift]);
                  
          double DIF=MathAbs(High[shift]-Low[shift])/periodo;
          double DIF1=MathAbs(Close[shift]-Close[shift+1]);
          
          double medium.price = (High[shift]+Low[shift])/2;
          double medium.price.previous = (High[shift+1]+Low[shift+1])/2;
          
         
         
         
          if(medium.price>=Buffer.Avlife2[shift+1]) {
               
               Print("EXECUTED: 1ºIF // medium.price>=Buffer.Avlife2[shift+1]");
               if(medium.price<medium.price.previous){
                   Buffer.Avlife2[shift]=(Buffer.Avlife2[shift+1])*(periodo-1)+(medium.price+DIF1)/periodo; //periodo-1 (is wrong)
                   Print("EXECUTED: 1ºIF // IF medium.price>=Buffer.Avlife2[shift+1]. Buffer Value: ",Buffer.Avlife2[shift]);
                   }
               
               else{
                   Buffer.Avlife2[shift]=Buffer.Avlife2[shift+1]-DIF;
                   Print("EXECUTED: 1ºIF // ELSEIF Buffer.Avlife2[shift]=Buffer.Avlife2[shift+1]-DIF. Buffer Value: ",Buffer.Avlife2[shift]);
                   }
          }
          
          
          double range.last=High[shift]+Low[shift];
          
          if(medium.price<Buffer.Avlife2[shift+1]) {
                Print("EXECUTED: 2ºIF //medium.price<Buffer.Avlife2[shift+1]");
                
                if(range.last>medium.price.previous){
                   Buffer.Avlife2[shift]=(Buffer.Avlife2[shift+1])*(periodo-1)+(medium.price-DIF1)/periodo;//*(periodo-1)
                   Print("EXECUTED: 2º IF // range.last>medium.price.previous. Buffer Value: ",Buffer.Avlife2[shift]);
                   }
                   
                else{
                   Buffer.Avlife2[shift]=Buffer.Avlife2[shift+1]+DIF;
                   Print("EXECUTED: 2º ELSEIF // Buffer.Avlife2[shift+1]+DIF;. Buffer Value: ",Buffer.Avlife2[shift]);
                   }
          }
          
          
  }
 
Potato:

Thanks for your reply.

Ok, Print commands are in place, but the problem is the buffer goes to infinite, because the multiplication (p-1);

Can you help me?

Problem Solved. The mathematic equation are wrong.

Thanks to everyone.