//+------------------------------------------------------------------+ //| Main.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 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "Functions.mqh" // Source: https://www.youtube.com/watch?v=o0v4KQxZbpU&t=183s //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CEstrategia : public CStrategyBase { private: bool m_operate; uint8_t m_strategy_flags; double m_max_9; double m_min_9; //--- CEstrategia_FuncBos m_func_bos; //--- CEstrategia_FuncBos m_func_pda; //--- void Clean(); 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); //--- void OnNewBar(const datetime &curr_time) override; void OnNewWeek(datetime init_time) override; void OnInterupcion(); void OnTick() override {} }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CEstrategia::CEstrategia(ulong magic_number_, string symbol_, ENUM_TIMEFRAMES timeframe_ = PERIOD_CURRENT, long chart_id_ = 0, int subwindow_ = 0, ulong max_deviation_ = 0) : CStrategyBase(magic_number_, symbol_, timeframe_, chart_id_, subwindow_, max_deviation_, "TTRdes sb") { Clean(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CEstrategia::~CEstrategia(void) { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CEstrategia::OnNewWeek(datetime init_time) { g_bos_choch.DeleteAll(); g_fvg.DeleteAll(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CEstrategia::Clean(void) { m_strategy_flags = 0; m_func_bos = NULL; m_func_pda = NULL; m_max_9 = 0.000; m_min_9 = 0.000; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CEstrategia::OnInterupcion() { g_fvg.SetParo(); g_bos_choch.SetParo(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CEstrategia::OnNewBar(const datetime &curr_time) { if(risk.GetPositionsTotal() > 0) return; //--- if(g_sesion.EnSesion()) { if(g_sesion.IsInitSession()) { m_max_9 = ::iHigh(m_symbol, PERIOD_H1, 1); m_min_9 = ::iLow(m_symbol, PERIOD_H1, 1); m_operate = false; } if(m_operate) return; //--- if(m_strategy_flags == 0) { const double prev_high = ::iHigh(m_symbol, m_timeframe, 1); const double prev_low = ::iLow(m_symbol, m_timeframe, 1); if(prev_high > m_max_9) { m_strategy_flags |= S_FLAG_DIRECION_SELL; m_func_bos = EstrategiaFuncionts::EstRopturaAlaBaja; } else if(m_max_9 > prev_low) { m_strategy_flags |= S_FLAG_DIRECION_BUY; m_func_bos = EstrategiaFuncionts::EstRopturaAlAlza; } } else if((m_strategy_flags & S_FLAG_DEZPLAZAMIENTO_HECHO) == 0) { if(m_func_bos()) { m_strategy_flags |= S_FLAG_DEZPLAZAMIENTO_HECHO; if((m_strategy_flags & S_FLAG_DIRECION_BUY) != 0) { m_func_pda = EstrategiaFuncionts::PdaMigAlcista; } else { m_func_pda = EstrategiaFuncionts::PdaMitBajista; } } } else { if(m_func_pda()) { OpenOrder(((m_strategy_flags & S_FLAG_DIRECION_BUY) != 0 ? POSITION_TYPE_BUY : POSITION_TYPE_SELL)); } } } else if(g_sesion.IsEndSession()) { Clean(); } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| 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); risk.SetStopLoss(entry - sl); double l = m_LOT_SIZE > 0.00 ? m_LOT_SIZE : 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); risk.SetStopLoss(sl - entry); double l = m_LOT_SIZE > 0.00 ? m_LOT_SIZE : risk.GetLote(ORDER_TYPE_SELL, entry, m_max_deviation, 0); m_trade.Sell(l, m_symbol, entry, sl, tp, "Ea sell"); } Clean(); m_operate = true; } //+------------------------------------------------------------------+