My indicator doesnt show up on mt5

 
//+------------------------------------------------------------------+
//|                                                     SimpleMA.mq5 |
//|                                   Copyright 2020, Julio Monteiro |
//|                     https://www.mql5.com/en/users/havok2k/seller |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Julio Monteiro"
#property link      "https://www.mql5.com/en/users/havok2k/seller"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots   1
//--- plot MA
#property indicator_label1  "MA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed,clrLime
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      InpPeriod = 2;
int peso1 = 2;
int peso2 = 3;
int peso3 = 4;
int peso4 = 5;
double divisor = 1.618;
//--- indicator buffers
double         MABuffer1[];
double         MABuffer2[];
double         MABuffer3[];
double         MABuffer4[];
double         MABufferSoma[];
double         ColorBuffer[];
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,MABuffer1,INDICATOR_CALCULATIONS);
   SetIndexBuffer(1,MABuffer2,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,MABuffer3,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,MABuffer4,INDICATOR_CALCULATIONS);
   SetIndexBuffer(4,MABufferSoma,INDICATOR_DATA);
   SetIndexBuffer(5,ColorBuffer,INDICATOR_COLOR_INDEX);

   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 backstep = InpPeriod;
   
   int rates_start = MathMax(0, prev_calculated - 1);
   
   for(int i = rates_start; i < rates_total; i++)
     {
      MABuffer1[i] = 0;
      MABuffer2[i] = 0;
      MABuffer3[i] = 0;
      MABuffer4[i] = 0;
      
      if(i < backstep)
        {
         continue;
        }

      for(int n = 0; n < InpPeriod; n++)
        {
         MABuffer1[i] += close[i-n];
         MABuffer2[i] += open[i-n];
         MABuffer3[i] += high[i-n];
         MABuffer4[i] += low[i-n];
        }

      MABuffer1[i] = MABuffer1[i] * peso4;
      MABuffer2[i] = MABuffer2[i] * peso1;
      MABuffer3[i] = MABuffer3[i] * peso3;
      MABuffer4[i] = MABuffer4[i] * peso2;
      
      MABufferSoma[i] = (MABuffer1[i]+MABuffer2[i]+MABuffer3[i]+MABuffer4[i])/peso1+peso2+peso3+peso4;
      
      if(MABufferSoma[i] > MABufferSoma[i-1])
        {
         ColorBuffer[i] = 1;
        }
      else
        {
         ColorBuffer[i] = 0;
        }
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+

Hi. I need some help. Im trying to do an average of OHCL in n periods. Thereis no error when i compile, but the indicator doesnt work. Could someone help me?

 
Jhonatan Breia Carvalho Maia :

Hi. I need some help. Im trying to do an average of OHCL in n periods. Thereis no error when i compile, but the indicator doesnt work. Could someone help me?

Prepare an indicator in the MQL5 Wizard - this is the only way to avoid mistakes.

The cat is the correct code:

//--- plot MA
#property indicator_label1  "MA"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1  clrRed,clrLime
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      InpPeriod = 2;
int peso1 = 2;
int peso2 = 3;
int peso3 = 4;
int peso4 = 5;
double divisor = 1.618;
//--- indicator buffers
double   MABufferSoma[];
double   ColorBuffer[];
double   MABuffer1[];
double   MABuffer2[];
double   MABuffer3[];
double   MABuffer4[];
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,MABufferSoma,INDICATOR_DATA);
   SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,MABuffer1,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,MABuffer2,INDICATOR_CALCULATIONS);
   SetIndexBuffer(4,MABuffer3,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,MABuffer4,INDICATOR_CALCULATIONS);
   return(INIT_SUCCEEDED);
  }


Result:


MQL5 Wizard: Creating Expert Advisors without Programming
MQL5 Wizard: Creating Expert Advisors without Programming
  • www.mql5.com
When you create automated trading systems it is necessary to write algorithms of analyzing market situation and generating trading signals, algorithms of trailing your open positions, as well as systems of money management and risk management. Once the modules' code is written the most difficult task is to assemble all parts and to debug the...
 
Vladimir Karputov:

Prepare an indicator in the MQL5 Wizard - this is the only way to avoid mistakes.

The cat is the correct code:


Result:


Thanks, it worked. As i can see, to do an indicator you really need to follow a restrict order in the code, dont you?

 
Jhonatan Breia Carvalho Maia :

Thanks, it worked. As i can see, to do an indicator you really need to follow a restrict order in the code, dont you?

Yes, the order in which variables are declared is very important.

Reason: