//+------------------------------------------------------------------+ //| 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 //+------------------------------------------------------------------+ //| Include | //+------------------------------------------------------------------+ #include "Functions.mqh" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CEstrategia : public CStrategyBase { private: //--- Variables miembro bool m_has_trade; //--- Funciones void OpenOrder(ENUM_POSITION_TYPE type); public: CEstrategia(ulong magic_number_, string symbol_, ENUM_TIMEFRAMES timeframe_ = PERIOD_CURRENT, long chart_id_ = 0, int subwindow_ = 0, ulong max_deviation_ = NO_MAX_DEVIATION_DEFINED); ~CEstrategia(void) {} //--- Funciones de ejecucion void OnNewBar(const datetime &curr_time) override final; void OnTick(const datetime& curr_time) override final {} void OnNewWeek(const datetime& init_time, const datetime& curr_time) override final; void OnInterupcion() override final; }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CEstrategia::CEstrategia(ulong magic_number_, string symbol_, ENUM_TIMEFRAMES timeframe_ = PERIOD_CURRENT, long chart_id_ = 0, int subwindow_ = 0, ulong max_deviation_ = NO_MAX_DEVIATION_DEFINED) : CStrategyBase(magic_number_, symbol_, timeframe_, chart_id_, subwindow_, max_deviation_, "Estrategia simple") { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CEstrategia::OnNewBar(const datetime &curr_time) { //--- if(g_risk.GetPositionsTotal() > 0) return; //--- if(g_fvg.SizeAlcistasMitigados() > 0) { LogInfo("Mitigacion de order block alcista AHORA", FUNCION_ACTUAL); OpenOrder(POSITION_TYPE_BUY); } else if(g_fvg.SizeBajistasMitigados() > 0) { LogInfo("Mitigacion de order block bajista AHORA", FUNCION_ACTUAL); OpenOrder(POSITION_TYPE_SELL); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CEstrategia::OnNewWeek(const datetime &init_time, const datetime &curr_time) { g_fvg.DeleteAll(); // Limpiamos todos los ob, esto ayuda a reducir la carga de memoria, etc. } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CEstrategia::OnInterupcion(void) { // Dado que el concpeto OB se ejeucta con la estrateiga.. habra "un paro" cuando se supere el MDL etc.. // Por lo que en caso pase eso tenemos que AVISARLE a la clase que SE DENTRA su llamada (OnNewBar/OnTick) // Esto lo hacemos llamando a la funcion SetParo g_fvg.SetParo(); } //+------------------------------------------------------------------+ //| Open Order Default | //+------------------------------------------------------------------+ void CEstrategia::OpenOrder(ENUM_POSITION_TYPE type) { //--- ::SymbolInfoTick(m_symbol, m_tick); //--- if(type == POSITION_TYPE_BUY) { double entry = m_tick.ask; double sl = GetSL(entry, type, m_tick.time); double tp = GetTP(entry, type, m_tick.time); g_risk.SetStopLoss(entry - sl); double l = m_LOT_SIZE > 0.00 ? m_LOT_SIZE : g_risk.GetLote(ORDER_TYPE_BUY, entry, m_max_deviation, 0); m_trade.Buy(l, m_symbol, entry, sl, tp, "Ea buy"); } else if(type == POSITION_TYPE_SELL) { double entry = m_tick.bid; double sl = GetSL(entry, type, m_tick.time); double tp = GetTP(entry, type, m_tick.time); g_risk.SetStopLoss(sl - entry); double l = m_LOT_SIZE > 0.00 ? m_LOT_SIZE : g_risk.GetLote(ORDER_TYPE_SELL, entry, m_max_deviation, 0); m_trade.Sell(l, m_symbol, entry, sl, tp, "Ea sell"); } } //+------------------------------------------------------------------+