Custom indicator doesn't work properly

To add comments, please log in or register
Soft Farr
18
Soft Farr  

Hi. I'm making a CI which does not work properly. When debugging stops in "bool y=..." line in OnCalculate(). I tested some options for that line and found that instead functions (iBands), variables (Close[]), if I replace for numbers or constants, indicator works. I have to say that Indicator, in debug mode, starts, then JUST ENDS in line mentioned before. No errors, no messages, no warnings. JUST ENDS!!! No array overflow message...

Why is this? I attached code and images showing working and noWorking mode. MetaEditor is ver.5.00 build 2143 13/Sep/2019. MT4 is ver.4.00 build 1220 13/Sep/2019.

Thanks in advance.

#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Resistencia"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         Label0Buffer[];
int flechaArriba=233;
int flechaAbajo=234;
int flechaDiagArriba=236;
int flechaDiagAbajo=238;
int flechaHorizontal=232;
int punto=159;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   int j=0;
   j=1;
   SetIndexBuffer(j-1,Label0Buffer);
   SetIndexArrow(j-1, flechaAbajo);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int velasSinCalcular=rates_total-prev_calculated,i,j;
//----
   for(i=velasSinCalcular-1; i>=0; i--)
     {
      bool y=(Close[i+1]>=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,i+1) &&
         iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,i)>=Close[i] &&
         true);
      //bool y=(0.7>=0.699999999);
      Print(i,j);
      Label0Buffer[i]=High[i]+_Point;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Files:
working.jpg 514 kb
notWorking.jpg 500 kb
Keith Watford
Moderator
20380
Keith Watford  

Please edit your post and use the code button (Alt + S) to paste your code.

I have moved your post here to the MQL4 and MetaTrader 4 sub-forum. In future, please post in the relevant section.

   int velasSinCalcular=rates_total-prev_calculated,i,j;

//----

   for(i=velasSinCalcular-1; i>=0; i--)

     {

      bool y=(Close[i+1]>=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,i+1) &&

         iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,i)>=Close[i] &&

         true);



      Print(i,j);

      Label0Buffer[i]=High[i]+_Point;

     }

When i==rates_total-1,i+1=rates_total and this shift does not exist so you will get an Array out or range error.

William Roeder
20210
William Roeder  
int velasSinCalcular=rates_total-prev_calculated,
As Keith said,
          How to do your lookbacks correctly.
To add comments, please log in or register