//±-----------------------------------------------------------------+
//|                                                     BuySellSignal.mq4 |
//|                        Custom Indicator for MetaTrader 4         |
//±-----------------------------------------------------------------+
#property copyright "Copyright 2023 by User"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

// Input parameters
extern int Bollinger_Period = 20;
extern double Bollinger_Deviations = 2.0;
extern int MA_Period = 14;
extern int MACD_Fast_EMA_Period = 12;
extern int MACD_Slow_EMA_Period = 26;
extern int MACD_Signal_SMA_Period = 9;
extern int RSI_Period = 14;
extern double RSI_Upper_Level = 70;
extern double RSI_Lower_Level = 30;

// Buffers for our signals
double BuySignalBuffer[];
double SellSignalBuffer[];

//±-----------------------------------------------------------------+
//| Custom indicator initialization function                         |
//±-----------------------------------------------------------------+
int OnInit()
{
    // Buffers initialization
    SetIndexStyle(0, DRAW_ARROW);
    SetIndexArrow(0, 233); // Arrow symbol for BUY signal (up arrow)
    SetIndexBuffer(0, BuySignalBuffer);
    ArraySetAsSeries(BuySignalBuffer, true);

    SetIndexStyle(1, DRAW_ARROW);
    SetIndexArrow(1, 234); // Arrow symbol for SELL signal (down arrow)
    SetIndexBuffer(1, SellSignalBuffer);
    ArraySetAsSeries(SellSignalBuffer, true);

    return(INIT_SUCCEEDED);
}

//±-----------------------------------------------------------------+
//| Custom indicator iteration function                              |
//±-----------------------------------------------------------------+
int start()
{
    int bars = Bars - Bollinger_Period - 1;
    if(bars <= 0) return(0);

    for(int i = 0; i < bars; i++)
    {
        double currentUpperBand = iBands(NULL, 0, Bollinger_Period, Bollinger_Deviations, 0, PRICE_CLOSE, MODE_UPPER, i+1);
        double currentLowerBand = iBands(NULL, 0, Bollinger_Period, Bollinger_Deviations, 0, PRICE_CLOSE, MODE_LOWER, i+1);
        double previousMA = iMA(NULL, 0, MA_Period, 0, MODE_SMA, PRICE_CLOSE, i+2);
        double currentMA = iMA(NULL, 0, MA_Period, 0, MODE_SMA, PRICE_CLOSE, i+1);
        double macdMain  = iMACD(NULL, 0, MACD_Fast_EMA_Period, MACD_Slow_EMA_Period, MACD_Signal_SMA_Period, PRICE_CLOSE, MODE_MAIN, i+1);
        double macdPrevious = iMACD(NULL, 0, MACD_Fast_EMA_Period, MACD_Slow_EMA_Period, MACD_Signal_SMA_Period, PRICE_CLOSE, MODE_MAIN, i+2);
        double rsiValue  = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i+1);

        if(currentMA > currentUpperBand && previousMA < currentUpperBand && macdMain > macdPrevious && rsiValue > RSI_Lower_Level && rsiValue < RSI_Upper_Level)
        {
            // BUY Signal
            BuySignalBuffer[i] = Low[i] - 4 * Point;
        }
        else
        {
            BuySignalBuffer[i] = EMPTY_VALUE;
        }
        
        if(currentMA < currentLowerBand && previousMA > currentLowerBand && macdMain < macdPrevious && rsiValue > RSI_Lower_Level && rsiValue < RSI_Upper_Level)
        {
            // SELL Signal
            SellSignalBuffer[i] = High[i] + 4 * Point;
        }
        else
        {
            SellSignalBuffer[i] = EMPTY_VALUE;
        }
        Print("Bar: ", i, " Buy Signal: ", BuySignalBuffer[i], " Sell Signal: ", SellSignalBuffer[i]);
    }


    return(0);
}

//±-----------------------------------------------------------------+

questo codice fallisce nel disegnare frecce sul grafico. ci sono errori?