Download MetaTrader 5
To add comments, please log in or register
Examine the Top MetaTrader 5 signals. Choose the best one and subscribe to it!
GonzaloV
28
GonzaloV 2014.06.11 03: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.
Trinh Dat
36695
Trinh Dat 2014.06.11 06:19  
Mql5 not work like it. you need use " CopyBuffer " to get value of indicator.
Marcelo Coutinho
1151
Marcelo Coutinho 2014.06.14 01:10  
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.

Rodrigo Malacarne
Moderator
9851
Rodrigo Malacarne 2014.06.14 01:29  

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));
  }
//+------------------------------------------------------------------+
/
To add comments, please log in or register