Problem with reading multisymbol indicators

 

I am looking for opportunities by sector. According to them, I can then select shares using the screener. I have a problem with loading data into indicators: only the current symbol from the chart is always loaded. The exception is when I close MT5 and then open it - that's when all the indicators are loaded. Is this a bug of MT5 or the program?

//+------------------------------------------------------------------+
//|                                           MultiCurrencyIndex_en.mq5 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "2021, milicka"
#property version   "1.1" 
#property indicator_separate_window

#property indicator_buffers 10
#property indicator_plots   10
#property indicator_level1   0
#property indicator_level2   100
#property indicator_level3   -100

#property indicator_label1  "energy XLE"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

#property indicator_label2  "materials XLB"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrAqua
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

#property indicator_label3  "industrials XLI"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrPaleTurquoise
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1

#property indicator_label4  "consumer XLY"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1

#property indicator_label5  "healthcare XLV"
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrMaroon
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1

#property indicator_label6  "financal XLF"
#property indicator_type6   DRAW_LINE
#property indicator_color6  clrPink
#property indicator_style6  STYLE_SOLID
#property indicator_width6  1

#property indicator_label7  "technology XLK"
#property indicator_type7   DRAW_LINE
#property indicator_color7  clrGreen
#property indicator_style7  STYLE_SOLID
#property indicator_width7  1

#property indicator_label8  "communication XLC"
#property indicator_type8   DRAW_LINE
#property indicator_color8  clrGreenYellow
#property indicator_style8  STYLE_SOLID
#property indicator_width8  1

#property indicator_label9  "utilities XLU"
#property indicator_type9   DRAW_LINE
#property indicator_color9  clrLightGreen
#property indicator_style9  STYLE_SOLID
#property indicator_width9  1

#property indicator_label10  "real estate XLRE"
#property indicator_type10   DRAW_LINE
#property indicator_color10  clrGray
#property indicator_style10  STYLE_SOLID
#property indicator_width10  1

double   b1[], b2[], b3[], b4[], b5[], b6[], b7[], b8[], b9[], b10[];
int      h1, h2, h3, h4, h5, h6, h7, h8, h9, h10;
input int      period=14;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {

   h1 = iCCI("#XLE", _Period, period, PRICE_CLOSE);
   h2 = iCCI("#XLB", _Period, period, PRICE_CLOSE);
   h3 = iCCI("#XLI", _Period, period, PRICE_CLOSE);
   h4 = iCCI("#XLY", _Period, period, PRICE_CLOSE);
   h5 = iCCI("#XLV", _Period, period, PRICE_CLOSE);
   h6 = iCCI("#XLF", _Period, period, PRICE_CLOSE);
   h7 = iCCI("#XLK", _Period, period, PRICE_CLOSE);
   h8 = iCCI("#XLC", _Period, period, PRICE_CLOSE);
   h9 = iCCI("#XLU", _Period, period, PRICE_CLOSE);
   h10= iCCI("#XLRE", _Period, period, PRICE_CLOSE);
   
   int idx=0;   
   SetIndexBuffer(idx,b1, INDICATOR_DATA); idx++;
   SetIndexBuffer(idx,b2, INDICATOR_DATA); idx++; 
   SetIndexBuffer(idx,b3, INDICATOR_DATA); idx++;
   SetIndexBuffer(idx,b4, INDICATOR_DATA); idx++;
   SetIndexBuffer(idx,b5, INDICATOR_DATA); idx++;
   SetIndexBuffer(idx,b6, INDICATOR_DATA); idx++;
   SetIndexBuffer(idx,b7, INDICATOR_DATA); idx++;
   SetIndexBuffer(idx,b8, INDICATOR_DATA); idx++;
   SetIndexBuffer(idx,b9, INDICATOR_DATA); idx++;
   SetIndexBuffer(idx,b10, INDICATOR_DATA); idx++;

   IndicatorSetString(INDICATOR_SHORTNAME, "sektory ("+period+")");
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(
   const int        rates_total,       // size of input time series 
   const int        prev_calculated,   // number of handled bars at the previous call 
   const datetime&  time[],            // Time array 
   const double&    open[],            // Open array 
   const double&    high[],            // High array 
   const double&    low[],             // Low array 
   const double&    close[],           // Close array 
   const long&      tick_volume[],     // Tick Volume array 
   const long&      volume[],          // Real Volume array 
   const int&       spread[]           // Spread array 
   )
      {
int ret;      
int bars = rates_total -1-period;
if (prev_calculated>0) 
   bars = rates_total - (prev_calculated -1);
else
  {
  
   ArrayInitialize(b1,0);
   ArrayInitialize(b2,0);
   ArrayInitialize(b3,0);
   ArrayInitialize(b4,0);
   ArrayInitialize(b5,0);
   ArrayInitialize(b6,0);
   ArrayInitialize(b7,0);
   ArrayInitialize(b8,0);
   ArrayInitialize(b9,0);
   ArrayInitialize(b10,0);
   
   };
EnsureSymbolLoaded("3XLE");

ret = CopyBuffer(h1, 0, 0, bars, b1);
ret = CopyBuffer(h2, 0, 0, bars, b2);
ret = CopyBuffer(h3, 0, 0, bars, b3);
ret = CopyBuffer(h4, 0, 0, bars, b4);
ret = CopyBuffer(h5, 0, 0, bars, b5);
ret = CopyBuffer(h6, 0, 0, bars, b6);
ret = CopyBuffer(h7, 0, 0, bars, b7);
ret = CopyBuffer(h8, 0, 0, bars, b8);
ret = CopyBuffer(h9, 0, 0, bars, b9);
ret = CopyBuffer(h10, 0, 0, bars, b10);

ArraySetAsSeries(close, true);
ArraySetAsSeries(b1, true);
ArraySetAsSeries(b2, true);
ArraySetAsSeries(b3, true);
ArraySetAsSeries(b4, true);
ArraySetAsSeries(b5, true);
ArraySetAsSeries(b6, true);
ArraySetAsSeries(b7, true);
ArraySetAsSeries(b8, true);
ArraySetAsSeries(b9, true);
ArraySetAsSeries(b10, true);

double delta;
for (int i=bars; i>=0; i--)
   {
   
   }

return rates_total;
}

void EnsureSymbolLoaded(string symbol)
{
    if(!SymbolSelect(symbol, true))
    {
        Print("Error loading symbol: ", symbol);
    }
}