Indicator Need Help

 

Hi everyone,

I need some help with a construction indicator: the indicator name is: Life2 Moving Average

website is: http://www.visualchart.com/esxx/ayuda_F1/Indicators/Medias/ML2.htm

Here is my code, but I have a error in loop calculation.

#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_LINE);
   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;
          }
        
        Comment(Buffer.Avlife2[shift]);
        
        for (shift=limit; shift>=0; shift--)
          {
                  int i=periodo+1;
             
        while(i>1){
             Buffer.Avlife2[shift] = Buffer.Avlife2[shift] + Close[shift+i];
             i--;
             }
                  
          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]) {
               
               if(medium.price<medium.price.previous)
                   Buffer.Avlife2[shift]=(Buffer.Avlife2[shift+1])*(periodo-1)+(medium.price+DIF1)/periodo; //periodo-1 (is wrong I need other Loop, BUT HOW?)
               else
                   Buffer.Avlife2[shift]=Buffer.Avlife2[shift+1]-DIF;
          }
          
          
          double range.last=High[shift]+Low[shift];
          
          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)
                else
                   Buffer.Avlife2[shift]=Buffer.Avlife2[shift+1]+DIF;     
          }
          
          
  }

  }
//+------------------------------------------------------------------+
 
Potato:

Hi everyone,

I need some help with a construction indicator: the indicator name is: Life2 Moving Average

website is: http://www.visualchart.com/esxx/ayuda_F1/Indicators/Medias/ML2.htm

Here is my code, but I have a error in loop calculation.


Anyone?
 
What error you are getting.?? Also I dont see any Print command. It will help you in debugging and to see how control flows..
 
dineshydv:
What error you are getting.?? Also I dont see any Print command. It will help you in debugging and to see how control flows..


Hi,

Its not a Error in Code, I use Comment not Print for debugging.

The error is in calculation loop, because in the original formulas, when you see (1-p), I think, I should have one more loop for this value, but I can't figure out, how to make this second loop.

Sorry for my bad english.

 
Comment() is useless for debugging, because, you only have the last error
 
qjol:
Comment() is useless for debugging, because, you only have the last error


But I don't have any error in the code.

I have problems in translation this mathematical equation to the indicator.

I need help in this matter not in coding.

 
do u really think that Print() or Alert() is used only for debugging the code, u can use them to find out where u r wrong in the mathematic 2
 
qjol:
do u really think that Print() or Alert() is used only for debugging the code, u can use them to find out where u r wrong in the mathematic 2


ok, let's move, can you help me with the code?

 
 for (int shift=limit; shift>=0; shift--)
          {
          Buffer.Avlife2[shift]=0;
          }
        // At this point shift = -1 so what does your comment print?
        Comment(Buffer.Avlife2[shift]); 
 
WHRoeder:


My "shift" never goes to -1, because the loop "for" have shift>=0.
The comment show the last value inside de Buffer.AvLife2, when shift = 0;
 
Potato:

My "shift" never goes to -1, because the loop "for" have shift>=0.
The comment show the last value inside de Buffer.AvLife2, when shift = 0;
When does your loop exit ?