Indicator for storing price of seconds ago in array. Array doesn't work.

 
Good afternoon!

I'm trying to build an indicator that stores the price of each second ago in an array. Then, I intend to get the price of, for example, 5 seconds ago, accessing the array L[5].... I made this code below, but I can't access the array. If it's L[0], then it works....
Where am I going wrong or what is missing? Someone help me?!
Thank you all!
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1


enum ENUM_ANCORA
 {
 
 
  _ANCHOR_LEFT_UPPER   = 0,    // Canto Superior Esquerdo
  _ANCHOR_LEFT_LOWER   = 2,    // Canto Inferior Esquerdo
  _ANCHOR_RIGHT_LOWER  = 4,    // Canto Inferior Direito
  _ANCHOR_RIGHT_UPPER  = 6     // Canto Superior Direito
 
 
 };
 
  
double L[];

input int                               Frequencia_Avaliacao         = 1;          // Frequência de avaliações (segundos) - Frequency of reviews in seconds
input int                               Distancia_preco_secs         = 5;          // Distância em segundos do preço - Price distance in seconds
input bool                             Mostrar_Painel                  = true;      // Mostrar Painel
input ENUM_ANCORA             Anchoragem                      = 0;          // Posição do Painel
input color                            Cor_do_Texto                    = clrYellow;  // Cor Do Texto

datetime LastTime,NextTime;
double LastClose;

string cod = "GUI123";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

  
   LastTime  = TimeCurrent();
   LastClose = iClose(_Symbol,0,0);
 // int x = Anchoragem  == 2 ? 5 : 
   NextTime  = LastTime+Frequencia_Avaliacao;
   

   SetIndexBuffer(0,L,INDICATOR_DATA);
   ArraySetAsSeries(L,true);
   
   
   return(INIT_SUCCEEDED);
  }
long width, height, Last_Height,Last_Width;
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
bool xx = false;


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[])
  {
//---
 
  
   

   if(TimeCurrent() >= NextTime)
    {
    LastTime = NextTime;
    NextTime = LastTime+Frequencia_Avaliacao; // Frequency of reviews in seconds
    LastClose = iClose(_Symbol,0,0);
    L[Distancia_preco_secs] = LastClose;
    
   
    
   
   
    ObjectSetString(0,cod+"Last_Time",OBJPROP_TEXT,"Ultima Atualização: "+TimeToString(LastTime,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
    ObjectSetString(0,cod+"Next_Time",OBJPROP_TEXT,"Próxima Atualização: "+TimeToString(NextTime,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
    ObjectSetString(0,cod+"Ultimo_Preco",OBJPROP_TEXT,"Ultimo Preço: "+DoubleToString(LastClose,_Digits)); 
       
    }
    
  
   height  =  ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
   width   =  ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
  
  if(height != Last_Height || width != Last_Width)
    {
    
    Last_Height = height; 
    Last_Width  = width;
    CriarPainel();
    
    }

  
   xx = true;
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Reason: