Help with Gap formula

 

Hi, I´m trying to find the points value of a gap. I already wrote it, but it did not work. Could you show me please, where I'm doing a mistake?


//+------------------------------------------------------------------+
//|                                                  Gap Formula.mq4 |
//|                      Copyright © 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 1
#property indicator_color1 LawnGreen
#property indicator_color2 Red

// Input Parameters
extern double a1=50;
extern double a2=90;

// Buffers

double Gap1[];
double Gap2[];
double Gap[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Gap);

   

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

//---- last counted bar will be recounted
int counted_bars = IndicatorCounted();
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;

//---- Gap calculation 

for(int i = limit-1; i>=0; i--)// Count down for one pass    
  { 
   if(iOpen(NULL,0,0)>iHigh(NULL,0,1))
    {
      Gap1[i]=iOpen(NULL,0,0)-iHigh(NULL,0,1);
    }  
         else Gap1[i]=0;
  
   if(iOpen(NULL,0,0)<iLow(NULL,0,1))
    {
      Gap2[i]=iLow(NULL,0,1)-iOpen(NULL,0,0);
    }  
        else Gap2[i]=0;           
  
    Gap[i]=Gap1[i]+Gap2[i];
  }  
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

Any idea?


Thanks

 
gap1 and gap2 are not indexbuffers so must be manually resized
 
WHRoeder:
gap1 and gap2 are not indexbuffers so must be manually resized

Sorry, but what do you meant - "manually resized" ?


Thanks for your help.

Reason: