Converting an array index value into a variable?

 

Hi, I'm just learning MQL5 and I have a question that has got me stuck.

I'm trying to write a basic script that adds up all of the price values within an array

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   MqlRates pricedata[];
   ArraySetAsSeries(pricedata, true);
   int barcount  = CopyRates(_Symbol, 0, 0, 10, pricedata);
   double close = pricedata[0].close;
   int data = 0;
   for(close <= pricedata[10].close; pricedata[++].close)
     {
      data = data + close;
     }
   Print(" The value is" + (string) data);
  }

I'm sure I have completely botched it.

However what I want is to get the data from index 0-10 and add them together by using a for loop on pricedata[x] where x is x + x++ and then extract the data for each value of x.

Would appreciate the help.

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / History Data Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / History Data Structure
  • www.mql5.com
History Data Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Please insert the code correctly: when editing a message, press the button    Codeand paste your code into the pop-up window. (The first time I corrected your message)
 
Colin Leamy: I'm sure I have completely botched it.

Definitely.

   double close = pricedata[0].close;
   for(close <= pricedata[10].close; pricedata[++].close)
     {
      data = data + close;
     }
The for loop controls the index.
   for(int i=0; i <= 10; ++i)
     {
     data += pricedata[i].close; 
     }