Pon "Me gusta" y sigue las noticias
Deje un enlace a él, ¡qué los demás también lo valoren!
Evalúe su trabajo en el terminal MetaTrader 5
- Visualizaciones:
- 30
- Ranking:
- Publicado:
-
¿Necesita un robot o indicador basado en este código? Solicítelo en la bolsa freelance Pasar a la bolsa
Esta biblioteca contiene más de 80 funciones diferentes para tratar variables temporales. El objetivo principal es proporcionar funciones temporales de alto rendimiento. El modo de rendimiento (que puede controlarse en tiempo de compilación mediante una #define) está desactivado por defecto. Este modo no es un requisito para incluir la biblioteca en sus proyectos, ya que se puede incluir normalmente sin él.
TIMEUTILS_PERFORMANCE_MODE
Opcionalmente, el modo de rendimiento puede activarse en tiempo de compilación mediante #defines antes de #include:
// activar el modo de rendimiento para la biblioteca #define TIMEUTILS_PERFORMANCE_MODE #include "TimeUtils.mqh"
Esto redirigirá todas las llamadas a las funciones TimeToStruct y StructToTime de MQL a alternativas más eficientes.
Puedes compilar el script "performance_mode.mq5" con y sin TIMEUTILS_PERFORMANCE_MODE para comprobar la diferencia de velocidad en tu máquina. Esto será beneficioso para los programas de alto rendimiento que realicen tareas pesadas o muchas relacionadas con el tiempo (por ejemplo, escanear todo el historial de cotizaciones en busca de barras H1 al inicio de las semanas de negociación o recopilar otras estadísticas).
Listado de todas las funciones de la biblioteca:
Los nombres de las funciones deberían explicarse por sí mismos; además, puede encontrar una breve descripción de una función específica en el archivo TimeUtils.mqh.
//+==================================================================+ //| Crear fecha a partir de componentes| //+==================================================================+ datetime CreateDateTime( const int year, // Año const int mon, // Mes const int day, // Día const int hour = 0, // Hora const int min = 0, // Minutos const int sec = 0 // Segundos ) datetime CreateDateTime(MqlDateTime& dt_struct); // alternativa rápida a StructToTime() //+==================================================================+ //| Break datetime To Components| //+==================================================================+ bool TimeToStructFast( datetime dt, // Valor de fecha a convertir MqlDateTime& dt_struct // estructura para la adopción de valores ) //+==================================================================+ //| Extraer componentes de datetime: Sunday, yyyy.mm.dd hh:mm:ss | //| Unidades Get()| //+==================================================================+ int GetSecond(datetime t) int GetMinute(datetime t) int GetHour(datetime t) int GetDay(datetime t) int GetMonth(datetime t) int GetYear(datetime t) //+==================================================================+ //| Día() Número| //+==================================================================+ int DayOfWeek(datetime t) int DayOfYear(datetime t) int DayIndex(datetime t) //+==================================================================+ //| Semana() Número| //+==================================================================+ int WeekOfMonth(const datetime t, bool StartsOnMonday = false) int WeekOfYear(const datetime t, bool StartsOnMonday = false) int WeekIndex(datetime t, bool StartsOnMonday = false) //+==================================================================+ //| Unidades StartOf()| //+==================================================================+ datetime StartOfMinute(datetime t) datetime StartOfHour(datetime t) datetime StartOfDay(datetime t) datetime StartOfWeek(datetime t, bool StartsOnMonday = false) datetime StartOfMonth(datetime t) datetime StartOfYear(datetime t) //+==================================================================+ //| Unidades EndOf()| //+==================================================================+ datetime EndOfMinute(datetime t) datetime EndOfHour(datetime t) datetime EndOfDay(datetime t) datetime EndOfWeek(datetime t, bool StartsOnMonday = false) datetime EndOfMonth(datetime t) datetime EndOfYear(datetime t) //+==================================================================+ //| SecsElapsedOf() Unidades| //+==================================================================+ int SecsElapsedOfMinute(datetime t) int SecsElapsedOfHour(datetime t) int SecsElapsedOfDay(datetime t) int SecsElapsedOfWeek(datetime t, bool StartsOnMonday = false) int SecsElapsedOfMonth(datetime t) int SecsElapsedOfYear(datetime t) //+==================================================================+ //| Unidades RoundTo() / Nearest()| //+==================================================================+ datetime RoundToMinute(datetime t) datetime RoundToHour(datetime t) datetime RoundToDay(datetime t) datetime RoundToWeek(datetime t, bool StartsOnMonday = false) //+==================================================================+ //| Unidades CeilTo() / Next()| //+==================================================================+ datetime CeilToMinute(datetime t) datetime CeilToHour(datetime t) datetime CeilToDay(datetime t) datetime CeilToWeek(datetime t, bool StartsOnMonday = false) //+==================================================================+ //| Next() Día de la semana| //+==================================================================+ datetime NextWeekday(datetime t, ENUM_DAY_OF_WEEK weekday = SUNDAY) datetime NextSunday(datetime t) datetime NextMonday(datetime t) datetime NextTuesday(datetime t) datetime NextWednesday(datetime t) datetime NextThursday(datetime t) datetime NextFriday(datetime t) datetime NextSaturday(datetime t) //+==================================================================+ //| Previous() Día de la semana| //+==================================================================+ datetime PreviousWeekday(datetime t, ENUM_DAY_OF_WEEK weekday = SUNDAY) datetime PreviousSunday(datetime t) datetime PreviousMonday(datetime t) datetime PreviousTuesday(datetime t) datetime PreviousWednesday(datetime t) datetime PreviousThursday(datetime t) datetime PreviousFriday(datetime t) datetime PreviousSaturday(datetime t) //+==================================================================+ //| Nth() Día de la semana del mes| //+==================================================================+ datetime FirstWeekdayOfTheMonth(datetime t, ENUM_DAY_OF_WEEK weekday = SUNDAY) datetime LastWeekdayOfTheMonth(datetime t, ENUM_DAY_OF_WEEK weekday = SUNDAY) datetime NthWeekdayOfTheMonth(datetime t, int Nth, ENUM_DAY_OF_WEEK weekday = SUNDAY) //+==================================================================+ //| Unidades Add()| //+==================================================================+ datetime AddSeconds(datetime t, int amount) datetime AddMinutes(datetime t, int amount) datetime AddHours(datetime t, int amount) datetime AddDays(datetime t, int amount) datetime AddBusinessDays(datetime t, int amount) datetime AddWeeks(datetime t, int amount) datetime AddMonths(datetime t, int amount) datetime AddYears(datetime t, int amount) //+==================================================================+ //| Unidades Sub()| //+==================================================================+ datetime SubSeconds(datetime t, int amount) datetime SubMinutes(datetime t, int amount) datetime SubHours(datetime t, int amount) datetime SubDays(datetime t, int amount) datetime SubBusinessDays(datetime t, int amount) datetime SubWeeks(datetime t, int amount) datetime SubMonths(datetime t, int amount) datetime SubYears(datetime t, int amount) //+==================================================================+ //| Unidades DifferenceIn()| //+==================================================================+ int DifferenceInCalendarDays(datetime beginTime, datetime endTime) int DifferenceInBusinessDays(datetime beginTime, datetime endTime) int DifferenceInCalendarWeeks(datetime beginTime, datetime endTime, bool StartsOnMonday = false) int DifferenceInCalendarMonths(datetime beginTime, datetime endTime) //+==================================================================+ //| Unidades IsSame()| //+==================================================================+ bool IsSameMinute(datetime t1, datetime t2) bool IsSameHour(datetime t1, datetime t2) bool IsSameDay(datetime t1, datetime t2) bool IsSameWeek(datetime t1, datetime t2, bool StartsOnMonday = false) bool IsSameMonth(datetime t1, datetime t2) bool IsSameYear(datetime t1, datetime t2) //+==================================================================+ //| Unidades IsCurrent()| //+==================================================================+ bool IsCurrentMinute(datetime t) bool IsCurrentHour(datetime t) bool IsCurrentWeek(datetime t, bool StartsOnMonday = false) bool IsCurrentMonth(datetime t) bool IsCurrentYear(datetime t) bool IsToday(datetime t) bool IsTomorrow(datetime t) bool IsYesterday(datetime t) //+==================================================================+ //| Misc| //+==================================================================+ bool IsLeapYear(int year) int DaysInMonth(int year, int month) datetime GetNthWeekdayInYearMonth(iYear, iMonth, Nth, weekday = SUNDAY) datetime GetNthSundayInYearMonth(iYear, iMonth, Nth) //+==================================================================+ //| Formatear Hora a Cadena| //+==================================================================+ string t2s(datetime t, const int mode = TIME_DATE | TIME_MINUTES) string SecondsToString(int seconds) string TimeFormat(datetime t, string format = "YYYY.MM.DD hh:mm")
Lista de todos los formatos de hora disponibles:
//+------------------------------------------------------------------+ //| Obtener la hora formateada según la cadena de tokens pasada. | //| Lista de todos los formatos disponibles:| //| Formato Salida Descripción| //| ------ ---------------- ------------------------------------- | //| YY 18Año de dos dígitos //| AAAA 2018 Año de cuatro cifras| //| M 1-12El mes, empezando por 1 | //| MM 01-12 El mes, 2 dígitos | //| MMM Ene-Dic El nombre abreviado del mes, 3 letras | //| MMMM Enero-Diciembre El nombre completo del mes| //| D 1-31El día del mes | //| DD 01-31El día del mes, 2 dígitos | //| DDD Sun-Sat El nombre abreviado del día de la semana || DDD Sun-Sat //| DDDD Domingo-Sábado El nombre del día de la semana ||| DDDD Domingo-Sábado //| h 0-23 La hora| //| hh 00-23 La hora, 2 dígitos | //| H 1-12La hora, reloj de 12 horas | //| HH 01-12 La hora, reloj de 12 horas, 2 dígitos | //| m 0-59 El minuto| //| mm 00-59 El minuto, 2 dígitos | //| s 0-59 El segundo| //| ss 00-59 El segundo, de 2 dígitos | //| A AM PM| //| a am pm| //+------------------------------------------------------------------+ //| Formatos de muestra:| //| "AAAA.MM.DD hh:mm" // "2024.12.08 22:05" (por defecto) || "2024.12.08 22:05" (por defecto) //| "DDD, YYYY.MM.DD hh:mm:ss" // "Sun, 2024.12.08 22:05:21" || //| "D MMMM AAAA, HH:mm a" // "8 de diciembre de 2024, 22:05" | //| "DD/MM/AAAA" // "08/12/2024"| //+------------------------------------------------------------------+ string TimeFormat(const datetime t, const string format = "YYYY.MM.DD hh:mm");
Los dos scripts adjuntos "basic.mq5" y "advanced.mq5" muestran los ejemplos de uso básico y avanzado.
Un ejemplo de salida del script "advanced.mq5":
/*
salida de ejemplo:
1. CreateDateTime(2022, 03, 25) = 2022.03.25 00:00:00
[año] [mes] [día] [hora] [min] [seg] [día_de_la_semana] [día_del_año]
[0] 2024 12 18 17 27 25 3 352
2. t2s(t, TIME_DATE|TIME_SECONDS) = Wed, 2024.12.18 18:27:25
3. GetYear(t) = 2024
4. GetMonth(t) = 2024 GetMonth(t) = 12
5. GetDay(t) = 18
6. GetHour(t) = 18
7. GetMinute(t) = 18 GetMinute(t) = 27
8. GetSecond(t) = 27 8. GetSecond(t) = 25
9. DayOfWeek(t) = 3
10. DayOfYear(t) = 352
11. DayIndex(t) = 2007 DayIndex(t) = 20075
12. WeekOfMonth(t) = 3 WeekOfMonth(t) = 3
13. WeekOfYear(t) = 352 13. WeekOfYear(t) = 51
14. WeekIndex(t) = 2868
15. WeekOfMonth(t, true) = 4
16. WeekOfYear(t, true) = 51
17. WeekIndex(t, true) = 2868
StartOfMinute(t) = 2024.12.18 18:27:00
19. StartOfHour(t) = 2024.12.18 18:00:00
20. StartOfDay(t) = 2024.12.18 18:27:00 StartOfDay(t) = 2024.12.18 00:00:00
21. StartOfWeek(t) = 2024.12.18 00:00:00 StartOfWeek(t) = 2024.12.15 00:00:00
22. StartOfWeek(t) = 2024.12.15 00:00:00 StartOfWeek(t, true) = 2024.12.16 00:00:00
23. StartOfMonth(t, true) = 2024.12.18 00:00:00 StartOfMonth(t) = 2024.12.01 00:00:00
24. StartOfYear(t) = 2024.12.15 00:00:00 StartOfYear(t) = 2024.01.01 00:00:00
25. EndOfMinute(t) = 2024.12.16 00:00:00 EndOfMinute(t) = 2024.12.18 18:27:59
26. EndOfHour(t) = 2024.12.01 00:00:00 EndOfHour(t) = 2024.12.18 18:59:59
27. EndOfDay(t) = 2024.01.01 00:00:00 EndOfDay(t) = 2024.12.18 23:59:59
28. EndOfWeek(t) = 2024.12.18 23:27:59 EndOfWeek(t) = 2024.12.21 23:59:59
29. EndOfWeek(t) = 2024.12.18 23:59:59 EndOfWeek(t, true) = 2024.12.22 23:59:59
30. EndOfMonth(t, true) = 2024.12.18 23:59:59 EndOfMonth(t) = 2024.12.31 23:59:59
31. EndOfYear(t) = 2024.12.22 23:59:59 EndOfYear(t) = 2024.12.31 23:59:59
32. SecsElapsedOfMonth(t) = 2024.12.22 23:59:59 32. SegsElapsedOfMinute(t) = 25
33. SecsElapsedOfHinute(t) = 2024.12.31 23:59:59 SecsElapsedOfHour(t) = 1645
34. SecsElapsedOfMinute(t) = 25 34. SegsElapsedOfDay(t) = 66445
SecsElapsedOfWeek(t) = 325645
36. SecsElapsedOfWeek(t) = 325645 SecsElapsedOfWeek(t, true) = 239245
37. SecsElapsedOfMeek(t, true) = 325645 SecsElapsedOfMonth(t) = 1535245
38. SecsElapsedOfWeek(t, true) = 239245 SecsElapsedOfYear(t) = 30479245
39. RoundToMinute(t, true) = 239245 RoundToMinute(t) = 2024.12.18 18:27:00
40. RoundToHour(t) = 1535245 RoundToHour(t) = 2024.12.18 18:00:00
41. RoundToDay(t) = 2024.12.18 18:27:00 RoundToDay(t) = 2024.12.19 00:00:00
42. RoundToWeek(t) = 2024.12.18 00:27:00 RoundToWeek(t) = 2024.12.22 00:00:00
43. RoundToWeek(t) = 2024.12.18 00:00:00 RoundToWeek(t, true) = 2024.12.16 00:00:00
44. CeilToMinute(t, true) = 2024.12.19 00:00:00 CeilToMinute(t) = 2024.12.18 18:28:00
45. CeilToHour(t) = 2024.12.22 00:00:00 CeilToHour(t) = 2024.12.18 19:00:00
46. CeilToDay(t) = 2024.12.16 00:00:00 CeilToDay(t) = 2024.12.19 00:00:00
47. CeilToWeek(t) = 2024.12.18 19:00:00 48. CeilToWeek(t) = 2024.12.22 00:00:00
CeilToWeek(t, true) = 2024.12.23 00:00:00
49. PróximoDomingo(t) = 2024.12.19 00:00:00 NextSunday(t) = 2024.12.22 00:00:00
50. LunesSiguiente(t) = 2024.12.23 00:00:00
51. PróximoMartes(t) = 2024.12.23 00:00:00 51. PróximoMartes(t) = 2024.12.24 00:00:00
52. PróximoMiércoles(t) = 2024.12.24 00:00:00 52. PróximoMiércoles(t) = 2024.12.25 00:00:00
53. PróximoJueves(t) = 2024.12.23 00:00:00 PróximoJueves(t) = 2024.12.19 00:00:00
54. PróximoViernes(t) = 2024.12.24 00:00:00 PróximoViernes(t) = 2024.12.20 00:00:00
55. PróximoSábado(t) = 2024.12.25 00:00:00 55. PróximoSábado(t) = 2024.12.21 00:00:00
56. AnteriorDomingo(t) = 2024.12.19 00:00:00 PreviousSunday(t) = 2024.12.15 00:00:00
57. PreviousMonday(t) = 2024.12.16 00:00:00
58. PreviousTuesday(t) = 2024.12.21 00:00:00 AnteriorMartes(t) = 2024.12.17 00:00:00
59. AnteriorMiércoles(t) = 2024.12.15 00:00:00 AnteriorMiércoles(t) = 2024.12.11 00:00:00
60. AnteriorJueves(t) = 2024.12.16 00:00:00 60. AnteriorJueves(t) = 2024.12.12 00:00:00
61. AnteriorViernes(t) = 2024.12.17 00:00:00 AnteriorViernes(t) = 2024.12.13 00:00:00
62. AnteriorSábado(t) = 2024.12.11 00:00:00 AnteriorSábado(t) = 2024.12.14 00:00:00
63. PrimerDíaDeLaSemana(t) = 2024.12.13 00:00:00 63. PrimerDíaDeLaSemanaDelMes(t, DOMINGO) = 2024.12.01 00:00:00
64. ÚltimoDíaDeLaSemana(t, DOMINGO) = 2024.12.01 00:00:00 64. LastWeekdayOfTheMonth(t, SUNDAY) = 2024.12.29 00:00:00
65. AddSeconds(t, 30,00:00) = 2024.12.01 00:00:00 AddSeconds(t, 30) = 2024.12.18 18:27:55
66. AddMinutes(t, 30) = 2024.12.18 18:27:55 66. AddMinutes(t, 30) = 2024.12.18 18:57:25
67. AddHours(t, 2) = 2024.12.29 00:00:00 AddHours(t, 2) = 2024.12.18 20:27:25
68. AddDays(t, 10) = 2024.12.18 20:27:55 68. AddDays(t, 10) = 2024.12.28 18:27:25
AddBusinessDays(t, 10) = 2025.01.01 18:27:25
70. AddWeeks(t, 4) = 2024.12.18 20:27:25 70. AddWeeks(t, 4) = 2025.01.15 18:27:25
71. AddMonths(t, 2) = 2025.02.18 18:27:25
72. AddYears(t, 5) = 2025.01.01 18:27:25 72. AddYears(t, 5) = 2029.12.18 18:27:25
SubSegundos(t, 30) = 2024.12.18 18:26:55
74. SubMinutos(t, 30) = 2025.02.18 18:27:25 SubMinutos(t, 30) = 2024.12.18 17:57:25
75. SubHoras(t, 2) = 2029.12.18 17:27:25 SubHoras(t, 2) = 2024.12.18 16:27:25
76. SubDías(t, 10) = 2024.12.18 16:26:55 76. SubDays(t, 10) = 2024.12.08 18:27:25
77. SubBusinessDays(t, 30) = 2024.12.18 17:57:25 SubBusinessDays(t, 10) = 2024.12.04 18:27:25
78. SubWeeks(t, 4) = 2024.12.18 16:27:25 78. SubSemanas(t, 4) = 2024.11.20 18:27:25
79. SubMeses(t, 5) = 2024.12.08 18:27:25 SubMeses(t, 2) = 2024.10.18 18:27:25
80. SubAños(t, 5) = 2024.12.04 18:27:25 SubYears(t, 5) = 2019.12.18 18:27:25
81. DifferenceInCalendarDays(t, AddWeeks(t, 9)) = 63
82. DifferenceInBusinessDays(t, AddWeeks(t, 9)) = 45
83. 83. DifferenceInCalendarWeeks(t, AddWeeks(t, 9)) = 9
DifferenceInCalendarWeeks(t, AddWeeks(t, 9), true) = 9
85. DifferenceInCalendarMonths(t, AddWeeks(t, 9)) = 2
86. IsSameMinute(t, AddHours(t, 25)) = false
87. EsIgualHora(t, SumaHoras(t, 25)) = false
88. IsSameDay(t, AddHours(t, 25)) = false
89. IsSameWeek(t, AddHours(t, 25)) = false 89. IsSameWeek(t, AddHours(t, 25)) = true
90. IsSameWeek(t, AddHours(t, 25)) = false IsSameWeek(t, AddHours(t, 25), true) = true
91. IsSameMonth(t, AddHours(t, 25)) = false IsSameMonth(t, AddHours(t, 25)) = true
92. IsSameYear(t, AddHours(t, 25)) = true IsSameYear(t, AddHours(t, 25)) = true
93. IsCurrentMinute(t) = false
94. IsCurrentHour(t) = false
95. IsCurrentWeek(t) = verdadero
96. IsCurrentWeek(t, true) = true
97. IsCurrentMonth(t) = true
98. EsAñoActual(t) = true
99. EsHoy(t) = true
100. EsMañana(t) = true EsMañana(t) = falso
101. IsYesterday(t) = false
102. IsLeapYear(t) = true IsLeapYear(2100) = falso
103. DaysInMonth(2024) = verdadero DaysInMonth(2024, 2) = 29
104. GetNthWeekdayInth(t) = false GetNthWeekdayInYearMonth(2024, 1, 1, SUNDAY) = 2024.01.07 00:00:00
105. t2s(TimeCurrent()) = Wed, 2024.12.18 17:27
106. SecondsToString(SecsElapsedOfDay(TimeCurrent())) = 17:27:25
107. 107. TimeFormat(TimeCurrent(), YYYY.MM.DD hh:mm) = 2024.12.18 17:27
108. TimeFormat(TimeCurrent(), YYYY.MM.DD hh:mm) = 2024.12.18 17:27 TimeFormat(TimeCurrent(), DDD, AAAA.MM.DD hh:mm:ss) = Mié, 2024.12.18 17:27:25
109. TimeFormat(TimeCurrent(), D MMM AAAA, HH:mm a) = 18 Dic 2024, 05:27 pm
*/
Actualizaciones:
2024.12.03 - v.1.10 : Versión inicial.
2024.12.05 - v.1.15 : Añadidas funciones para días laborables y para Nth() día de la semana del mes. Optimizados los cálculos en la función DaysInMonth().
2024.12.09 - v.1.20 : Añadida función TimeFormat() para dar formato a la hora según la cadena de tokens pasada.
2024.12.09 - v.1.25 : Optimizados los cálculos en la función TimeToStructFast().
2024.12.10 - v.1.30 : Optimizadas las funciones TimeFormat(), StartOfYear() y EndOfYear(). Actualizadas las descripciones de algunas funciones.
2024.12.15 - v.1.35 : Optimizada la función GetNthWeekdayInYearMonth().
2024.12.18 - v.1.40 : Añadidas las funciones IsCurrentXXX(), IsToday(), IsTomorrow() y IsYesterday().
2024.12.19 - v.1.45 : Optimizadas las funciones AddMonths() y GetNthWeekdayInYearMonth().
2024.12.20 - v.1.50 : Más limpieza de código.
2024.12.21 - v.1.55 : Simplificados los cálculos en AddMonths(): sustituida la compleja lógica de ajuste de meses y años por un cálculo más simple del total de meses.
Traducción del inglés realizada por MetaQuotes Ltd.
Artículo original: https://www.mql5.com/en/code/53970

Buenas tardes chicos, soy un nuevo estudiante en metatrader5, estoy creando un robot para copiar operaciones de una cuenta demo y guardarlas en una base de datos me gustaria algo de ayuda para identificar posibles problemas, mejores soluciones para el codigo, etc.

MarketPredictor para MetaTrader 5 MarketPredictor es un innovador Asesor Experto (EA) para MetaTrader 5 que aprovecha modelos matemáticos como funciones senoidales, Transformada Rápida de Fourier (FFT), funciones sigmoidales y simulaciones Monte Carlo para analizar y predecir los movimientos del mercado. Este proyecto está diseñado para desarrolladores, entusiastas de las matemáticas y traders interesados en combinar innovaciones tecnológicas y financieras. Siéntete libre de sugerir, discutir e implementar ideas de código directamente en este hilo. Ya se trate de nuevas características, sugerencias de mejora, o estrategias - cada contribución es bienvenida para seguir desarrollando y optimizando el MarketPredictor. También eres bienvenido a agregarme para aclarar dudas en privado, colaborar en el proyecto de GitHub, o enviarme tus comentarios directamente. ¡Vamos a cocinar algo increíble juntos y llevar este proyecto al siguiente nivel!

El indicador Accumulation/Distribution (Acumulación/Distribución) queda determinado por los cambios que se producen en el precio y en el volumen.

El indicador Acceleration/Deceleration (AC, Aceleración/Desaceleración) mide la aceleración y la desaceleración de la fuerza impulsora del mercado.