English

## S/R in MQL recognition

 11 Lukas273 2016.01.29 22:01 #   I did the hard way... Below is the code which SHOULD BE capable of doing what I described above...However, it shows me error during backtest "Array out of Range." Unfortunately, I don't understand the explanation very well... I thought this line would solve it but it did not. (Bars > Number_of_candles)Any help? (I read what the error means but I dont get it) ```//+------------------------------------------------------------------+ //|                                           support_resistance.mq4 | //|                                                               LJ | //+------------------------------------------------------------------+ #property copyright "LJ" #property link      "lukas.janca@icloud.com" #property version   "1.00" #property strict input int Number_of_candles = 15; //Number of candles which are necessary to create S/R levels int OnInit() { Alert("EA is ON"); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) {   Alert("EA is OFF"); } void OnTick() { int static NewBar = Bars; if(NewBar != Bars && Bars > Number_of_candles) { NewBar = Bars; double static level_high; int PS = Number_of_candles+1; Print("Level High = ", level_high); if(High[PS] >= High[PS-1] && High[PS] >= High[PS+1])    {    if(PS-1 == 1)       {       level_high = High[PS];       }    if(High[PS] >= High[PS-2] && High[PS] >= High[PS+2])       {       if(PS-1 == 2)          {          level_high = High[PS];          }       if(High[PS] >= High[PS-3] && High[PS] >= High[PS+3])          {          if(PS-1 == 3)             {             level_high = High[PS];             }          if(High[PS] >= High[PS-4] && High[PS] >= High[PS+4])             {             if(PS-1 == 4)                {                level_high = High[PS];                }             if(High[PS] >= High[PS-5] && High[PS] >= High[PS+5])                {                if(PS-1 == 5)                   {                   level_high = High[PS];                   }                if(High[PS] >= High[PS-6] && High[PS] >= High[PS+6])                   {                   if(PS-1 == 6)                      {                      level_high = High[PS];                      }                   if(High[PS] >= High[PS-7] && High[PS] >= High[PS+7])                      {                      if(PS-1 == 7)                         {                         level_high = High[PS];                         }                      if(High[PS] >= High[PS-8] && High[PS] >= High[PS+8])                         {                         if(PS-1 == 8)                            {                            level_high = High[PS];                            }                         if(High[PS] >= High[PS-9] && High[PS] >= High[PS+9])                            {                            if(PS-1 == 9)                               {                               level_high = High[PS];                               }                            if(High[PS] >= High[PS-10] && High[PS] >= High[PS+10])                               {                               if(PS-1 == 10)                                  {                                  level_high = High[PS];                                  }                               if(High[PS] >= High[PS-11] && High[PS] >= High[PS+11])                                  {                                  if(PS-1 == 11)                                     {                                     level_high = High[PS];                                     }                                  if(High[PS] >= High[PS-12] && High[PS] >= High[PS+12])                                     {                                     if(PS-1 == 12)                                        {                                        level_high = High[PS];                                        }                                     if(High[PS] >= High[PS-13] && High[PS] >= High[PS+13])                                        {                                        if(PS-1 == 13)                                           {                                           level_high = High[PS];                                           }                                        if(High[PS] >= High[PS-14] && High[PS] >= High[PS+14])                                           {                                           if(PS-1 == 14)                                              {                                              level_high = High[PS];                                              }                                           if(High[PS] >= High[PS-15] && High[PS] >= High[PS+15])                                              {                                              if(PS-1 == 15)                                                 {                                                 level_high = High[PS];                                                 }                                              if(High[PS] >= High[PS-16] && High[PS] >= High[PS+16])                                                 {                                                 if(PS-1 == 16)                                                    {                                                    level_high = High[PS];                                                    }                                                 if(High[PS] >= High[PS-17] && High[PS] >= High[PS+17])                                                    {                                                    if(PS-1 == 17)                                                       {                                                       level_high = High[PS];                                                       }                                                    if(High[PS] >= High[PS-18] && High[PS] >= High[PS+18])                                                       {                                                       if(PS-1 == 18)                                                          {                                                          level_high = High[PS];                                                          }                                                       if(High[PS] >= High[PS-19] && High[PS] >= High[PS+19])                                                          {                                                          if(PS-1 == 19)                                                             {                                                             level_high = High[PS];                                                             }                                                          if(High[PS] >= High[PS-20] && High[PS] >= High[PS+20])                                                             {                                                             if(PS-1 == 20)                                                                {                                                                level_high = High[PS];                                                                }                                                             }                                                          }                                                       }                                                    }                                                 }                                              }                                           }                                        }                                     }                                  }                               }                            }                         }                      }                   }                }             }          }       }    } } }```
 Moderator3517 GumRai 2016.01.30 00:18 #   ```Number_of_candles = 15 int PS = Number_of_candles+1;    //PS=16```when you reach` if(High[PS] >= High[PS-17] && High[PS] >= High[PS+17])` PS-17 is [-1]There is no such bar, so you get "array out of range"
 11 Lukas273 2016.01.30 18:45 #   Tried to put it into the indicator to draw a line on the graph... I cannot figure it out how... again. Anybody? you might see the mistake immediately...```//+------------------------------------------------------------------+ //|                                                         test.mq4 | //|                                                               LJ | //+------------------------------------------------------------------+ #property copyright "LJ" #property link      "lukas.janca@icloud.com" #property version   "1.00" #property strict #property indicator_chart_window // v/mimo okno #property indicator_buffers 1 //množství buferů #property indicator_plots   1 //počet linií? //--- plot barsToProcess #property indicator_label1  "barsToProcess = 100" #property indicator_type1   DRAW_LINE #property indicator_color1  Green #property indicator_style1  STYLE_SOLID #property indicator_width1  1 //--- indicator buffers double Buffer1[]; input int Number_of_candles = 15; int OnInit()    {    IndicatorShortName("S/R levels");    SetIndexStyle(0,DRAW_LINE);    SetIndexBuffer(0,Buffer1);         return(0);    return(INIT_SUCCEEDED);    } 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 counted_bars=IndicatorCounted(); int static NewBar = Bars; for(int i = 0; i < Bars; i++)    {       if(NewBar != Bars && Bars > Number_of_candles)       {       NewBar = Bars;              double static level_high;              int PS = Number_of_candles+1;              if(High[PS] >= High[PS-1] && High[PS] >= High[PS+1] && PS >= 2)          {          if(PS-1 == 1)             {             level_high = High[PS];             }                 if(High[PS] >= High[PS-2] && High[PS] >= High[PS+2] && PS >= 3)             {             if(PS-1 == 2)                {                level_high = High[PS];                }                    if(High[PS] >= High[PS-3] && High[PS] >= High[PS+3] && PS >= 4)                {                if(PS-1 == 3)                   {                   level_high = High[PS];                   }                       if(High[PS] >= High[PS-4] && High[PS] >= High[PS+4] && PS >= 5)                   {                   if(PS-1 == 4)                      {                      level_high = High[PS];                      }                          if(High[PS] >= High[PS-5] && High[PS] >= High[PS+5] && PS >= 6)                      {                      if(PS-1 == 5)                         {                         level_high = High[PS];                         }                             if(High[PS] >= High[PS-6] && High[PS] >= High[PS+6] && PS >= 7)                         {                         if(PS-1 == 6)                            {                            level_high = High[PS];                            }                                if(High[PS] >= High[PS-7] && High[PS] >= High[PS+7] && PS >= 8)                            {                            if(PS-1 == 7)                               {                               level_high = High[PS];                               }                                   if(High[PS] >= High[PS-8] && High[PS] >= High[PS+8] && PS >= 9)                               {                               if(PS-1 == 8)                                  {                                  level_high = High[PS];                                  }                                      if(High[PS] >= High[PS-9] && High[PS] >= High[PS+9] && PS >= 10)                                  {                                  if(PS-1 == 9)                                     {                                     level_high = High[PS];                                     }                                         if(High[PS] >= High[PS-10] && High[PS] >= High[PS+10] && PS >= 11)                                     {                                     if(PS-1 == 10)                                        {                                        level_high = High[PS];                                        }                                            if(High[PS] >= High[PS-11] && High[PS] >= High[PS+11] && PS >= 12)                                        {                                        if(PS-1 == 11)                                           {                                           level_high = High[PS];                                           }                                               if(High[PS] >= High[PS-12] && High[PS] >= High[PS+12] && PS >= 13)                                           {                                           if(PS-1 == 12)                                              {                                              level_high = High[PS];                                              }                                                  if(High[PS] >= High[PS-13] && High[PS] >= High[PS+13] && PS >= 14)                                              {                                              if(PS-1 == 13)                                                 {                                                 level_high = High[PS];                                                 }                                                     if(High[PS] >= High[PS-14] && High[PS] >= High[PS+14] && PS >= 15)                                                 {                                                 if(PS-1 == 14)                                                    {                                                    level_high = High[PS];                                                    }                                                        if(High[PS] >= High[PS-15] && High[PS] >= High[PS+15] && PS >= 16)                                                    {                                                    if(PS-1 == 15)                                                       {                                                       level_high = High[PS];                                                       }                                                           if(High[PS] >= High[PS-16] && High[PS] >= High[PS+16] && PS >= 17)                                                       {                                                       if(PS-1 == 16)                                                          {                                                          level_high = High[PS];                                                          }                                                              if(High[PS] >= High[PS-17] && High[PS] >= High[PS+17] && PS >= 18)                                                          {                                                          if(PS-1 == 17)                                                             {                                                             level_high = High[PS];                                                             }                                                                 if(High[PS] >= High[PS-18] && High[PS] >= High[PS+18] && PS >= 19)                                                             {                                                             if(PS-1 == 18)                                                                {                                                                level_high = High[PS];                                                                }                                                                    if(High[PS] >= High[PS-19] && High[PS] >= High[PS+19] && PS >= 20)                                                                {                                                                if(PS-1 == 19)                                                                   {                                                                   level_high = High[PS];                                                                   }                                                                       if(High[PS] >= High[PS-20] && High[PS] >= High[PS+20] && PS >= 21)                                                                   {                                                                   if(PS-1 == 20)                                                                      {                                                                      level_high = High[PS];                                                                      }                                                                   }                                                                }                                                             }                                                          }                                                       }                                                    }                                                 }                                              }                                           }                                        }                                     }                                  }                               }                            }                         }                      }                   }                }             }          }          Print("Level High = ", level_high);                 Buffer1[i]=level_high;       }    } return(rates_total); }```