RFC: Push&Pull - first attempt at custom indicators :)

 
Hello world!

Just to test whether I'm able to code anything in MQL4, I wrote a pretty simple custom indicator (see below).

It defines 'push' as fraction of maximum gain during the period that is still kept at close, and then puts a MA over it. Similarly, 'pull' is for fraction of maximum loss.

(Disclaimer: please don't kill me if this has already been done by some guy back in 1978 :D)

So, it seems to work and even yield pretty interesting results... but some questions remain:

* how can I get the start of chart to display correctly (i.e., not display at all)?
* is there anything I've done wrong or could have done more efficiently?

Thank you in advance for the time you spent looking at this. :)

//+------------------------------------------------------------------+
//|                                                    Push-Pull.mq4 |
//|                                                     Drave Robber |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Drave Robber"
#property link      ""

#property indicator_separate_window
#property  indicator_buffers 4
#property indicator_minimum -0.1
#property indicator_maximum 1.1
#property indicator_color3 Yellow
#property indicator_color4 Blue

//---- input parameters

extern int       APeriod=21;

double TPushBuffer[];
double TPullBuffer[];
double PushBuffer[];
double PullBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
IndicatorBuffers(4);
SetIndexBuffer(0,TPushBuffer);
SetIndexBuffer(1,TPullBuffer);
SetIndexBuffer(2,PushBuffer);
SetIndexBuffer(3,PullBuffer);
SetIndexStyle(0,12);
SetIndexStyle(1,12);
SetIndexStyle(2,0);
SetIndexStyle(3,0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

for(int i=0; i<limit; i++)
 {
 if(Close[i]>Close[i+1]) TPushBuffer[i]=(Close[i]-Close[i+1])/(High[i]-Close[i+1]);
 else TPushBuffer[i]=0;
 if(Close[i]<Close[i+1]) TPullBuffer[i]=(Close[i+1]-Close[i])/(Close[i+1]-Low[i]);
 else TPullBuffer[i]=0;
 }

for(i=0; i<limit; i++)
 {
 PushBuffer[i]=iMAOnArray(TPushBuffer,0,APeriod,0,MODE_SMA,i);
 PullBuffer[i]=iMAOnArray(TPullBuffer,0,APeriod,0,MODE_SMA,i);
 }
    
//----
return(0);
}
//+------------------------------------------------------------------+
Reason: