ICTLibraryExamples/Base/Bloques/CustomBlock/Main.mqh
243 lines
20 KiB
MQL5
Nique_372
2026-01-07 08:22:58 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Main.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372"
#property strict
//+------------------------------------------------------------------+
Nique_372
2026-01-13 14:50:22 -05:00
//| |
Nique_372
2026-01-07 08:22:58 -05:00
//+------------------------------------------------------------------+
#include "..\\..\\..\\DefGlobal.mqh"
Nique_372
2026-01-13 14:50:22 -05:00
//---
Nique_372
2026-02-14 17:50:28 -05:00
// Notas:
Nique_372
2026-01-07 08:22:58 -05:00
// 1. Solo se permite dibujar el bloque.. como tal no agregados... si es necesario lo podria agregar.. por ahora creo que no
// 2. Llamo a las funciones Timeframe, ChartId, Subwin por que estos pueden ser volatiles.. no son fijos auqnue estos ultimos no pero pronto...
Nique_372
2026-02-14 17:50:28 -05:00
Nique_372
2026-01-13 14:50:22 -05:00
Nique_372
2026-01-07 08:22:58 -05:00
//#define USE_TICK
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-01-13 14:50:22 -05:00
#define ICTLIB_CUSTOMBLOCK_FVG_ID 0
Nique_372
2026-01-07 08:22:58 -05:00
Nique_372
2026-05-24 16:37:32 -05:00
Nique_372
2026-01-07 08:22:58 -05:00
//---
Nique_372
2026-01-13 14:50:22 -05:00
#ifdef USE_TICK
Nique_372
2026-01-07 08:22:58 -05:00
#define ICTLIB_BLOCK_HIDE(bloque) HIDE_OBJECT(bloque.name, ICTCustomBlocksTick_ChartId(m_handle)); \
HIDE_OBJECT(bloque.name_mitad_line, ICTCustomBlocksTick_ChartId(m_handle));
#else
Nique_372
2026-05-24 16:37:32 -05:00
Nique_372
2026-01-07 08:22:58 -05:00
#define ICTLIB_BLOCK_HIDE(bloque) HIDE_OBJECT(bloque.name, ICTCustomBlocksBar_ChartId(m_handle)); \
Nique_372
2026-01-13 14:50:22 -05:00
HIDE_OBJECT(bloque.name_mitad_line, ICTCustomBlocksBar_ChartId(m_handle));
Nique_372
2026-05-24 16:37:32 -05:00
Nique_372
2026-01-13 14:50:22 -05:00
#endif
Nique_372
2026-05-24 16:37:32 -05:00
Nique_372
2026-01-13 14:50:22 -05:00
Nique_372
2026-01-07 08:22:58 -05:00
//---
Nique_372
2026-05-24 16:37:32 -05:00
Nique_372
2026-01-07 08:22:58 -05:00
class CCustomFvg : public IIctLibCustomBlock
Nique_372
2026-05-24 16:37:32 -05:00
{
Nique_372
2026-01-07 08:22:58 -05:00
Nique_372
2026-01-13 14:50:22 -05:00
private:
Nique_372
2026-01-07 08:22:58 -05:00
MqlRates m_rates[];
Nique_372
2026-01-13 14:50:22 -05:00
public:
Nique_372
2026-01-07 08:22:58 -05:00
CCustomFvg(void) {}
~CCustomFvg(void) {}
//---
void OnSummary() const override final { Print(" Handle: ", m_handle); }
Nique_372
2026-05-24 16:37:32 -05:00
void Init(const IctLibBloqueInitConfig& config) override final;
void Draw(const Bloques& bloque, const ENUM_ORDERBLOCKS_TYPE type, const bool show_objetcs, const datetime extra_time);
Nique_372
2026-01-07 08:22:58 -05:00
void OnGetBlocks(bool& prev_data_calculated, const datetime extra_time, const bool show_concepts) override final;
Nique_372
2026-05-24 16:37:32 -05:00
//---
inline int Id() const override final { return ICTLIB_CUSTOMBLOCK_FVG_ID; } // Id para distinguir de otros bloques custom
inline bool UpdateConcepts() const override final { return false; } // Actuliza los conceptos (rectangulos)
Nique_372
2026-01-07 08:22:58 -05:00
inline uint8_t ModifyFlags() const override final { return ICTCOMPONENT_ALL_FLAGS_MODIFY; } // Banderas de modificacion (en este caso todas)
};
Nique_372
2026-05-24 16:37:32 -05:00
//+------------------------------------------------------------------+
//| |
Nique_372
2026-01-07 08:22:58 -05:00
//+------------------------------------------------------------------+
void CCustomFvg::OnGetBlocks(bool& prev_data_calculated, const datetime extra_time, const bool show_concepts)
{
//---
#ifdef USE_TICK
ResetLastError();
if(CopyRates(m_symbol_info.symbol, ICTCustomBlocksTick_Timeframe(m_handle), 1, 3, m_rates) != 3)
Nique_372
2026-05-24 16:37:32 -05:00
{
LogError("No se pudo obtener data", FUNCION_ACTUAL);
Nique_372
2026-01-07 08:22:58 -05:00
return;
}
#else
ResetLastError();
if(CopyRates(m_symbol_info.symbol, ICTCustomBlocksBar_Timeframe(m_handle), 1, 3, m_rates) != 3)
{
LogError("No se pudo obtener data", FUNCION_ACTUAL);
return;
}
#endif
//---
if(!prev_data_calculated) // SI no se calculo la data previa (entonces en teroia deberiamos de hacelro, en este caso NO.. para este ejemplo)
{
Nique_372
2026-02-14 17:50:28 -05:00
prev_data_calculated = true; // Ponemos que ya se calculo
Nique_372
2026-01-07 08:22:58 -05:00
Nique_372
2026-01-13 14:50:22 -05:00
// return false;// Omitimos esta llamada
}
// En caso se soporte se debera de veriicar que no haya sido mitigado para eso puede incluir el modeulo Functions..
Nique_372
2026-10-25 12:04:40 -05:00
// Y llamar a las funciones mitigados alcista o mitigados bajista... para verificar que el bloque a a<EFBFBD>adir No este mitigado
Nique_372
2026-01-13 14:50:22 -05:00
//---
Nique_372
2026-10-25 12:04:40 -05:00
Nique_372
2026-01-13 14:50:22 -05:00
const int one_vela = 2;
const int two_vela = 1;
const int tree_vela = 0;
Nique_372
2026-10-25 12:04:40 -05:00
Nique_372
2026-01-13 14:50:22 -05:00
//---
static Bloques blocke;
Nique_372
2026-10-25 12:04:40 -05:00
Nique_372
2026-01-13 14:50:22 -05:00
//---
if(m_rates[tree_vela].low > m_rates[one_vela].high && m_rates[two_vela].close > m_rates[two_vela].open)
Nique_372
2026-01-07 08:22:58 -05:00
{
blocke.price1 = m_rates[one_vela].high;
blocke.price2 = m_rates[tree_vela].low;
blocke.time1 = m_rates[two_vela].time;
Nique_372
2026-10-25 12:04:40 -05:00
Nique_372
2026-01-07 08:22:58 -05:00
blocke.name = m_bull_code + TimeToString(blocke.time1);
blocke.name_mitad_line = blocke.name + "-50";
Nique_372
2026-10-25 12:04:40 -05:00
blocke.mitad_price = GetPriceCoeficiente(blocke.price1, blocke.price2, 0.5);
Nique_372
2026-01-07 08:22:58 -05:00
if(m_handler.Add(blocke, BULL_OB))
Draw(blocke, BULL_OB, show_concepts, extra_time);
}
Nique_372
2026-10-25 12:04:40 -05:00
Nique_372
2026-01-07 08:22:58 -05:00
else
if(m_rates[one_vela].low > m_rates[tree_vela].high && m_rates[two_vela].open > m_rates[two_vela].close)
Nique_372
2026-10-25 12:04:40 -05:00
{
Nique_372
2026-01-07 08:22:58 -05:00
blocke.price1 = m_rates[one_vela].low;
blocke.price2 = m_rates[tree_vela].high;
Nique_372
2026-05-24 16:37:32 -05:00
Nique_372
2026-01-07 08:22:58 -05:00
blocke.time1 = m_rates[two_vela].time;
blocke.name = m_bear_code + TimeToString(blocke.time1);
blocke.name_mitad_line = blocke.name + "-50";
blocke.mitad_price = GetPriceCoeficiente(blocke.price1, blocke.price2, 0.5);
if(m_handler.Add(blocke, BEAR_OB))