Alerta de fechamento fora dos níveis de BB

 

Olá,

Alguém Poderia me ajudar com o código abaixo, não consigo arrumar os erros dele, que um alerta para os niveis de banda para auxilio em analise quando estiver fechando fora dos niveis 2 e 3 da BB.

//+------------------------------------------------------------------+
//|                                               AlertBollinger.mq5 |
//|                        Copyright 2023, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "Copyright 2023, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property indicator_chart_window

#property indicator_buffers 3

 

input int InpBandsPeriod = 14;      // Período da Banda de Bollinger

input double InpBandsDeviation = 2; // Desvio da Banda de Bollinger

input double InpBandsExtraLevel = 0.5; // Nível extra para o alerta

input ENUM_TIMEFRAMES InpTimeframe1 = PERIOD_H1; // Primeiro timeframe

input ENUM_TIMEFRAMES InpTimeframe2 = PERIOD_H4; // Segundo timeframe

 

double UpperBuffer[];

double MiddleBuffer[];

double LowerBuffer[];

 

int OnInit()

{

   IndicatorShortName("Alerta Bollinger (" + IntegerToString(InpBandsPeriod) + ")");

   SetIndexBuffer(0, UpperBuffer);

   SetIndexBuffer(1, MiddleBuffer);

   SetIndexBuffer(2, LowerBuffer);

   IndicatorDigits(Digits);

 

   return(INIT_SUCCEEDED);

}

 

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

{

   int i, limit;

 

   if (prev_calculated > rates_total || prev_calculated <= 0) limit = rates_total - InpBandsPeriod;

   else limit = rates_total - prev_calculated;

 

   for (i = 0; i < limit; i++)

   {

      ArrayResize(UpperBuffer, rates_total);

      ArrayResize(MiddleBuffer, rates_total);

      ArrayResize(LowerBuffer, rates_total);

 

      iBands(NULL, InpTimeframe1, InpBandsPeriod, InpBandsDeviation, 0, PRICE_CLOSE, MODE_UPPER, i, UpperBuffer[i]);

      iBands(NULL, InpTimeframe1, InpBandsPeriod, InpBandsDeviation, 0, PRICE_CLOSE, MODE_MIDDLE, i, MiddleBuffer[i]);

      iBands(NULL, InpTimeframe1, InpBandsPeriod, InpBandsDeviation, 0, PRICE_CLOSE, MODE_LOWER, i, LowerBuffer[i]);

 

      if (close[i] > UpperBuffer[i] + InpBandsExtraLevel * _Point || close[i] < LowerBuffer[i] - InpBandsExtraLevel * _Point)

      {

         Alert(Symbol(), " ", EnumToString(InpTimeframe1), " Bollinger Breakout: ", TimeToString(time[i], TIME_DATE | TIME_MINUTES));

      }

   }

 

   for (i = 0; i < limit; i++)

   {

      iBands(NULL, InpTimeframe2, InpBandsPeriod, InpBandsDeviation, 0, PRICE_CLOSE, MODE_UPPER, i, UpperBuffer[i]);

      iBands(NULL, InpTimeframe2, InpBandsPeriod, InpBandsDeviation, 0, PRICE_CLOSE, MODE_MIDDLE, i, MiddleBuffer[i]);

      iBands(NULL, InpTimeframe2, InpBandsPeriod, InpBandsDeviation, 0, PRICE_CLOSE, MODE_LOWER, i, LowerBuffer[i]);

 

      if (close[i] > UpperBuffer[i] + InpBandsExtraLevel * _Point || close[i] < LowerBuffer[i] - InpBandsExtraLevel * _Point)

      {

         Alert(Symbol(), " ", EnumToString(InpTimeframe2), " Bollinger Breakout: ", TimeToString(time[i], TIME_DATE | TIME_MINUTES));

      }

   }

 

   return(rates_total);

}

//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.03.23
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Razão: