704 lines
54 KiB
MQL5
704 lines
54 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Swings.mqh |
|
|
//| Copyright 2025, Leo. |
|
|
//| https://www.mql5.com/es/users/nique_372/news |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2025, Leo."
|
|
#property link "https://www.mql5.com/es/users/nique_372/news"
|
|
#property strict
|
|
|
|
#ifndef ICTLIBRARYEASY_SRC_CONCEPTS_SWINGS_MQH
|
|
#define ICTLIBRARYEASY_SRC_CONCEPTS_SWINGS_MQH
|
|
#include "..\\Base\\Imports.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
//Flujo de trabajo:
|
|
//La clase CSwingBar, consta unicamente de la obtencion de swings y dibujado, esto que se ejecuta a cada nueva vela (OnNewBar)
|
|
|
|
//--- Declaracion previa
|
|
class CSwingBarPure;
|
|
class CSwingBarZigZag;
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
class CSwingBar : public CLoggerBase
|
|
{
|
|
protected:
|
|
int m_handle_real; // Handle real al array de ISwings
|
|
int m_handle; // Handle especifico
|
|
ENUM_GET_SWING m_type_get_swing; // Tipo de swing
|
|
string m_symbol; // Simbolo del swing
|
|
ENUM_TIMEFRAMES m_timeframe; // Timeframe del swing
|
|
long m_chart_id; // ChartID del swing
|
|
int m_subwin; // SubVentana del swing
|
|
bool m_show_concept; // Bandera de la visibilidad INICIAL del concepto
|
|
|
|
//---
|
|
bool m_delete;
|
|
|
|
|
|
public:
|
|
CSwingBar();
|
|
~CSwingBar() { Destroy(); }
|
|
|
|
//--- Creacion
|
|
virtual void Create(string symbol, ENUM_TIMEFRAMES timeframe, long chart_id, int subwin, bool show_concept, MqlParam ¶metros[]) = 0;
|
|
|
|
//---
|
|
void CreateByHandle(int handle_real, int handle_especifico = INVALID_HANDLE);
|
|
|
|
|
|
//--- Destruccion
|
|
virtual bool Destroy(); // Destruye el swing, luego de esto hara falta crear un nuevo swing
|
|
|
|
//---
|
|
inline void SetProperties(color color_buy_swing, color color_sell_swing, string text_buy_swing_, string text_sell_swing_,
|
|
string font_ = "Arial", int8_t font_size_ = 7, int max_elements_array_ = ADD_ALL);
|
|
inline void OnNewBar(); // Ejecuta la logica principal
|
|
inline bool GetSwingPrev(const int range_obtencion); // Obtiene swing previos
|
|
|
|
//--- Trabajo con los swings
|
|
inline BasicSwing GetSwingsAlcistas(const int pos_idx); // Obtiene un swing alcista en base a su posicion
|
|
inline BasicSwing GetSwingsBasjitas(const int pos_idx); // Obtiene un swingf bajista en base a su posicion
|
|
inline int SizeSwingAlcistas(); // Obtiene el tamaño total de swings alcistas
|
|
inline int SizeSwingBajistas(); // Obtiene el tamaño total de swings bajistas
|
|
|
|
//--- GetCloset obtener el mas cercano
|
|
// Obtiene el indice (pos) de un swing alcista cercano con el modo mode a tagerget_time
|
|
inline int GetCloseSwingAlcistaIndex(datetime target_time, MODE_CLOSET_INDEX mode);
|
|
|
|
// Obtiene el indice (pos) de un swing bajista cercano con el modo mode a tagerget_time
|
|
inline int GetCloseSwingBajistaIndex(datetime target_time, MODE_CLOSET_INDEX mode);
|
|
|
|
// Obtiene el indice (pos) del swing mas cercano con el modo "mode" a target_time, ademas de devolver el tipo de swing
|
|
// "tipo", puede ser a (swing alcista), o b (swing bajista)
|
|
inline int GetCloseSwingIndex(datetime target_time, MODE_CLOSET_INDEX mode, string &tipo);
|
|
|
|
//--- Comprobacion de la creacion de un swing
|
|
inline bool HayUnNuevoSwing(); // Devuelve true si se creo un nuevo swing para la nueva vela
|
|
|
|
// Devuelve el indice (podra ser consultado con GetSwingAlcista.. o GetSwingBa...) si se creo un nuevo swing del tipo
|
|
// type, si no se creo u swing para dicho tipo devolvera -1
|
|
inline int HayUnNuevoSwing(ENUM_TYPE_SWING type);
|
|
|
|
|
|
//--- Mas cercano
|
|
// Devuelve el swing mas cercano por precio y tiempo (el mas cercano el tiempo actual, osea el swing mas reciente)
|
|
// Ideal para dibujar Fibbo
|
|
inline BasicSwing GetSwingLowMasCeracanoPorPrecioYTime(double target_price, ENUM_TYPE_CERCANOS_SWING mode);
|
|
inline BasicSwing GetSwingHighMasCeracanoPorPrecioYTime(double target_price, ENUM_TYPE_CERCANOS_SWING mode);
|
|
|
|
//--- Setter y Getter generales
|
|
// Minima cantidad de elementos | Para el array interno swings alcista y swwings bajistas, por defecto 0, util
|
|
// Si es que siempre se necesita que las funciones de obtencion de data devuelvan un valor..
|
|
inline void MiniumElement(int min); // Setter, establece dicho valor (elementos minimos)
|
|
inline int MiniumElement(); // Getter, obtiene dicho valor (elementos minimos)
|
|
|
|
// Color del swing high | Si se cambia el color, NO SE ACTULIZARA LAS PROPIEDADES
|
|
// de los swings existentes.. osea que el cambio de color se vera
|
|
// reflejado en el siguiente swing creado luego del cambio del color
|
|
inline void SwingHighColor(color new_value);
|
|
inline color SwingHighColor();
|
|
|
|
// Color del swing low | Si se cambia el color, NO SE ACTULIZARA LAS PROPIEDADES
|
|
// de los swings existentes.. osea que el cambio de color se vera
|
|
// reflejado en el siguiente swing creado luego del cambio del color
|
|
inline void SwingLowColor(color new_value);
|
|
inline color SwingLowColor();
|
|
|
|
//- Lenth
|
|
inline int LenthAntes() { return ICTSwing_LenthAntes(m_handle_real); }
|
|
inline int LenthDespues() { return ICTSwing_LenthDespues(m_handle_real); }
|
|
|
|
|
|
//--- Funcionalidades
|
|
// Obtiene el tiempo en base a un indice y el tipo de swing
|
|
inline datetime GetTimeByIndex(const int index, ENUM_TYPE_SWING type);
|
|
|
|
// Devuelve el precio de un swing en base a su indice y tipo
|
|
inline double GetPriceByIndex(const int index, ENUM_TYPE_SWING type);
|
|
|
|
// Devuelve el indice de un swing en base al tiempo, si no se encutra un swing del tipo "type"
|
|
// Con el tiempo "time", devolvera -1
|
|
inline int GetIndexByTime(const datetime time, ENUM_TYPE_SWING type);
|
|
|
|
//--- Funciones de Log
|
|
inline void AddLogFlags(const uint8_t flags) override;
|
|
inline void RemoveLogFlags(const uint8_t flags) override;
|
|
|
|
//---
|
|
inline bool IsNewBarConcept();
|
|
inline bool ShowAll();
|
|
inline bool HideAll();
|
|
inline bool DeleteAll();
|
|
inline void SetFlagMostrarObjetos(bool mostrar);
|
|
inline void ForzeToActulizeCurrentTick();
|
|
virtual inline void SetParo() { }
|
|
|
|
//---
|
|
inline bool Delete() const { return m_delete;}
|
|
void Delete(const bool new_val) { m_delete = new_val; }
|
|
|
|
//--- General
|
|
inline ENUM_TIMEFRAMES Timeframe() const { return m_timeframe; }
|
|
inline string Simbolo() const { return m_symbol; }
|
|
inline int Subwindow() const { return m_subwin; }
|
|
inline long ChartId() const { return m_chart_id; }
|
|
inline bool ShowConcept() const { return m_show_concept; }
|
|
inline int Handle() const { return m_handle; }
|
|
inline int HandleReal() const { return m_handle_real; }
|
|
|
|
|
|
//--- Tipo de swing
|
|
inline ENUM_GET_SWING TypeSwing() const { return m_type_get_swing; }
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CSwingBar::CSwingBar()
|
|
{
|
|
m_handle = INVALID_HANDLE;
|
|
m_handle_real = INVALID_HANDLE;
|
|
m_type_get_swing = WRONG_VALUE;
|
|
m_symbol = NULL;
|
|
m_chart_id = 0;
|
|
m_subwin = 0;
|
|
m_show_concept = true;
|
|
m_delete = true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool CSwingBar::Destroy(void)
|
|
{
|
|
if(!m_delete)
|
|
{
|
|
LogWarning("El obejeto no puede ser eliminado", FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
|
|
if(m_handle == INVALID_HANDLE)
|
|
{
|
|
LogWarning("El obejto a eliminar ya es invalido", FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
//--- Eliminamos el swing
|
|
if(m_type_get_swing == ZIGZAG)
|
|
ICTSwingZigZag_Delete(m_handle, m_handle_real);
|
|
else
|
|
ICTSwingPure_Delete(m_handle, m_handle_real);
|
|
|
|
//--- Reset variables
|
|
m_handle = INVALID_HANDLE;
|
|
m_handle_real = INVALID_HANDLE;
|
|
m_type_get_swing = WRONG_VALUE;
|
|
m_symbol = NULL;
|
|
m_chart_id = 0;
|
|
m_subwin = 0;
|
|
m_show_concept = true;
|
|
return true;
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
/*
|
|
- Esta funcion crea un swing en base a un handle real existente y opcionalemten un handle especifico, si se especifica
|
|
el handle especifico se tiene la posiblidad de poner hacer dynamic cast (si es qeuy se cera un CSwingBar), de lo contrario
|
|
solo se pondran las funciones de CSwibngBar
|
|
*/
|
|
|
|
//---
|
|
void CSwingBar::CreateByHandle(int handle_real, int handle_especifico = INVALID_HANDLE)
|
|
{
|
|
if(m_handle != INVALID_HANDLE)
|
|
Destroy(); // Si tenmos un swing activo lo eliminamos
|
|
|
|
//---
|
|
m_handle_real = handle_real;
|
|
m_handle = handle_especifico;
|
|
m_delete = false; // No eliminar, dado qeu es una copia
|
|
|
|
//---
|
|
if(m_handle_real >= 0)
|
|
{
|
|
m_timeframe = ICTSwing_Timeframe(m_handle_real);
|
|
m_symbol = ICTSwing_Simbolo(m_handle_real);
|
|
m_chart_id = ICTSwing_ChartId(m_handle_real);
|
|
m_subwin = ICTSwing_Subwin(m_handle_real);
|
|
m_show_concept = ICTSwing_GetInittialStateObj(m_handle_real);
|
|
}
|
|
else
|
|
{
|
|
LogCriticalError(StringFormat("Handle real pasado %d es Invalido", handle_real), FUNCION_ACTUAL);
|
|
Remover();
|
|
}
|
|
|
|
//---
|
|
if(handle_especifico == INVALID_HANDLE)
|
|
{
|
|
LogWarning("EL handle especifico es invalido, no se podra hacer dynamic cast para usar funciones especificas", FUNCION_ACTUAL);
|
|
}
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::SetProperties(color color_buy_swing, color color_sell_swing, string text_buy_swing_, string text_sell_swing_,
|
|
string font_, int8_t font_size_, int max_elements_array_)
|
|
{
|
|
ICTSwing_SetProperties(m_handle_real, color_buy_swing, color_sell_swing, text_buy_swing_, text_sell_swing_, font_, font_size_, max_elements_array_);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::OnNewBar()
|
|
{
|
|
ICTSwing_OnNewBar(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline bool CSwingBar::GetSwingPrev(const int range_obtencion)
|
|
{
|
|
return ICTSwing_GetSwingPrev(m_handle_real, range_obtencion);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline BasicSwing CSwingBar::GetSwingsAlcistas(const int pos_idx)
|
|
{
|
|
return ICTSwing_GetSwingsAlcistas(m_handle_real, pos_idx);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline BasicSwing CSwingBar::GetSwingsBasjitas(const int pos_idx)
|
|
{
|
|
return ICTSwing_GetSwingsBasjitas(m_handle_real, pos_idx);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline int CSwingBar::SizeSwingAlcistas()
|
|
{
|
|
return ICTSwing_SizeSwingAlcistas(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline int CSwingBar::SizeSwingBajistas()
|
|
{
|
|
return ICTSwing_SizeSwingBajistas(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline int CSwingBar::GetCloseSwingAlcistaIndex(datetime target_time, MODE_CLOSET_INDEX mode)
|
|
{
|
|
return ICTSwing_GetCloseSwingAlcistaIndex(m_handle_real, target_time, mode);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline int CSwingBar::GetCloseSwingBajistaIndex(datetime target_time, MODE_CLOSET_INDEX mode)
|
|
{
|
|
return ICTSwing_GetCloseSwingBajistaIndex(m_handle_real, target_time, mode);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline int CSwingBar::GetCloseSwingIndex(datetime target_time, MODE_CLOSET_INDEX mode, string &tipo)
|
|
{
|
|
return ICTSwing_GetCloseSwingIndex(m_handle_real, target_time, mode, tipo);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline bool CSwingBar::HayUnNuevoSwing()
|
|
{
|
|
return ICTSwing_HayUnNuevoSwing(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline int CSwingBar::HayUnNuevoSwing(ENUM_TYPE_SWING type)
|
|
{
|
|
return ICTSwing_HayUnNuevoSwing(m_handle_real, type);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline BasicSwing CSwingBar::GetSwingLowMasCeracanoPorPrecioYTime(double target_price, ENUM_TYPE_CERCANOS_SWING mode)
|
|
{
|
|
return ICTSwing_GetSwingLowMasCeracanoPorPrecioYTime(m_handle_real, target_price, mode);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline BasicSwing CSwingBar::GetSwingHighMasCeracanoPorPrecioYTime(double target_price, ENUM_TYPE_CERCANOS_SWING mode)
|
|
{
|
|
return ICTSwing_GetSwingHighMasCeracanoPorPrecioYTime(m_handle_real, target_price, mode);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::MiniumElement(int min)
|
|
{
|
|
ICTSwing_MiniumElement(m_handle_real, min);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline int CSwingBar::MiniumElement()
|
|
{
|
|
return ICTSwing_MiniumElement(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::SwingHighColor(color new_value)
|
|
{
|
|
ICTSwing_SwingHighColor(m_handle_real, new_value);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline color CSwingBar::SwingHighColor()
|
|
{
|
|
return ICTSwing_SwingHighColor(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::SwingLowColor(color new_value)
|
|
{
|
|
ICTSwing_SwingLowColor(m_handle_real, new_value);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline color CSwingBar::SwingLowColor()
|
|
{
|
|
return ICTSwing_SwingLowColor(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline datetime CSwingBar::GetTimeByIndex(const int index, ENUM_TYPE_SWING type)
|
|
{
|
|
return ICTSwing_GetTimeByIndex(m_handle_real, index, type);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline double CSwingBar::GetPriceByIndex(const int index, ENUM_TYPE_SWING type)
|
|
{
|
|
return ICTSwing_GetPriceByIndex(m_handle_real, index, type);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline int CSwingBar::GetIndexByTime(const datetime time, ENUM_TYPE_SWING type)
|
|
{
|
|
return ICTSwing_GetIndexByTime(m_handle_real, time, type);
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::AddLogFlags(const uint8_t flags)
|
|
{
|
|
ICTSwing_AddLogFlag(m_handle_real, flags);
|
|
CLoggerBase::AddLogFlags(flags); // Añadimos al intero
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::RemoveLogFlags(const uint8_t flags)
|
|
{
|
|
ICTSwing_RemoveLogFlag(m_handle_real, flags);
|
|
CLoggerBase::RemoveLogFlags(flags); // Añadimos al intero
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline bool CSwingBar::IsNewBarConcept()
|
|
{
|
|
return ICTSwing_IsNewBarConcept(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline bool CSwingBar::ShowAll()
|
|
{
|
|
return ICTSwing_ShowAll(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline bool CSwingBar::HideAll()
|
|
{
|
|
return ICTSwing_HideAll(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline bool CSwingBar::DeleteAll()
|
|
{
|
|
return ICTSwing_DeleteAll(m_handle_real);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::SetFlagMostrarObjetos(bool mostrar)
|
|
{
|
|
ICTSwing_SetFlagMostrarObjetos(m_handle_real, mostrar);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline void CSwingBar::ForzeToActulizeCurrentTick()
|
|
{
|
|
ICTSwing_ForzeToActulizeCurrentTick(m_handle_real);
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Swing bar default |
|
|
//+------------------------------------------------------------------+
|
|
/*
|
|
- USo: esta clase se debera de usar al momento de crear una copia (CreateByHandle)..
|
|
*/
|
|
//---
|
|
class CSwingBarDefault : public CSwingBar
|
|
{
|
|
public:
|
|
void Create(string symbol, ENUM_TIMEFRAMES timeframe, long chart_id, int subwin, bool show_concept, MqlParam ¶metros[]) override { }
|
|
};
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Swing bar pure |
|
|
//+------------------------------------------------------------------+
|
|
class CSwingBarPure : public CSwingBar
|
|
{
|
|
public:
|
|
CSwingBarPure();
|
|
// Lo dejamos Inutilizable, dado que es una clase FIJA no podemos cambiar el tipo
|
|
//---
|
|
void Create(string symbol, ENUM_TIMEFRAMES timeframe, long chart_id, int subwin, bool show_concept, MqlParam ¶metros[]) override;
|
|
|
|
//---
|
|
bool Destroy() override;
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CSwingBarPure::CSwingBarPure(void)
|
|
{
|
|
m_type_get_swing = PURE_SWINGS;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CSwingBarPure::Create(string symbol, ENUM_TIMEFRAMES timeframe, long chart_id, int subwin, bool show_concept, MqlParam ¶metros[])
|
|
{
|
|
if(m_handle != INVALID_HANDLE)
|
|
Destroy(); // Si tenmos un swing activo lo eliminamos
|
|
|
|
//---
|
|
m_type_get_swing = PURE_SWINGS; // Obligamos a que sea pure swing
|
|
|
|
//---
|
|
m_handle = ICTSwingPure_Create(symbol, timeframe, chart_id, subwin, show_concept, parametros, m_handle_real);
|
|
|
|
if(m_handle >= 0)
|
|
{
|
|
m_timeframe = timeframe;
|
|
m_symbol = symbol;
|
|
m_chart_id = chart_id;
|
|
m_subwin = subwin;
|
|
m_show_concept = show_concept;
|
|
}
|
|
else
|
|
{
|
|
LogCriticalError("No se pudo crear un handle para CSwingBar del tipo pure", FUNCION_ACTUAL);
|
|
Remover();
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
// Nota, creo que no deberia de dar el error de funcion puramente virutal llamada.. no lo es.. por lo que al momento de desutrir este objeto
|
|
// Se llamara al destrucutro de CSwingBar (Desotry)
|
|
// Overrideo esto por que la propiedad "m_type_get_swing" NECESITO que se mantenga para no causar errore en getter TypeSwing
|
|
bool CSwingBarPure::Destroy(void)
|
|
{
|
|
if(!m_delete)
|
|
{
|
|
LogCaution("El obejeto no puede ser eliminado", FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
if(m_handle == INVALID_HANDLE)
|
|
{
|
|
LogWarning("El obejeto a eliminar ya es invalido", FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
//--- Eliminamos el swing
|
|
ICTSwingPure_Delete(m_handle, m_handle_real);
|
|
|
|
//--- Reset variables
|
|
m_handle = INVALID_HANDLE;
|
|
m_handle_real = INVALID_HANDLE;
|
|
m_symbol = NULL;
|
|
m_chart_id = 0;
|
|
m_subwin = 0;
|
|
m_show_concept = true;
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Swing bar zigzag |
|
|
//+------------------------------------------------------------------+
|
|
class CSwingBarZigZag : public CSwingBar
|
|
{
|
|
public:
|
|
CSwingBarZigZag(void);
|
|
//---
|
|
void Create(string symbol, ENUM_TIMEFRAMES timeframe, long chart_id, int subwin, bool show_concept, MqlParam ¶metros[]) override;
|
|
|
|
|
|
//---
|
|
inline double GetPriceZigZagAct();
|
|
inline ENUM_ZIGZAG_DIRECTION GetDirectionZigZagAct();
|
|
inline datetime GetLastTimeZigZag();
|
|
inline bool NewZigZagResize();
|
|
|
|
//---
|
|
bool Destroy() override;
|
|
inline void SetParo() override { ICTSwingZigZag_SetParo(m_handle); }
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CSwingBarZigZag::CSwingBarZigZag()
|
|
{
|
|
m_type_get_swing = ZIGZAG;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CSwingBarZigZag::Create(string symbol, ENUM_TIMEFRAMES timeframe, long chart_id, int subwin, bool show_concept, MqlParam ¶metros[])
|
|
{
|
|
if(m_handle != INVALID_HANDLE)
|
|
Destroy(); // Si tenemos un swing activo lo eliminamos
|
|
|
|
//---
|
|
m_type_get_swing = ZIGZAG; // Obligamos a que sea ZigZag...
|
|
m_handle = ICTSwingZigZag_Create(symbol, timeframe, chart_id, subwin, show_concept, parametros, m_handle_real);
|
|
|
|
if(m_handle >= 0)
|
|
{
|
|
m_timeframe = timeframe;
|
|
m_symbol = symbol;
|
|
m_chart_id = chart_id;
|
|
m_subwin = subwin;
|
|
m_show_concept = show_concept;
|
|
}
|
|
else
|
|
{
|
|
LogCriticalError("No se pudo crear un handle para CSwingBar del tipo ZigZag", FUNCION_ACTUAL);
|
|
Remover();
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
// Nota, creo que no deberia de dar el error de funcion puramente virutal llamada.. no lo es.. por lo que al momento de desutrir este objeto
|
|
// Se llamara al destrucutro de CSwingBar (Desotry)
|
|
// Overrideo esto por que la propiedad "m_type_get_swing" NECESITO que se mantenga para no causar errore en getter TypeSwing
|
|
bool CSwingBarZigZag::Destroy(void)
|
|
{
|
|
if(!m_delete)
|
|
{
|
|
LogCaution("El obejeto no puede ser eliminado", FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
if(m_handle == INVALID_HANDLE)
|
|
{
|
|
LogWarning("El obejeto a eliminar ya es invalido", FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
//--- Eliminamos el swing
|
|
ICTSwingZigZag_Delete(m_handle, m_handle_real);
|
|
|
|
//--- Reset variables
|
|
m_handle = INVALID_HANDLE;
|
|
m_handle_real = INVALID_HANDLE;
|
|
m_symbol = NULL;
|
|
m_chart_id = 0;
|
|
m_subwin = 0;
|
|
m_show_concept = true;
|
|
return true;
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline double CSwingBarZigZag::GetPriceZigZagAct()
|
|
{
|
|
return ICTSwingZigZag_GetPriceZigZagAct(m_handle);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline ENUM_ZIGZAG_DIRECTION CSwingBarZigZag::GetDirectionZigZagAct()
|
|
{
|
|
return ICTSwingZigZag_GetDirectionZigZagAct(m_handle);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline datetime CSwingBarZigZag::GetLastTimeZigZag()
|
|
{
|
|
return ICTSwingZigZag_GetLastTimeZigZag(m_handle);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
inline bool CSwingBarZigZag::NewZigZagResize()
|
|
{
|
|
return ICTSwingZigZag_NewZigZagResize(m_handle);
|
|
}
|
|
|
|
//+-------------------------------------------------------------------------------------+
|
|
//| En base a ciertos paraemtros, crea un array del tipo MqlParam |
|
|
//| Para la configuracion del swing del tipo ZigZag |
|
|
//| Inputs: |
|
|
//| - period_ : Periodo del ZigZag. |
|
|
//| - range_ : Rango de obtencion previo (para el calculo del ZigZag). |
|
|
//| - ocultar_zz : Booleano, que indicara si es necesario ocultar el indicador ZigZag . |
|
|
//| Out: |
|
|
//| - params: Array dinamico del tipo MqlParams, donde se configuraran los parametros |
|
|
//+-------------------------------------------------------------------------------------+
|
|
void ZZToParams(int16_t period_, int range_, bool ocultar_zz, MqlParam ¶m[])
|
|
{
|
|
ArrayResize(param, 3);
|
|
param[0].integer_value = period_;
|
|
param[1].integer_value = range_;
|
|
param[2].integer_value = (long)ocultar_zz;
|
|
}
|
|
|
|
//+-------------------------------------------------------------------------------------+
|
|
//| En base a ciertos paraemtros, crea un array del tipo MqlParam |
|
|
//| Para la configuracion del swing del tipo PURE. |
|
|
//| Inputs: |
|
|
//| - lenth_antes : Velas anteriores del swing, que se necesitaran |
|
|
// para considerar un swing. |
|
|
//| - lenth_despues : Velas posteriores del swing, que se necesitaran |
|
|
// para considerar un swing. |
|
|
//| - type_mode : Modo del swing, si es estricto se buscara consecutivadad |
|
|
//| De lo contrario solo que la vela swing sea el pico o o puntero mas |
|
|
//| bajo. |
|
|
//| Out: |
|
|
//| - params: Array dinamico del tipo MqlParams, donde se configuraran los parametros. |
|
|
//+-------------------------------------------------------------------------------------+
|
|
void PureToParmas(int16_t lenth_antes, int16_t lenth_despues, MODE_BUSQUEDA_SWING type_mode, MqlParam ¶m[])
|
|
{
|
|
ArrayResize(param, 3);
|
|
param[0].integer_value = lenth_despues;
|
|
param[1].integer_value = lenth_antes;
|
|
param[2].integer_value = type_mode;
|
|
}
|
|
|
|
|
|
#endif // ICTLIBRARYEASY_SRC_CONCEPTS_SWINGS_MQH
|
|
//+------------------------------------------------------------------+
|