Download MetaTrader 5

Indicator and debugger won't start

To add comments, please log in or register
n22alpha
63
n22alpha  

Hi guys,

 I built this indicator for calculating an angle of moving average over a given number of bars but when I try and debug it using breakpoints it won't start at all. The sub_window loads up but nothing else happens. I don't know whats wrong could someone help. Could someone check that my code is correct? 

 P.S. a previous indicator of a similar nature worked so I'm not sure why this one isn't working.

 

EDIT: now no indicator at all will load include the MT5 ones not sure whats going on tbh. 

 

//+------------------------------------------------------------------+
//|                                                     MA_Angle.mq5 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_minimum -90
#property indicator_maximum 90
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Angle
#property indicator_label1  "Angle"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      MA_period = 100;
input ENUM_MA_METHOD      MA_type = MODE_SMA;
input int      AngleBars = 2;
//--- indicator buffers
double         AngleBuffer[];
double pi = 3.14159265358979323846;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,AngleBuffer,INDICATOR_DATA);
   
    if (AngleBars < 2)
   {
      Print("Error anglebars less than 2, ending program");
      return(INIT_FAILED);
   }
   
   if (AngleBars > MA_period)
   {
      Print("Error anglebars must be less than moving average period");
      return(INIT_FAILED);
   }
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration 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[])
  {
  
  int i, start;

   if (rates_total < MA_period) return(0);
   
   if (prev_calculated == 0)
      {
         for (i = 0; i < AngleBars; i++)
         {
            AngleBuffer[i] = 0.0;
         }
      }
    

    
    if (prev_calculated == 0)
      {
         start = AngleBars - 1;
      }
    else
      {
      //rates_total for the previous tick = prev_calculated
       start = prev_calculated - 1;
      }
      
    
    for (i = start; i < rates_total; i++)
      {
         double MA_first = iMA(_Symbol, _Period, MA_period, 0, MA_type, i - (AngleBars - 1));
         double MA_second = iMA(_Symbol, _Period, MA_period, 0, MA_type, i);
         
         double diff = MA_second - MA_first;
         
         diff = NormalizeDouble(diff, _Digits);
         
         double roc = (diff * 10000)/AngleBars;
         
         AngleBuffer[i] = MathArctan(roc) * (180/pi);
         
      }
    
   return(rates_total);
  }
//+------------------------------------------------------------------+
Vladimir Karputov
Moderator
52610
Vladimir Karputov  

When starting in the "experts" we get an error:

2015.02.22 19:37:58.619 MA_Angle (EURUSD,H1) cannot load indicator 'Moving Average' [4804]

Vladimir Karputov
Moderator
52610
Vladimir Karputov  

Error:

         double MA_first = iMA(_Symbol, _Period, MA_period, 0, MA_type, i - (AngleBars - 1));

         double MA_second = iMA(_Symbol, _Period, MA_period, 0, MA_type, i);

 

Should be something like this:

         double MA_first = iMA(_Symbol, _Period, MA_period, 0, MA_type, PRICE_CLOSE);

         double MA_second = iMA(_Symbol, _Period, MA_period, 0, MA_type, PRICE_OPEN);

n22alpha
63
n22alpha  
ah ofc sorry I was still thinking I was using MQL4 thank you for that :)
To add comments, please log in or register