What was wrong with my code ( modified Ichimoku indicator)

 

Hi everyone, I have modified the ichimoku indicator for my own trading style. There is no error but when running on charts, it return to MetaEditor immediately. I am new to this language so please help me. Thank you in advance.


//+------------------------------------------------------------------+

//|                                                     Ichimoku.mq4 |

//|                   Copyright 2005-2014, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright   "2005-2014, MetaQuotes Software Corp."

#property link        "https://www.mql5.com"

#property description "Ichimoku Kinko Hyo"

#property strict



#property indicator_chart_window

#property indicator_buffers 9

#property indicator_color1 Red          // Tenkan-sen

#property indicator_color2 Blue         // Kijun-sen

#property indicator_color3 SandyBrown   // Up Kumo

#property indicator_color4 Thistle      // Down Kumo

#property indicator_color5 Lime         // Chikou Span

#property indicator_color6 SandyBrown   // Up Kumo bounding line

#property indicator_color7 Thistle      // Down Kumo bounding line

#property indicator_color8 Pink          // Dao Gam 1

#property indicator_color9 White          // Dao Gam 2



//--- input parameters

input int InpTenkan=9;   // Tenkan-sen

input int InpKijun=26;   // Kijun-sen

input int InpSenkou=52;  // Senkou Span B

input int InpDaoGam1=64;

input int InpDaoGam2=129;

//--- buffers

double ExtTenkanBuffer[];

double ExtKijunBuffer[];

double ExtSpanA_Buffer[];

double ExtSpanB_Buffer[];

double ExtChikouBuffer[];

double ExtSpanA2_Buffer[];

double ExtSpanB2_Buffer[];

double ExtDaoGam1Buffer[];

double ExtDaoGam2Buffer[];

//---

int    ExtBegin;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

void OnInit(void)

  {

   IndicatorDigits(Digits);

//---

   SetIndexStyle(0,DRAW_LINE);

   SetIndexBuffer(0,ExtTenkanBuffer);

   SetIndexDrawBegin(0,InpTenkan-1);

   SetIndexLabel(0,"Tenkan Sen");

//---

   SetIndexStyle(1,DRAW_LINE);

   SetIndexBuffer(1,ExtKijunBuffer);

   SetIndexDrawBegin(1,InpKijun-1);

   SetIndexLabel(1,"Kijun Sen");

//---

   ExtBegin=InpKijun;

   if(ExtBegin<InpTenkan)

      ExtBegin=InpTenkan;

//---

   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DOT);

   SetIndexBuffer(2,ExtSpanA_Buffer);

   SetIndexDrawBegin(2,InpKijun+ExtBegin-1);

   SetIndexShift(2,InpKijun);

   SetIndexLabel(2,NULL);

   SetIndexStyle(5,DRAW_LINE,STYLE_DOT);

   SetIndexBuffer(5,ExtSpanA2_Buffer);

   SetIndexDrawBegin(5,InpKijun+ExtBegin-1);

   SetIndexShift(5,InpKijun);

   SetIndexLabel(5,"Senkou Span A");

//---

   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DOT);

   SetIndexBuffer(3,ExtSpanB_Buffer);

   SetIndexDrawBegin(3,InpKijun+InpSenkou-1);

   SetIndexShift(3,InpKijun);

   SetIndexLabel(3,NULL);

   SetIndexStyle(6,DRAW_LINE,STYLE_DOT);

   SetIndexBuffer(6,ExtSpanB2_Buffer);

   SetIndexDrawBegin(6,InpKijun+InpSenkou-1);

   SetIndexShift(6,InpKijun);

   SetIndexLabel(6,"Senkou Span B");

//---

   SetIndexStyle(4,DRAW_LINE);

   SetIndexBuffer(4,ExtChikouBuffer);

   SetIndexShift(4,-InpKijun);

   SetIndexLabel(4,"Chikou Span");

//---

   SetIndexStyle(8,DRAW_LINE);

   SetIndexBuffer(8,ExtDaoGam1Buffer);

   SetIndexDrawBegin(8,InpDaoGam1-1);

   SetIndexLabel(8,"DaoGam1");

//---

   SetIndexStyle(9,DRAW_LINE);

   SetIndexBuffer(9,ExtDaoGam2Buffer);

   SetIndexDrawBegin(9,InpDaoGam2-1);

   SetIndexLabel(9,"DaoGam2");   

     

//--- initialization done

  }

//+------------------------------------------------------------------+

//| Ichimoku Kinko Hyo                                               |

//+------------------------------------------------------------------+

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    i,k,pos;

   double high_value,low_value;

//---

   if(rates_total<=InpTenkan || rates_total<=InpKijun || rates_total<=InpSenkou|| rates_total<=InpDaoGam1 || rates_total<=InpDaoGam2)

      return(0);

//--- counting from 0 to rates_total

   ArraySetAsSeries(ExtTenkanBuffer,false);

   ArraySetAsSeries(ExtKijunBuffer,false);

   ArraySetAsSeries(ExtSpanA_Buffer,false);

   ArraySetAsSeries(ExtDaoGam1Buffer,false);

   ArraySetAsSeries(ExtDaoGam2Buffer,false);

   ArraySetAsSeries(ExtSpanB_Buffer,false);

   ArraySetAsSeries(ExtChikouBuffer,false);

   ArraySetAsSeries(ExtSpanA2_Buffer,false);

   ArraySetAsSeries(ExtSpanB2_Buffer,false);

   ArraySetAsSeries(open,false);

   ArraySetAsSeries(high,false);

   ArraySetAsSeries(low,false);

   ArraySetAsSeries(close,false);

//--- initial zero

   if(prev_calculated<1)

     {

      for(i=0; i<InpTenkan; i++)

         ExtTenkanBuffer[i]=0.0;

      for(i=0; i<InpKijun; i++)

         ExtKijunBuffer[i]=0.0;

      for(i=0; i<ExtBegin; i++)

        {

         ExtSpanA_Buffer[i]=0.0;

         ExtSpanA2_Buffer[i]=0.0;

        }

      for(i=0; i<InpSenkou; i++)

        {

         ExtSpanB_Buffer[i]=0.0;

         ExtSpanB2_Buffer[i]=0.0;

        }

       for(i=0; i<InpDaoGam1; i++)

         ExtDaoGam1Buffer[i]=0.0; 

        for(i=0; i<InpDaoGam2; i++)

         ExtDaoGam2Buffer[i]=0.0;   

     }

//--- Tenkan Sen

   pos=InpTenkan-1;

   if(prev_calculated>InpTenkan)

      pos=prev_calculated-1;

   for(i=pos; i<rates_total; i++)

     {

      high_value=high[i];

      low_value=low[i];

      k=i+1-InpTenkan;

      while(k<=i)

        {

         if(high_value<high[k])

            high_value=high[k];

         if(low_value>low[k])

            low_value=low[k];

         k++;

        }

      ExtTenkanBuffer[i]=(high_value+low_value)/2;

     }

//--- Kijun Sen

   pos=InpKijun-1;

   if(prev_calculated>InpKijun)

      pos=prev_calculated-1;

   for(i=pos; i<rates_total; i++)

     {

      high_value=high[i];

      low_value=low[i];

      k=i+1-InpKijun;

      while(k<=i)

        {

         if(high_value<high[k])

            high_value=high[k];

         if(low_value>low[k])

            low_value=low[k];

         k++;

        }

      ExtKijunBuffer[i]=(high_value+low_value)/2;

     }

//--- Dao Gam 1

   pos=InpDaoGam1-1;

   if(prev_calculated>InpDaoGam1)

      pos=prev_calculated-1;

   for(i=pos; i<rates_total; i++)

     {

      high_value=high[i];

      low_value=low[i];

      k=i+1-InpDaoGam1;

      while(k<=i)

        {

         if(high_value<high[k])

            high_value=high[k];

         if(low_value>low[k])

            low_value=low[k];

         k++;

        }

      ExtDaoGam1Buffer[i]=(high_value+low_value)/2;

      }

//--- Dao Gam 2

   pos=InpDaoGam2-1;

   if(prev_calculated>InpDaoGam2)

      pos=prev_calculated-1;

   for(i=pos; i<rates_total; i++)

     {

      high_value=high[i];

      low_value=low[i];

      k=i+1-InpDaoGam2;

      while(k<=i)

        {

         if(high_value<high[k])

            high_value=high[k];

         if(low_value>low[k])

            low_value=low[k];

         k++;

        }

      ExtDaoGam2Buffer[i]=(high_value+low_value)/2;

      }           

//--- Senkou Span A

   pos=ExtBegin-1;

   if(prev_calculated>ExtBegin)

      pos=prev_calculated-1;

   for(i=pos; i<rates_total; i++)

     {

      ExtSpanA_Buffer[i]=(ExtKijunBuffer[i]+ExtTenkanBuffer[i])/2;

      ExtSpanA2_Buffer[i]=ExtSpanA_Buffer[i];

     }

//--- Senkou Span B

   pos=InpSenkou-1;

   if(prev_calculated>InpSenkou)

      pos=prev_calculated-1;

   for(i=pos; i<rates_total; i++)

     {

      high_value=high[i];

      low_value=low[i];

      k=i+1-InpSenkou;

      while(k<=i)

        {

         if(high_value<high[k])

            high_value=high[k];

         if(low_value>low[k])

            low_value=low[k];

         k++;

        }

      ExtSpanB_Buffer[i]=(high_value+low_value)/2;

      ExtSpanB2_Buffer[i]=ExtSpanB_Buffer[i];

     }

//--- Chikou Span

   pos=0;

   if(prev_calculated>1)

      pos=prev_calculated-1;

   for(i=pos; i<rates_total; i++)

      ExtChikouBuffer[i]=close[i];

//---

   return(rates_total);

  }

//+------------------------------------------------------------------+
 
Lam Tran: it return to MetaEditor immediately.
Nothing "returns to the editor." The editor just compiles. Then you have to put it on a chart.
 
whroeder1:
Nothing "returns to the editor." The editor just compiles. Then you have to put it on a chart.

I have put it on chart, nothing appears. Please kindly check !

 
2018.08.03 13:24:53.700    testIndi AUDCAD,M15: array out of range in 'testIndi.mq4' (307,26)
Reason: