Mira cómo descargar robots gratis
¡Búscanos en Facebook!
Pon "Me gusta" y sigue las noticias
Pon "Me gusta" y sigue las noticias
¿Es interesante este script?
Deje un enlace a él, ¡qué los demás también lo valoren!
Deje un enlace a él, ¡qué los demás también lo valoren!
¿Le ha gustado el script?
Evalúe su trabajo en el terminal MetaTrader 5
Evalúe su trabajo en el terminal MetaTrader 5
- Visualizaciones:
- 60
- Ranking:
- Publicado:
-
¿Necesita un robot o indicador basado en este código? Solicítelo en la bolsa freelance Pasar a la bolsa
#property copyright "Samson Mwita 2025" #property link "Samson Mwita 2025" #property version "1.00" #property description "Advanced price action-based dynamic exit strategy" #property description "Monitors Fibonacci, market structure, candlestick patterns" #property description "and behavioral patterns for optimal exit timing" //--- Parámetros de entrada input double ProfitActivationPercent = 70.0; // Empezar a monitorizar cuando la operación está a X% del TP input bool UseRSIReversal = true; // Utilizar el RSI para detectar retrocesos input int RSIPeriod = 14; // Periodo RSI input double RSIOverbought = 70.0; // RSI Nivel de sobrecompra input double RSI_Oversold = 30.0; // RSI Nivel de sobreventa input bool UseCandlestickPatterns = true; // Utilizar patrones de velas input bool UseMovingAverageCross = false; // Utilice la cruz MA para la confirmación input int FastMA_Period = 5; // Periodo MA rápido input int SlowMA_Period = 10; // Periodo MA lento input int CheckEveryXSeconds = 10; // Frecuencia de comprobación (segundos) //+------------------------------------------------------------------+ //| Función de inicio del programa de script| //+------------------------------------------------------------------+ void OnStart() { //--- Mostrar mensaje de script iniciado Print("Dynamic Exit Protector Started - Monitoring Trades..."); //--- Crear un temporizador para la monitorización continua EventSetTimer(CheckEveryXSeconds); } //+------------------------------------------------------------------+ //| Función temporizador - se ejecuta cada X segundos || //+------------------------------------------------------------------+ void OnTimer() { CheckAndProtectTrades(); } //+------------------------------------------------------------------+ //| Función principal para comprobar y proteger las operaciones | //+------------------------------------------------------------------+ void CheckAndProtectTrades() { int total = PositionsTotal(); for(int i = total-1; i >= 0; i--) { ulong ticket = PositionGetTicket(i); if(ticket > 0) { string symbol = PositionGetString(POSITION_SYMBOL); double volume = PositionGetDouble(POSITION_VOLUME); double openPrice = PositionGetDouble(POSITION_PRICE_OPEN); double currentProfit = PositionGetDouble(POSITION_PROFIT); ulong type = PositionGetInteger(POSITION_TYPE); double sl = PositionGetDouble(POSITION_SL); double tp = PositionGetDouble(POSITION_TP); //--- Saltar si no hay Take Profit if(tp == 0) continue; double currentPrice = (type == POSITION_TYPE_BUY) ? SymbolInfoDouble(symbol, SYMBOL_BID) : SymbolInfoDouble(symbol, SYMBOL_ASK); //--- Calcular lo cerca que estamos de TP (en porcentaje) double distanceToTP = 0; double progressToTP = 0; if(type == POSITION_TYPE_BUY) { distanceToTP = tp - openPrice; progressToTP = (currentPrice - openPrice) / distanceToTP * 100; } else // Posición de VENTA { distanceToTP = openPrice - tp; progressToTP = (openPrice - currentPrice) / distanceToTP * 100; } //--- Si estamos lo suficientemente cerca de TP, comprobar si hay retrocesos if(progressToTP >= ProfitActivationPercent) { bool shouldClose = false; string reason = ""; //--- Comprobar RSI Reversal (si está activado) if(UseRSIReversal && CheckRSI_Reversal(symbol, type)) { shouldClose = true; reason = "RSI Reversal Signal"; } //--- Comprobar patrones de velas (si está activado) if(UseCandlestickPatterns && CheckCandlestickReversal(symbol, type)) { shouldClose = true; reason = "Candlestick Reversal Pattern"; } //--- Comprobar MA Cross (si está activado) if(UseMovingAverageCross && CheckMA_Cross(symbol)) { shouldClose = true; reason = "Moving Average Cross"; } //--- Seguridad adicional: Si el beneficio empieza a disminuir significativamente if(IsProfitDecreasing(symbol, ticket, currentProfit)) { shouldClose = true; reason = "Profit Retracement Detected"; } //--- Cerrar la operación si se cumple alguna condición de inversión if(shouldClose) { if(ClosePosition(ticket, symbol, volume, type)) { Print("Position #", ticket, " closed. Reason: ", reason, " | Progress to TP: ", DoubleToString(progressToTP, 1), "%", " | Final Profit: ", DoubleToString(currentProfit, 2)); } } } } } } //+------------------------------------------------------------------+ //| Comprobar RSI para señales de reversión| //+------------------------------------------------------------------+ bool CheckRSI_Reversal(string symbol, ulong positionType) { double rsi[]; ArraySetAsSeries(rsi, true); int handle = iRSI(symbol, PERIOD_CURRENT, RSIPeriod, PRICE_CLOSE); if(CopyBuffer(handle, 0, 0, 3, rsi) > 0) { // Para posiciones de COMPRA: Vigilar que el RSI entre en sobrecompra y gire a la baja if(positionType == POSITION_TYPE_BUY) { if(rsi[0] < rsi[1] && rsi[1] > RSIOverbought) return true; } // Para posiciones de VENTA: Esté atento a que el RSI entre en sobreventa y gire al alza else { if(rsi[0] > rsi[1] && rsi[1] < RSI_Oversold) return true; } } return false; } //+------------------------------------------------------------------+ //| Busca patrones de inversión de velas. //+------------------------------------------------------------------+ bool CheckCandlestickReversal(string symbol, ulong positionType) { MqlRates rates[]; ArraySetAsSeries(rates, true); if(CopyRates(symbol, PERIOD_CURRENT, 0, 3, rates) > 0) { // Patrón de inversión bajista simple para posiciones de COMPRA if(positionType == POSITION_TYPE_BUY) { // Comprobar si hay estrella fugaz o envolvente bajista if((rates[1].close > rates[1].open && rates[0].close < rates[0].open && rates[0].close < rates[1].open) || // Envolvente bajista (rates[0].high - MathMax(rates[0].open, rates[0].close) > MathAbs(rates[0].close - rates[0].open) * 2)) // Estrella fugaz return true; } // Patrón de inversión alcista simple para posiciones de VENTA else { // Compruebe si hay una envolvente alcista o un martillo if((rates[1].close < rates[1].open && rates[0].close > rates[0].open && rates[0].close > rates[1].open) || // Envolvente alcista (MathMin(rates[0].open, rates[0].close) - rates[0].low > MathAbs(rates[0].close - rates[0].open) * 2)) // Martillo return true; } } return false; } //+------------------------------------------------------------------+ //| Comprobar cruce de medias móviles| //+------------------------------------------------------------------+ bool CheckMA_Cross(string symbol) { double fastMA[], slowMA[]; ArraySetAsSeries(fastMA, true); ArraySetAsSeries(slowMA, true); int fast_handle = iMA(symbol, PERIOD_CURRENT, FastMA_Period, 0, MODE_SMA, PRICE_CLOSE); int slow_handle = iMA(symbol, PERIOD_CURRENT, SlowMA_Period, 0, MODE_SMA, PRICE_CLOSE); if(CopyBuffer(fast_handle, 0, 0, 2, fastMA) > 0 && CopyBuffer(slow_handle, 0, 0, 2, slowMA) > 0) { // Comprobar si hay cruce bajista (la MA rápida cruza por debajo de la MA lenta) if(fastMA[1] > slowMA[1] && fastMA[0] < slowMA[0]) return true; } return false; } //+------------------------------------------------------------------+ //| Comprueba si el beneficio disminuye significativamente. //+------------------------------------------------------------------+ bool IsProfitDecreasing(string symbol, ulong ticket, double currentProfit) { // En una aplicación real, es posible que desee realizar un seguimiento de la historia de los beneficios // Esta es una versión simplificada - podrías almacenar valores de beneficios anteriores // y comparar si el beneficio ha disminuido en un determinado porcentaje // Por ahora, utilizaremos un enfoque simple basado en el movimiento de los precios static double lastProfit = 0; static ulong lastTicket = 0; if(lastTicket != ticket) { lastProfit = currentProfit; lastTicket = ticket; return false; } // Si el beneficio disminuye más de un 20% desde su máximo if(currentProfit < lastProfit * 0.8 && currentProfit > 0) { return true; } // Actualiza el último beneficio si el actual es mayor if(currentProfit > lastProfit) { lastProfit = currentProfit; } return false; } //+------------------------------------------------------------------+ //| Función de posición de cierre| //+------------------------------------------------------------------+ bool ClosePosition(ulong ticket, string symbol, double volume, ulong type) { MqlTradeRequest request = {1}; MqlTradeResult result = {0}; request.action = TRADE_ACTION_DEAL; request.position = ticket; request.symbol = symbol; request.volume = volume; request.deviation = 10; request.comment = "Dynamic Exit"; if(type == POSITION_TYPE_BUY) { request.type = ORDER_TYPE_SELL; request.price = SymbolInfoDouble(symbol, SYMBOL_BID); } else { request.type = ORDER_TYPE_BUY; request.price = SymbolInfoDouble(symbol, SYMBOL_ASK); } return OrderSend(request, result); } //+------------------------------------------------------------------+ //| Función de desinicialización| //+------------------------------------------------------------------+ //+------------------------------------------------------------------+
Traducción del inglés realizada por MetaQuotes Ltd.
Artículo original: https://www.mql5.com/en/code/66130
VR Locker Lite - Estrategia comercial basada en un bloqueo positivo
Funciona mediante un bloqueo positivo; el robot comercial crea un bloqueo positivo y el trader decide qué hacer con él.
Estrategia comercial Heads or Tails
La versión clásica de la estrategia comercial Heads or Tails con el análisis del código del bloque de señal.
iCrosshair - Real-Time Candle Metrics on Hover
Pase el ratón sobre cualquier vela para ver lo que MT5 no muestra: Tamaño de rango, Porcentaje de cuerpo, Ratios de mecha. Inteligente, rápido y personalizable.
Accelerator Oscillator (AC)
El indicador Acceleration/Deceleration (AC, Aceleración/Desaceleración) mide la aceleración y la desaceleración de la fuerza impulsora del mercado.
