iMACD parameters on MQL5 - page 3

Gerardo Calvetty
30
Gerardo Calvetty  

Solution for MQL5, sorry for the language mix.

//+------------------------------------------------------------------+
//| Global variables for indicators                                  |
//+------------------------------------------------------------------+
// MACD Moving Averages Convergence/Divergence
int    MACD_handle;          // MACD Manejador
double MACD_buffer_main[];   // MACD Array.receptor main
double MACD_buffer_signal[]; // MACD Array.receptor signal

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   // MACD Moving Averages Convergence/Divergence
   SetIndexBuffer(0,MACD_buffer_main,INDICATOR_DATA);
   SetIndexBuffer(1,MACD_buffer_signal,INDICATOR_DATA);
   MACD_handle = iMACD(_Symbol,PERIOD_CURRENT,12,26,9,PRICE_CLOSE);
   
   // Códigos para evaluar posibles errores de carga de variables
   if(MACD_handle < 0)
     {
      Alert("Error al intentar crear el identificador para el indicador - error: ",GetLastError(),"!");
      return(-1);
     }
   
   // Para agregar el indicador al gráfico:
   ChartIndicatorAdd(0,1,MACD_handle);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   IndicatorRelease(MACD_handle);             // MACD Moving Averages Convergence/Divergence
   ChartIndicatorDelete(0,1,"MACD(12,26,9)"); // Moving Averages Convergence/Divergence
   Comment("");
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   // Recibe en el array búfer los datos del búfer
   CopyBuffer(MACD_handle,0,0,7,MACD_buffer_main);
   CopyBuffer(MACD_handle,1,0,7,MACD_buffer_signal);
   
   // Dirección de indexación de la matriz
   ArraySetAsSeries(MACD_buffer_main,true);
   ArraySetAsSeries(MACD_buffer_signal,true);
   
   // Comentar
   Comment("MACD_Main: ",DoubleToString(MACD_buffer_main[0],6),"\n",
           "MACD_Signal: ",DoubleToString(MACD_buffer_signal[0],6));
//---
  }
//+------------------------------------------------------------------+