//+------------------------------------------------------------------+ //| MultyEstrategieRange.mqh | //| Copyright 2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Leo y Niquel" #property link "https://www.mql5.com" #property strict //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "Global.mqh" //+------------------------------------------------------------------+ //| Enumerations | //+------------------------------------------------------------------+ enum ENUM_TYPE_RETEST_RANGE { RETEST_STRICT, //Strict RETEST_NO_STRICT //No strict }; //+------------------------------------------------------------------+ //| Clase CRangeEstrategie | //+------------------------------------------------------------------+ class CRangeEstrategie : public ICTComponent { private: //--- Range CRange *range; //--- ENUM_MODE_STRATEGY_RANGE type_strategy; ENUM_TYPE_RETEST_RANGE type_retest_range; ENUM_TYPE_ROPTURA last_type; Range last_range; Range range_signal; //--- double entry_buy_price; double entry_sell_price; //--- bool en_proceso_devolver; void Reset(); //--- int max_espera; datetime max_espera_date; public: CRangeEstrategie(string symbol_, ENUM_TIMEFRAMES timf, long chart_id_, int subwin_, bool mostrar_obj, ENUM_MODE_STRATEGY_RANGE mode_strategy); ~CRangeEstrategie(); //--- Setters void SetProperties(color clr_range_, int width_range_, bool fill_range_, ENUM_LINE_STYLE style_range_, int16_t leth_swing_, ENUM_GET_SWING type_get, int prev_rabge_ob, CDiff* diff); void SetEspera(int espera_en_barras) { this.max_espera = espera_en_barras; } void SetPropertiesRangeByRestest(ENUM_TYPE_RETEST_RANGE type_retest_) { this.type_retest_range = type_retest_; } //--- General void OnNewBar(datetime curr_time); void InitPrev(int range_, SignalRange &signals[]) { this.range.GetPrev(range_, this.type_strategy, this.max_espera, signals); } inline double GetBuyPrice() const { return this.entry_buy_price; } inline double GetSellPrice() const { return this.entry_sell_price; } inline Range GetLastRange() const {return this.range_signal; } //--- Limpieza void OnEndTrade() { Reset(); } bool DeleteAll() override { return range.DeleteAll(); } //--- Objetos Graficos bool HideAll() override { return range.HideAll(); } bool ShowAll() override { return range.ShowAll(); } }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CRangeEstrategie::~CRangeEstrategie(void) { DeleteAll(); if(CheckPointer(range) != POINTER_INVALID) delete range; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CRangeEstrategie::CRangeEstrategie(string symbol_, ENUM_TIMEFRAMES timf, long chart_id_, int subwin_, bool mostrar_obj, ENUM_MODE_STRATEGY_RANGE mode_strategy) : ICTComponent(symbol_, chart_id_, subwin_, timf, mostrar_obj, Spanish, CONCEPT_STRATEGY_RANGE_BREAKOUT), last_type(WRONG_VALUE), en_proceso_devolver(false), max_espera_date(wrong_datetime) { this.type_strategy = mode_strategy; this.last_range.Reset(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CRangeEstrategie::SetProperties(color clr_range_, int width_range_, bool fill_range_, ENUM_LINE_STYLE style_range_, int16_t leth_swing_, ENUM_GET_SWING type_get, int prev_rabge_ob, CDiff* diff) { range = new CRange(this.symbol, this.timeframe, subwin, this.chart_id, true); range.Set(fill_range_, clr_range_, width_range_, style_range_, type_get, leth_swing_, prev_rabge_ob, diff); AddLogger(range); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CRangeEstrategie::Reset(void) { this.last_type = WRONG_VALUE; this.last_range.Reset(); this.en_proceso_devolver = false; this.max_espera_date = wrong_datetime; this.range.EstadoBusquedaRangos(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CRangeEstrategie::OnNewBar(datetime curr_time) { //--- range.OnNewBar(); //--- double curr_open; this.entry_buy_price = 0; this.entry_sell_price = 0; //--- if(this.type_strategy != RANGE_STRATEGY_BREAKOUT) { if(this.en_proceso_devolver) { if(this.type_strategy == RANGE_STRATEGY_BREAKOUT_AND_RETEST) { if(curr_time < this.max_espera_date) { double curr_low = iLow(this.symbol, this.timeframe, 1); double curr_high = iHigh(this.symbol, this.timeframe, 1); double curr_close = iClose(this.symbol, this.timeframe, 1); if(this.last_type == ROPTURA_HACIA_ABAJO) { if(curr_high > last_range.min_price && (last_range.min_price > curr_close || this.type_retest_range == RETEST_NO_STRICT)) { curr_open = iOpen(this.symbol, this.timeframe, 0); this.entry_sell_price = curr_open; this.entry_buy_price = 0; if(flag_enviar_alertas) { string mess = StringFormat("Multi Strategy Ranges Indicator MT5 | Sell signal now..\nEntry price = %.*f", symbol_ict.GetDigits(), entry_sell_price); SendAlertFlags(mess, types_alert, "Multi Strategy Ranges Indicator"); } range_signal = last_range; Reset(); } } else if(this.last_type == ROPTURA_HACIA_ARRIBA) { if(curr_low < last_range.max_price && (curr_close > last_range.max_price || this.type_retest_range == RETEST_NO_STRICT)) { curr_open = iOpen(this.symbol, this.timeframe, 0); this.entry_sell_price = 0; this.entry_buy_price = curr_open; if(flag_enviar_alertas) { string mess = StringFormat("Multi Strategy Ranges Indicator MT5 | Buy signal now..\nEntry price = %.*f", symbol_ict.GetDigits(), entry_buy_price); SendAlertFlags(mess, types_alert, "Multi Strategy Ranges Indicator"); } range_signal = last_range; Reset(); } } } else { Print("The maximum wait for retesting has been exceeded"); Reset(); return; } } else if(this.type_strategy == RANGE_STRATEGY_REENTRY) { if(curr_time < this.max_espera_date) { double curr_close = iClose(this.symbol, this.timeframe, 1); if(this.last_type == ROPTURA_HACIA_ABAJO) { if(curr_close > last_range.min_price) { curr_open = iOpen(this.symbol, this.timeframe, 0); this.entry_sell_price = 0; this.entry_buy_price = curr_open; if(flag_enviar_alertas) { string mess = StringFormat("Multi Strategy Ranges Indicator MT5 | Buy signal now..\nEntry price = %.*f", symbol_ict.GetDigits(), entry_buy_price); SendAlertFlags(mess, types_alert, "Multi Strategy Ranges Indicator"); } range_signal = last_range; Reset(); } } else if(this.last_type == ROPTURA_HACIA_ARRIBA) { if(last_range.max_price > curr_close) { curr_open = iOpen(this.symbol, this.timeframe, 0); this.entry_sell_price = curr_open; this.entry_buy_price = 0; if(flag_enviar_alertas) { string mess = StringFormat("Multi Strategy Ranges Indicator MT5 | Sell signal now..\nEntry price = %.*f", symbol_ict.GetDigits(), entry_sell_price); SendAlertFlags(mess, types_alert, "Multi Strategy Ranges Indicator"); } range_signal = last_range; Reset(); } } } else { Print("Maximum wait for range reentry has been exceeded"); Reset(); return; } } } } //--- if(range.GetTypeRoptura() == ROPTURA_HACIA_ABAJO) { curr_open = iOpen(this.symbol, this.timeframe, 1); if(this.type_strategy == RANGE_STRATEGY_BREAKOUT) { this.entry_sell_price = curr_open; this.entry_buy_price = 0; if(flag_enviar_alertas) { string mess = StringFormat("Multi Strategy Ranges Indicator MT5 | Sell signal now..\nEntry price = %.*f", symbol_ict.GetDigits(), entry_sell_price); SendAlertFlags(mess, types_alert, "Multi Strategy Ranges Indicator"); } range_signal = range.GetLastRange(); } else { this.last_type = ROPTURA_HACIA_ABAJO; this.en_proceso_devolver = true; this.last_range = range.GetLastRange(); this.max_espera_date = TimeCurrent() + (timeframe_principal_in_seconds * max_espera); this.range.EstadoBusquedaRangos(false); } } else if(range.GetTypeRoptura() == ROPTURA_HACIA_ARRIBA) { curr_open = iOpen(this.symbol, this.timeframe, 1); if(this.type_strategy == RANGE_STRATEGY_BREAKOUT) { this.entry_sell_price = 0; this.entry_buy_price = curr_open; if(flag_enviar_alertas) { string mess = StringFormat("Multi Strategy Ranges Indicator MT5 | Buy signal now..\nEntry price = %.*f", symbol_ict.GetDigits(), entry_buy_price); SendAlertFlags(mess, types_alert, "Multi Strategy Ranges Indicator"); } range_signal = range.GetLastRange(); } else { this.last_type = ROPTURA_HACIA_ARRIBA; this.en_proceso_devolver = true; this.last_range = range.GetLastRange(); this.range.EstadoBusquedaRangos(false); this.max_espera_date = TimeCurrent() + (timeframe_principal_in_seconds * max_espera); } } } //+------------------------------------------------------------------+