294 行
无行尾
20 KiB
MQL5
294 行
无行尾
20 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Functions.mqh |
|
|
//| Copyright 2025, Niquel Mendoza. |
|
|
//| https://www.mql5.com/es/users/nique_372/news |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2025, Niquel Mendoza."
|
|
#property link "https://www.mql5.com/es/users/nique_372/news"
|
|
#property strict
|
|
|
|
#ifndef ICTLIBRARYEASY_SRC_BASE_FUNCTIONS_MQH
|
|
#define ICTLIBRARYEASY_SRC_BASE_FUNCTIONS_MQH
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
inline bool GetMaxPriceVela(int start, int end, int &maxIndex, ENUM_TIMEFRAMES period, string symbol)
|
|
{
|
|
if(start < end || start < 0)
|
|
return false;
|
|
maxIndex = iHighest(symbol, period, MODE_HIGH, (start - end) + 1, end);
|
|
return maxIndex == -1 ? false : true;
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline bool GetMinPriceVela(int start, int end, int &minIndex, ENUM_TIMEFRAMES period, string symbol)
|
|
{
|
|
if(start < end || start < 0)
|
|
return false;
|
|
minIndex = iLowest(symbol, period, MODE_LOW, (start - end) + 1, end);
|
|
return minIndex == -1 ? false : true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline double GetMaxPriceInRange(int start, int end, ENUM_TIMEFRAMES period, string symbol)
|
|
{
|
|
if(start < end || start < 0)
|
|
return false;
|
|
int maxIndex = iHighest(symbol, period, MODE_HIGH, (start - end) + 1, end);
|
|
return maxIndex == -1 ? 0.00 : iHigh(symbol, period, maxIndex);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline double GetMinPriceInRange(int start, int end, ENUM_TIMEFRAMES period, string symbol)
|
|
{
|
|
if(start < end || start < 0)
|
|
return false;
|
|
int minIndex = iLowest(symbol, period, MODE_LOW, (start - end) + 1, end);
|
|
return minIndex == -1 ? 0.00 : iLow(symbol, period, minIndex);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline double GetMaxPriceInRange(const datetime start, const datetime end, ENUM_TIMEFRAMES period, string symbol)
|
|
{
|
|
if(start > end || start > TimeCurrent())
|
|
return 0.00;
|
|
int maxIndex = iHighest(symbol, period, MODE_HIGH, (iBarShift(symbol, period, start) - iBarShift(symbol, period, end)) + 1, iBarShift(symbol, period, end));
|
|
return maxIndex == -1 ? 0.00 : iHigh(symbol, period, maxIndex);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline double GetMinPriceInRange(const datetime start, const datetime end, ENUM_TIMEFRAMES period, string symbol)
|
|
{
|
|
if(start > end || start > TimeCurrent())
|
|
return 0.00;
|
|
int minIndex = iLowest(symbol, period, MODE_LOW, (iBarShift(symbol, period, start) - iBarShift(symbol, period, end)) + 1, iBarShift(symbol, period, end));
|
|
return minIndex == -1 ? 0.00 : iLow(symbol, period, minIndex);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
datetime MitigadoLineMaxTime(double price, const datetime inicio_, const datetime _end, string symbol, ENUM_TIMEFRAMES timeframe)
|
|
{
|
|
int inicio = iBarShift(symbol, timeframe, inicio_);
|
|
int end = _end == 0 ? 0 : iBarShift(symbol, timeframe, _end);
|
|
|
|
if(inicio < end)
|
|
{
|
|
PrintFormat("%s Error | Start %i is greater than end %i >> Timeframe: %s", __FUNCTION__, inicio, end, EnumToString(timeframe));
|
|
return 0;
|
|
}
|
|
|
|
int count = inicio - end;
|
|
|
|
NormalizeDouble(price, _Digits);
|
|
double highs[];
|
|
ArraySetAsSeries(highs, true);
|
|
int totalBars = CopyHigh(symbol, timeframe, end, count + 1, highs); // Copia todas las velas hasta el índice 'inicio'
|
|
|
|
if(totalBars <= 0)
|
|
{
|
|
PrintFormat("%s: Error | No se pudieron copair velas desde %s - hasta %s", __FUNCTION__, TimeToString(inicio_), TimeToString(_end));
|
|
return 0; // Error al copiar datos
|
|
}
|
|
|
|
for(int i = totalBars - 1; i >= 0; i--)
|
|
{
|
|
if(price < highs[i])
|
|
return iTime(symbol, timeframe, end + i);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
datetime MitigadoLineMinTime(double price, const datetime inicio_, const datetime _end, string symbol, ENUM_TIMEFRAMES timeframe)
|
|
{
|
|
int inicio = iBarShift(symbol, timeframe, inicio_);
|
|
int end = _end == 0 ? 0 : iBarShift(symbol, timeframe, _end);
|
|
|
|
if(inicio < end)
|
|
{
|
|
PrintFormat("%s Error | Start %i is greater than end %i >> Timeframe: %s", __FUNCTION__, inicio, end, EnumToString(timeframe));
|
|
return 0;
|
|
}
|
|
|
|
int count = inicio - end;
|
|
|
|
NormalizeDouble(price, _Digits);
|
|
double lows[];
|
|
ArraySetAsSeries(lows, true);
|
|
int totalBars = CopyLow(symbol, timeframe, end, count + 1, lows); // Copia todas las velas hasta el índice 'inicio'
|
|
|
|
if(totalBars <= 0)
|
|
{
|
|
PrintFormat("%s: Error | No se pudieron copair velas desde %s - hasta %s", __FUNCTION__, TimeToString(inicio_), TimeToString(_end));
|
|
return 0; // Error al copiar datos
|
|
}
|
|
|
|
for(int i = totalBars - 1; i >= 0; i--)
|
|
{
|
|
if(price > lows[i])
|
|
return iTime(symbol, timeframe, end + i);
|
|
}
|
|
|
|
return 0; // No se mitigó hasta el momento
|
|
}
|
|
|
|
//---
|
|
datetime MitigadoLineMaxIndex(double price, const int inicio, const int end, string symbol, ENUM_TIMEFRAMES timeframe)
|
|
{
|
|
if(inicio < end)
|
|
{
|
|
PrintFormat("%s Error | Start %i is greater than end %i >> Timeframe: %s", __FUNCTION__, inicio, end, EnumToString(timeframe));
|
|
return 0;
|
|
}
|
|
|
|
int count = inicio - end;
|
|
|
|
NormalizeDouble(price, _Digits);
|
|
double highs[];
|
|
ArraySetAsSeries(highs, true);
|
|
int totalBars = CopyHigh(symbol, timeframe, end, count + 1, highs); // Copia todas las velas hasta el índice 'inicio'
|
|
|
|
if(totalBars <= 0)
|
|
return 0; // Error al copiar datos
|
|
|
|
for(int i = totalBars - 1; i >= 0; i--)
|
|
{
|
|
if(price < highs[i])
|
|
return iTime(symbol, timeframe, end + i);
|
|
}
|
|
|
|
return 0; // No se mitigó hasta el momento
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
datetime MitigadoLineMinIndex(double price, const int inicio, const int end, string symbol, ENUM_TIMEFRAMES timeframe)
|
|
{
|
|
if(inicio < end)
|
|
{
|
|
PrintFormat("%s Error | Start %i is greater than end %i >> Timeframe: %s", __FUNCTION__, inicio, end, EnumToString(timeframe));
|
|
return 0;
|
|
}
|
|
|
|
int count = inicio - end;
|
|
|
|
NormalizeDouble(price, _Digits);
|
|
double lows[];
|
|
ArraySetAsSeries(lows, true);
|
|
int totalBars = CopyLow(symbol, timeframe, end, count + 1, lows); // Copia todas las velas hasta el índice 'inicio'
|
|
|
|
if(totalBars <= 0)
|
|
return 0; // Error al copiar datos
|
|
|
|
for(int i = totalBars - 1; i >= 0; i--)
|
|
{
|
|
if(price > lows[i])
|
|
return iTime(symbol, timeframe, end + i);
|
|
}
|
|
|
|
return 0; // No se mitigó hasta el momento
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
datetime LineMinRota(double price, MqlRates &rates[], datetime inicio, datetime end, ENUM_TIMEFRAMES timeframe, string symbol)
|
|
{
|
|
NormalizeDouble(price, _Digits);
|
|
|
|
int inicio_index = iBarShift(symbol, timeframe, inicio);
|
|
int end_index = iBarShift(symbol, timeframe, end);
|
|
|
|
if(inicio_index >= ArraySize(rates) || inicio_index < 0)
|
|
{
|
|
PrintFormat("%s: Error | Start index %i is greater than %i, rate array size, or index %+i is less than 0", __FUNCTION__, inicio_index, ArraySize(rates), inicio_index);
|
|
return 0;
|
|
}
|
|
//PrintFormat("El incio %s con index %i, el fin %s con index %i",TimeToString(inicio),inicio_index,TimeToString(end),end_index);
|
|
for(int i = inicio_index; i >= end_index; i--)
|
|
{
|
|
if(price > rates[i].close)
|
|
return rates[i].time;
|
|
}
|
|
|
|
return 0; // No se mitigó hasta el momento
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
datetime LineMaxRota(double price, MqlRates &rates[], datetime inicio, datetime end, ENUM_TIMEFRAMES timeframe, string symbol)
|
|
{
|
|
NormalizeDouble(price, _Digits);
|
|
|
|
int inicio_index = iBarShift(symbol, timeframe, inicio);
|
|
int end_index = iBarShift(symbol, timeframe, end);
|
|
|
|
if(inicio_index >= ArraySize(rates) || inicio_index < 0)
|
|
{
|
|
PrintFormat("%s: Error | Start index %i is greater than %i, rate array size, or index %+i is less than 0", __FUNCTION__, inicio_index, ArraySize(rates), inicio_index);
|
|
return 0;
|
|
}
|
|
|
|
for(int i = inicio_index; i >= end_index; i--)
|
|
{
|
|
if(price < rates[i].close)
|
|
return rates[i].time;
|
|
}
|
|
|
|
return 0; // No se mitigó hasta el momento
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
datetime LineMinRota(double price, datetime inicio, datetime end, ENUM_TIMEFRAMES timeframe, string symbol)
|
|
{
|
|
NormalizeDouble(price, _Digits);
|
|
|
|
int inicio_index = iBarShift(symbol, timeframe, inicio);
|
|
int end_index = end > TimeCurrent() ? 0 : iBarShift(symbol, timeframe, end);
|
|
|
|
if(inicio_index < 0)
|
|
return 0;
|
|
|
|
|
|
int count = inicio_index - end_index;
|
|
|
|
double closes[];
|
|
ArraySetAsSeries(closes, true);
|
|
CopyClose(symbol, timeframe, end_index, count + 1, closes);
|
|
|
|
for(int i = inicio_index; i >= end_index; i--)
|
|
{
|
|
if(price > closes[i])
|
|
return iTime(symbol, timeframe, i);
|
|
}
|
|
|
|
return 0; // No se mitigó hasta el momento
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
datetime LineMaxRota(double price, datetime inicio, datetime end, ENUM_TIMEFRAMES timeframe, string symbol)
|
|
{
|
|
NormalizeDouble(price, _Digits);
|
|
|
|
int inicio_index = iBarShift(symbol, timeframe, inicio);
|
|
int end_index = end > TimeCurrent() ? 0 : iBarShift(symbol, timeframe, end);
|
|
|
|
if(inicio_index < 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int count = inicio_index - end_index;
|
|
|
|
double closes[];
|
|
ArraySetAsSeries(closes, true);
|
|
CopyClose(symbol, timeframe, end_index, count + 1, closes);
|
|
|
|
|
|
for(int i = inicio_index; i >= end_index; i--)
|
|
{
|
|
if(price < closes[i])
|
|
return iTime(symbol, timeframe, i);
|
|
}
|
|
|
|
return 0; // No se mitigó hasta el momento
|
|
}
|
|
#endif // ICTLIBRARYEASY_SRC_BASE_FUNCTIONS_MQH |