Problem with array index higher than [100]

 
Hello, I have a problem and I don't know how solve it
I need data from different bars, data like: volume, close, open, high and low... I don't have problem with first 100 bars, the problem is when I try to get those values of bars higher than 100, I get the error "array out of range"

I try something like this:

double xhigh, xlow, xopen;
xhigh=High[1200];
xlow=Low[1200];
xopen=Open[1200];
Print("High:",xhigh,"Low:",xlow);

Beforehand thank you very much!! ^^

 
roge1205:
I try something like this:

double xhigh, xlow, xopen;
xhigh=High[1200];
xlow=Low[1200];
xopen=Open[1200];
Print("High:",xhigh,"Low:",xlow);

Please don't post code something like what is causing the problem. Post the actual code.

Too often we are trying to help people and then find that we have wasted out time because they have not posted the code that causes the problem.

 

Check Bars to make sure that there are enough bars on the chart

Unless there are less than 1201 bars on the chart, I can't imagine the posted code causing an array out of range error.

 

Sorry, this is my actual code, I want to get the average of High, Low and Open for all the 6'099,906 bars

 

 

#property copyright "Personal Codes"

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

#property version   "1.00"

#property strict

int totalBars=0;

long countVolume=0;

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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---

   

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

      double averageHigh=0,averageLow=0,averageOpen=0;

      totalBars=Bars;

      for(int x=totalBars; x>1; x--)

      {

           averageHigh=averageHigh+High[x];

           averageLow=averageLow+Low[x];

           averageOpen=averageOpen+Open[x];

   countVolume=countVolume+Volume[x]; 

      }

      averageHigh=averageHigh/totalBars;

      averageLow=averageLow/totalBars;

      averageOpen=averageOpen/totalBars;

      Print("aHigh: ",averageHigh," aLow: ",averageLow," aOpen: ",averageOpen);

      Print("Volume of all the bars is: ",countVolume);       

  }

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

 

Error 

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Of course you get array exceeded. x == TotalBars == Bars. The candles are numbered 0 .. Bars-1. Therefor High[x] is High[Bars] and that does not exist.
    totalBars=Bars;
    for(int x=totalBars; x>1; x--){
       averageHigh=averageHigh+High[x];

Reason: