Download MetaTrader 5

Hi, please help find error in code.

To add comments, please log in or register
barryvirtsetti
11
barryvirtsetti 2016.04.13 09:00 
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property strict
#property version "1.0"
#property  indicator_buffers 500

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
//---- input parameters

extern int       CountBars=300;
extern int       SSP=7;
extern double    Kmin=1.6;
extern double    Kmax=50.6;


//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE,0,2,Red);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,0,2,DodgerBlue);
   SetIndexBuffer(1,ExtMapBuffer2);

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

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

   if(CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+SSP);
   SetIndexDrawBegin(1,Bars-CountBars+SSP);
   int i,i2,loopbegin,counted_bars=IndicatorCounted();
   double SsMax,SsMin,K,val1,val2,smin,smax,price;

   if(Bars<=SSP+1) return(0);
//---- initial zero

//K=33-RISK; 

/*
if (firstTime==true)   { 
   loopbegin = CountBars; 
   if (loopbegin>(Bars-2*SSP+1)) loopbegin=Bars-2*SSP+1; 
   firstTime=False; 
}; рудимент старой программы 
*/
   if(Bars<=SSP+1) return(0);
//---- initial zero

//+++++++
   if(counted_bars<SSP+1)
     {
      for(i=1;i<=SSP;i++) ExtMapBuffer1[CountBars-i]=0.0;
      for(i=1;i<=SSP;i++) ExtMapBuffer2[CountBars-i]=0.0;
     }
//+++++++-SSP

   for(i=CountBars-SSP;i>=0;i--) 
     {

      SsMax = High[Highest(NULL,0,MODE_HIGH,SSP,i-SSP+1)];
      SsMin = Low[Lowest(NULL,0,MODE_LOW,SSP,i-SSP+1)];
      smin = SsMin-(SsMax-SsMin)*Kmin/100;
      smax = SsMax-(SsMax-SsMin)*Kmax/100;
      ExtMapBuffer1[i-SSP+6]=smax;
      ExtMapBuffer2[i-SSP-1]=smax;
      val1 = ExtMapBuffer1[0];
      val2 = ExtMapBuffer2[0];
      if(val1>val2) Comment("buy ",val1);

      if(val1<val2) Comment("sell ",val2);

     }



//----
   return(0);
  }
//+------------------------------------------------------------------+
Hi, please help find error in code. Error: array out of range in (88,17)
Marco vd Heijden
Moderator
4728
Marco vd Heijden 2016.04.13 09:38  
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property strict
#property version "1.0"
#property  indicator_buffers 500

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
//---- input parameters

extern int       CountBars=300;
extern int       SSP=7;
extern double    Kmin=1.6;
extern double    Kmax=50.6;


//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE,0,2,Red);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,0,2,DodgerBlue);
   SetIndexBuffer(1,ExtMapBuffer2);

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

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

   if(CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+SSP);
   SetIndexDrawBegin(1,Bars-CountBars+SSP);
   int i,i2,loopbegin,counted_bars=IndicatorCounted();
   double SsMax,SsMin,K,val1,val2,smin,smax,price;

   if(Bars<=SSP+1) return(0);
//---- initial zero

//K=33-RISK; 

/*
if (firstTime==true)   { 
   loopbegin = CountBars; 
   if (loopbegin>(Bars-2*SSP+1)) loopbegin=Bars-2*SSP+1; 
   firstTime=False; 
}; рудимент старой программы 
*/
   if(Bars<=SSP+1) return(0);
//---- initial zero

//+++++++
   if(counted_bars<SSP+1)
     {
      for(i=1;i<=SSP;i++) ExtMapBuffer1[CountBars-i]=0.0;
      for(i=1;i<=SSP;i++) ExtMapBuffer2[CountBars-i]=0.0;
     }
//+++++++-SSP

   for(i=CountBars-SSP;i>=0;i--) 
     {

      SsMax = High[Highest(NULL,0,MODE_HIGH,SSP,i-SSP+1)];
      SsMin = Low[Lowest(NULL,0,MODE_LOW,SSP,i-SSP+1)];
      smin = SsMin-(SsMax-SsMin)*Kmin/100;
      smax = SsMax-(SsMax-SsMin)*Kmax/100;
      int x=i-SSP+6;if(x<0){x=0;}      
      ExtMapBuffer1[x]=smax;
      int y=i-SSP-1;if(y<0){y=0;}
      ExtMapBuffer2[y]=smax;
      val1 = ExtMapBuffer1[0];
      val2 = ExtMapBuffer2[0];
      if(val1>val2) Comment("buy ",val1);

      if(val1<val2) Comment("sell ",val2);

     }



//----
   return(0);
  }
//+------------------------------------------------------------------+
barryvirtsetti
11
barryvirtsetti 2016.04.14 12:52  
Thank you
To add comments, please log in or register