Mira cómo descargar robots gratis
¡Búscanos en Facebook!
Pon "Me gusta" y sigue las noticias
¿Es interesante este script?
Deje un enlace a él, ¡qué los demás también lo valoren!
¿Le ha gustado el script?
Evalúe su trabajo en el terminal MetaTrader 5
Librerías

Biblioteca de compatibilidad MQL4 a MQL5 - librería para MetaTrader 5

Visualizaciones:
2200
Ranking:
(49)
Publicado:
2014.01.14 13:35
Actualizado:
2016.11.22 07:33
mql4compat.mqh (54.62 KB) ver
¿Necesita un robot o indicador basado en este código? Solicítelo en la bolsa freelance Pasar a la bolsa

Esta biblioteca permite ejecutar la mayoría de los scripts e indicadores de Metatrader4 en Metatrader 5. La mayoría de las funciones ya están soportadas, solamente no se ha modificado la lógica de funcionamiento de los expertos, por este motivo el mecanismo de trading debe ser reescrito.

Esta librería soporta la mayoría de las funciones, excepto el mecanismo de trading de los EAs. Igualmente para la mayoría de las funciones que provocan errores en MT5 se ofrecen funciones alternativas con el mismo nombre, pero terminado en MQL4. La mayoría de los errores se deben a conflictos con funciones del mismo nombre que ya existen en MQL5. En el artículo original solo se presentaba un esqueleto de la biblioteca, en esta versión se ofrece una base más completa de funciones MQL4.  Para localizar funciones específicas en el código fuente de la biblioteca utilize el patrón de búsqueda "MQL4".

PENDIENTE:  Mecanismo de trading de los EAs para envio de órdenes y su control. Alguna funciones tienen fragmentos genéricos que generarán los errores correspondientes en el log. El código de retorno para los mismos siempre es -1.

Instalación:

Coloque mql4compat.mqh en su carpeta Include (está ubicada en su perfil de roaming).

En el EA/indicador/biblioteca/script de MQL4 agregue directamente después de las declaraciones #property:

#include <mql4compat.mqh>

 Sustituya las funciones de MQL4:

int init() por int OnInit()
int deinit() por void OnDeinit(const int reason);
int start() en scripts por void OnStart();
int start() en  indicadores por:
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[])
  {

la última línea con return() debe reescribirse como:

   return(rates_total);

 Modifique los nombres de las funciones que generan conflictos entre MQL4 y MQL5 debido a que se han modificado los parámetros, añadiendo MQL4 a sus nombres:

   int ArrayInitializeMQL4(double &array[], double value)
   int ArrayMaximumMQL4(double &array[], int count=WHOLE_ARRAY, int start=0)
   int ArrayMinimumMQL4(double &array[], int count=WHOLE_ARRAY, int start=0)
   int ArraySortMQL4(double &array[], int count=WHOLE_ARRAY, int start=0, int sort_dir=MODE_ASCEND)
   double CopyBufferMQL4(int handle,int index,int shift)
   double EnvelopesMQL4(string symbol, int tf, int ma_period, int method, int ma_shift, int price, double deviation, int mode, int shift)
   double FileReadDoubleMQL4(int handle, int size=DOUBLE_VALUE)
   bool FileSeekMQL4(long handle, int offset, ENUM_FILE_POSITION origin)
   int IndicatorCountedMQL4(int _prev_calculated=0)
   bool ObjectCreateMQL4(string name, ENUM_OBJECT type, int window, datetime time1, double price1, datetime time2=0, double price2=0, datetime time3=0, double price3=0)
   bool ObjectDeleteMQL4(string name)
   string ObjectDescriptionMQL4(string name)
   int ObjectFindMQL4(string name)
   bool ObjectMoveMQL4(string name, int point, datetime time1, double price1)
   string ObjectNameMQL4(int index)
   int ObjectsDeleteAllMQL4(int window=EMPTY, int type=EMPTY)
   int ObjectsTotalMQL4(int type=EMPTY, int window=-1)
   bool SetIndexBufferMQL4(int index, double &array[])
   string StringConcatenateMQL4(string _str1,string _str2, ... string _str64="")
   int StringGetCharMQL4(string text, int pos)
   string StringSetCharMQL4(string text, int pos, int value)
   double iACMQL4(string symbol, int tf, int shift)
   double iADMQL4(string symbol, int tf, int shift)
   double iADXMQL4(string symbol, int tf, int period, int price, int mode, int shift)
   double iAOMQL4(string symbol, int tf, int shift)
   double iATRMQL4(string symbol, int tf, int period, int shift)
   double iAlligatorMQL4(string symbol, int tf, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int method, int price, int mode, int shift)
   double iBWMFIMQL4(string symbol, int tf, int shift)
   double iBandsMQL4(string symbol, int tf, int period, double deviation, int bands_shift, int method, int mode, int shift)
   double iBearsPowerMQL4(string symbol, int tf, int period, int price, int shift)
   double iBullsPowerMQL4(string symbol, int tf, int period, int price, int shift)
   double iCCIMQL4(string symbol, int tf, int period, int price, int shift)
   double iDeMarkerMQL4(string symbol, int tf, int period, int shift)
   double iForceMQL4(string symbol, int tf, int period, int method, int price, int shift)
   double iFractalsMQL4(string symbol, int tf, int mode, int shift)
   double iGatorMQL4(string symbol, int tf, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int method, int price, int mode, int shift)
   double iIchimokuMQL4(string symbol, int tf, int tenkan_sen, int kijun_sen, int senkou_span_b, int mode, int shift)
   double iMACDMQL4(string symbol, int tf, int fast_ema_period, int slow_ema_period, int signal_period, int price, int mode, int shift)
   double iMAMQL4(string symbol, int tf, int period, int ma_shift, int method, int price, int shift)
   double iMFIMQL4(string symbol, int tf, int period, int shift)
   double iMomentumMQL4(string symbol, int tf, int period, int price, int shift)
   double iOBVMQL4(string symbol, int tf, int price, int shift)
   double iOsMAMQL4(string symbol, int tf, int fast_ema_period, int slow_ema_period, int signal_period, int price, int shift)
   double iRSIMQL4(string symbol, int tf, int period, int price, int shift)
   double iRVIMQL4(string symbol, int tf, int period, int mode, int shift)
   double iSARMQL4(string symbol, int tf, double step, double maximum, int shift)
   double iStdDevMQL4(string symbol, int tf, int ma_period, int ma_shift, int method, int price, int shift)
   double iStochasticMQL4(string symbol, int tf, int Kperiod, int Dperiod, int slowing, int method, int field, int mode, int shift)
   double iWPRMQL4(string symbol, int tf, int period, int shift)

En los indicadores hay que hacer ajustes manuales para la función OnInit() y las cabeceras #property. También se debe sustituir la función IndicatorCounted() por la variable del mismo nombre o utilizar la variable de MQL5 prev_calculated:

#define IndicatorCounted IndicatorCountedMQL4(prev_calculated)

En los indicadores personalizados revise las cabeceras #property acorde con las reglas de MQL5 y sustituya en las declaraciones de los parámetros den entrada el tipo extern por input. Tenga en cuenta que en MQL5 estos parámetros son constantes y cualquier intento de modificar sus valores provocará un error. La solución es utilizar variables temporales e inicializarlas con los valores de los parámetros de entrada.

En la primera línea del código principal añada la función de inicialización de las variables reservadas de MQL4 (los indicadores personalizados provocaran mensaje aviso sobre la utilización de variables reservadas de tipo OHLC/Time/Volume si estas son utilizadas en la función OnCalculate(), simplemente ingnore dichos mensajes): 

 

// -- Init MQL4 compatible environment
   InitMQL4Env();

Traducción del inglés realizada por MetaQuotes Ltd.
Artículo original: https://www.mql5.com/en/code/1787

Abanico de medias móviles (MA Fan) Abanico de medias móviles (MA Fan)

Abanico de indicadores MA (Medias Móviles) cuyo período se define por una progresión a escoger de entre un grupo de cuatro disponibles.

RSI Fan RSI Fan

Un abanico de indicadores RSI, el periodo de los cuales se determina mediante una de cuatro progresiones

JeromeClock JeromeClock

El indicador muestra la hora en diferentes zonas horarias en un gráfico

Range Ratio Range Ratio

Indicador de trading a corto plazo que se puede utilizar como señal de cierre de posiciones, o como filtro para abrir posiciones.