Array out of range. Please check where the problem is.

 
//+------------------------------------------------------------------+
//|                                                   test_alert.mq5 |
//|                                            Copyright 2023, metaq5 |
//|                                        https://www.metaq5.com/    |
//+------------------------------------------------------------------+

#property indicator_chart_window

//--- input parameters
input double SSMA_Period=50;

//--- global variables
double SSMA_Buffer[];
double prev_SSMA_Buffer[];
datetime prev_candle_time = 0;

//--- indicator initialization function
int OnInit()
{
    //--- set SSMA indicator buffer
    SetIndexBuffer(0, SSMA_Buffer, INDICATOR_DATA);
    SetIndexBuffer(1, prev_SSMA_Buffer, INDICATOR_CALCULATIONS);

    //--- set indicator parameters
    IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, 1);
    IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, -1);
    IndicatorSetInteger(INDICATOR_LEVELSTYLE, DRAW_ARROW);
    IndicatorSetInteger(INDICATOR_LEVELWIDTH, 3);

    //--- set indicator arrow code
    IndicatorSetInteger(INDICATOR_DIGITS, 2);
    IndicatorSetString(INDICATOR_SHORTNAME, "test_alert");

    //--- initialize indicator buffers
    for(int i=0; i<SSMA_Period; i++)
    {
        SSMA_Buffer[i] = 0;
        prev_SSMA_Buffer[i] = 0;
    }

    return(INIT_SUCCEEDED);
}

//--- indicator calculation function
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[])
{
    //--- check for rates_total
    if(rates_total<=SSMA_Period)
    {
        return(0);
    }

    //--- calculate the current time
    datetime current_candle_time = time[rates_total-1];

    //--- check if we need to update the SSMA buffer
    if(current_candle_time != prev_candle_time)
    {
        //--- update previous SSMA buffer
        for(int i=0; i<SSMA_Period; i++)
        {
            prev_SSMA_Buffer[i] = SSMA_Buffer[i];
        }

        //--- calculate the SSMA for the current candle
        double ssma = iMA(_Symbol, PERIOD_CURRENT, (int)SSMA_Period, 0, MODE_SMMA, PRICE_CLOSE);

        //--- add the SSMA value to the buffer
        ArraySetAsSeries(SSMA_Buffer, true);
        SSMA_Buffer[0] = ssma;

        //--- set previous candle time
        prev_candle_time = current_candle_time;

        //--- check for signal
        if(prev_SSMA_Buffer[2] < prev_SSMA_Buffer[1] && prev_SSMA_Buffer[1] < prev_SSMA_Buffer[0])
        {
            if(close[1] > prev_SSMA_Buffer[1] && close[1] < prev_SSMA_Buffer[2] && close[0] < prev_SSMA_Buffer[1])
            {
                //--- alert signal
                Alert("Price has touched and engulfed on 50 SSMA and 21,50,200 SSMA are in a trending order");
            }
        }
    }

    return(rates_total);
}

 
Learn to use the </> button to insert your code please.
 

You can check yourself by:

  1. the error message  has line and char number to know exactly where the problem is.
  2. Or start the debugger: https://www.metatrader5.com/en/metaeditor/help/development/debug
  3. learn to use array. Here is a list of all function that deal with array: https://www.mql5.com/en/docs/array
    Look e.g. for the example of ArrayResize() how a dynamic array is treated correctly.
Documentation on MQL5: Array Functions
Documentation on MQL5: Array Functions
  • www.mql5.com
Array Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
        double ssma = iMA(_Symbol, PERIOD_CURRENT, (int)SSMA_Period, 0, MODE_SMMA, PRICE_CLOSE);

iMA does not return a double in MT5. Invalid call int MT4.

Stop using ChatGPT.
          Error message in EA - 'OnInit' - function already defined and has body - MQL4 programming forum (2023)

Reason: