forked from nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| Def.mqh |
| |
//| Copyright 2026, Niquel Mendoza. |
| |
//| https://www.mql5.com |
| |
//+------------------------------------------------------------------+
| |
#property copyright "Copyright 2026, Niquel Mendoza."
| |
#property link "https://www.mql5.com"
| |
#property strict
| |
| |
| |
#ifndef MQLARTICLES_UTILS_OBJECTS_FIBO_DEF_MQH
| |
#define MQLARTICLES_UTILS_OBJECTS_FIBO_DEF_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "..\\GraphicObjects.mqh"
| |
#include <TSN\\GCol\\HashMap.mqh>
| |
#include <TSN\\GCol\\GenericHashes.mqh>
| |
#include <TSN\\Std\\Basics\\ErrManager.mqh>
| |
#include <TSN\\Std\\Misce\\BitReinterprete.mqh>
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
namespace TSN
| |
{
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
// NOTAS:
| |
// La clase mezcla dos formas de "errores" en las funciones InitFibbo y Create la funcion no setea m_last_err
| |
// si no qeu usa la pila global de errores y ahi pone el error
| |
// pero en errores fuera de la config .... ahi si usa m_last_err como una clase de bajo nivel
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
struct pack(8) FibboLevel
| |
{
| |
double level_price;
| |
double level_value;
| |
color level_color;
| |
| |
//--- Constructores
| |
FibboLevel()
| |
: level_color(clrBlack), level_price(0.00), level_value(0.00) {}
| |
FibboLevel(const FibboLevel& other)
| |
: level_price(other.level_price), level_value(other.level_value), level_color(other.level_color) {}
| |
};
| |
| |
//---
| |
enum ENUM_MODE_NEAREST_LEVEL_FIBBO
| |
{
| |
FIBBO_LEVEL_MAYOR_A_TARGE_PRICE = 0,
| |
FIBBO_LEVEL_MENOR_A_TARGE_PRICE,
| |
};
| |
| |
| |
//---
| |
enum ENUM_TSNQMQLART_FIBBO_ERR
| |
{
| |
TSNQMQLART_FIBBO_ERR_NOT,
| |
| |
//--- init
| |
TSNQMQLART_FIBBO_ERR_FAILED_CREATE_OBJ,
| |
| |
//--- config
| |
TSNQMQLART_FIBBO_ERR_EMPTY_COLOR,
| |
TSNQMQLART_FIBBO_ERR_IN_PARSE_COLORS_STR,
| |
TSNQMQLART_FIBBO_ERR_FIBBO_VALUE_EMPTY,
| |
TSNQMQLART_FIBBO_ERR_ARRAYS_MUST_BE_EQUAL,
| |
TSNQMQLART_FIBBO_ERR_LEVELVALUE_IS_REPETIDO,
| |
| |
//--- ahora si valores de fallo en funciones
| |
TSNQMQLART_FIBBO_ERR_FAILED_MOVE_OBJECT,
| |
TSNQMQLART_FIBBO_ERR_FAILED_CALC_PRICE_INV_ARE_EQ,
| |
TSNQMQLART_FIBBO_ERR_FAILED_EMPTY_FIBBO,
| |
TSNQMQLART_FIBBO_ERR_FAILED_NOT_FOUND_NEAREST_LEVEL,
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| Formater de los errores del fibbo (pila global de errores) |
| |
//+------------------------------------------------------------------+
| |
#ifndef CFIBBO_MIN_VALUE
| |
#define CFIBBO_MIN_VALUE 0.00040
| |
#endif // CFIBBO_MIN_VALUE
| |
| |
//---
| |
class CFibboFormater
| |
{
| |
public:
| |
static void FormatTrace(const TSNErrorFrame &trace[], int &trace_idx, string &out);
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
static void CFibboFormater::FormatTrace(const TSNErrorFrame &trace[], int &trace_idx, string &out)
| |
{
| |
TSNSTD_ERRMAN_PUSHINI(out, trace_idx)
| |
switch(trace[trace_idx].code)
| |
{
| |
case TSNQMQLART_FIBBO_ERR_NOT:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "Not error", trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_FAILED_CREATE_OBJ:
| |
TSNSTD_ERRMAN_PUSHOUT(out, StringFormat("Failed to create the fibbo object, last err = %d", trace[trace_idx].mql_err), trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_EMPTY_COLOR:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "Empty color in the colors string (the string is empty or a color is missing between the separators)", trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_IN_PARSE_COLORS_STR:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "Failed to parse the colors string, caused by:", trace_idx)
| |
CFibboFormater::FormatTrace(trace, trace_idx, out); // el frame de abajo es de esta misma clase
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_FIBBO_VALUE_EMPTY:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "The fibbo levels string is empty or invalid (no values were found)", trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_ARRAYS_MUST_BE_EQUAL:
| |
TSNSTD_ERRMAN_PUSHOUT(out, StringFormat("The number of fibbo levels and colors must be equal [levels = %d | colors = %d]",
| |
int(trace[trace_idx].info), int(trace[trace_idx].info >> 32)), trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_LEVELVALUE_IS_REPETIDO:
| |
TSNSTD_ERRMAN_PUSHOUT(out, StringFormat("The fibbo level value [%.5f] is repeated (levels closer than %.5f are considered equal)",
| |
CBitsReinterprete::ToBasic<double, ulong>(trace[trace_idx].info), CFIBBO_MIN_VALUE), trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_FAILED_MOVE_OBJECT:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "Failed to move the fibbo object", trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_FAILED_CALC_PRICE_INV_ARE_EQ:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "Cannot calculate the fibbo prices, both prices are equal", trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_FAILED_EMPTY_FIBBO:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "The fibbo has no levels", trace_idx)
| |
break;
| |
case TSNQMQLART_FIBBO_ERR_FAILED_NOT_FOUND_NEAREST_LEVEL:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "No nearest level was found for the target price", trace_idx)
| |
break;
| |
default:
| |
TSNSTD_ERRMAN_PUSHOUT(out, "Unknow error", trace_idx)
| |
break;
| |
}
| |
}
| |
| |
//---
| |
//#define TSNMQLART_GRAPOBJ_FIBBO_ELOGS
| |
| |
//---
| |
#define FIBBO_FLAG_LEVEL_MODIFY_COLOR_SUCCESS (1)
| |
#define FIBBO_FLAG_LEVEL_MODIFY_STYLE_SUCCESS (2)
| |
#define FIBBO_FLAG_LEVEL_MODIFY_WIDTH_SUCCESS (4)
| |
| |
//---
| |
#define TSNMQLART_GRAPH_FIBBO_F_CREATED (1)
| |
#define TSNMQLART_GRAPH_FIBBO_F_DRAW_OBJ (2)
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CGenericUtilsSort_FibboLevel
| |
{
| |
public:
| |
CGenericUtilsSort_FibboLevel(void) {}
| |
~CGenericUtilsSort_FibboLevel(void) {}
| |
| |
//---
| |
static __forceinline bool Less(const FibboLevel& a, const FibboLevel& b) { return a.level_value < b.level_value; }
| |
static void Swap(FibboLevel& a, FibboLevel& b)
| |
{
| |
const FibboLevel temp = a;
| |
a = b;
| |
b = temp;
| |
}
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CFibboStrConvClr
| |
{
| |
public:
| |
CFibboStrConvClr(void) {}
| |
~CFibboStrConvClr(void) {}
| |
| |
//---
| |
static void ToValue(const string& str, int& pos, color& val, const int s_len)
| |
{
| |
//---
| |
ushort c = str[pos];
| |
| |
//--- trim ws inciatle emepmozas subiendo ..
| |
while(++pos < s_len && (c = str[pos]) < 33) {}
| |
| |
//---
| |
if(c == ',') // separador (no habia nada)
| |
{
| |
pos = TSNSTD_STRFUNC_TOARR_INT_FAILED_VALUE; // fallo
| |
CErrorTrace::FailInit<CFibboFormater>(TSNQMQLART_FIBBO_ERR_EMPTY_COLOR, 0);
| |
return;
| |
}
| |
| |
//--- inicalte saltmos el primer char "bueno" luego
| |
const int start = pos;
| |
while(++pos < s_len && str[pos] != ',') {}
| |
| |
//---
| |
val = StringToColor(str.Substr(start, pos - start));
| |
}
| |
};
| |
| |
}
| |
| |
#endif // MQLARTICLES_UTILS_OBJECTS_FIBO_DEF_MQH
| |
//+------------------------------------------------------------------+
|