HELP , iMA always returns 10

 

Hi, i have this problems, in every chart it always returns "10". What i done wrong?

this is the code, very very simply.

Help Please


//+------------------------------------------------------------------+
//|                                                CruceDeMedias.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

int Media_Movil;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  
 
  
  
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
 
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   Media_Movil = iMA(Symbol(),PERIOD_M5,3,1,MODE_SMA,PRICE_CLOSE);
  

  
  Comment ("MediaMovil= ", Media_Movil,"\n", "Error =", GetLastError());
  
//---
   
  }
//+------------------------------------------------------------------+
Trading automático y simulación de estrategias comerciales
Trading automático y simulación de estrategias comerciales
  • www.mql5.com
MQL5 es un lenguaje built-in de estrategias comerciales para el terminal MetaTrader 5. Este lenguaje permite escribir sus propios sistemas automáticos de trading, indicadores técnicos, scripts y bibliotecas de funciones.
 
Mql5 not work like it. you need use " CopyBuffer " to get value of indicator.
 
GonzaloV:

Hi, i have this problems, in every chart it always returns "10". What i done wrong?

this is the code, very very simply.

Help Please


You are getting the handle of the indicator. 

You need to use ArraySetAsSeries declared @ OnInit() part of your EA and, CopyBuffer, declared @ OnTick() part of your EA to get the indicator values.

 

Hi GonsaloV,

please try this approach:

//+------------------------------------------------------------------+
//|                                                CruceDeMedias.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

int    Media_Movil;
double MA_Buffer[];

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   Media_Movil = iMA(Symbol(),PERIOD_M5,3,1,MODE_SMA,PRICE_CLOSE);
   ArraySetAsSeries(MA_Buffer,true);
   //---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   IndicatorRelease(Media_Movil);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(CopyBuffer(Media_Movil,0,0,2,MA_Buffer)!=2) return;  
   //---
   Comment("Media_Movil[0] = ",DoubleToString(MA_Buffer[0],6),"\n","Media_Movil[1] = ",DoubleToString(MA_Buffer[1],6));
  }
//+------------------------------------------------------------------+
Reason: