Schau, wie man Roboter kostenlos herunterladen kann
Finden Sie uns auf Facebook!
und werden Sie Mitglied unserer Fangruppe
Interessantes Skript?
Veröffentliche einen Link auf das Skript, damit die anderen ihn auch nutzen können
Hat Ihnen das Skript gefallen?
Bewerten Sie es im Terminal MetaTrader 5
Skripte

Price Action Dynamic Exit Strategy - Profit Shield pro - Skript für den MetaTrader 5

Ansichten:
37
Rating:
(2)
Veröffentlicht:
\MQL5\Include\
metaeditor_view.png (199.05 KB)
MQL5 Freelance Benötigen Sie einen Roboter oder Indikator, der auf diesem Code basiert? Bestellen Sie ihn im Freelance-Bereich Zum Freelance

Meta-Editor-Ansicht

#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"
//--- Eingabeparameter
input double   ProfitActivationPercent = 70.0;  // Beginn der Überwachung, wenn der Handel X% vom TP entfernt ist
input bool     UseRSIReversal = true;           // RSI zur Erkennung von Umkehrungen verwenden
input int      RSIPeriod = 14;                  // RSI Zeitraum
input double   RSIOverbought = 70.0;            // RSI Überkauftes Niveau
input double   RSI_Oversold = 30.0;             // RSI überverkauftes Niveau
input bool     UseCandlestickPatterns = true;   // Candlestick-Muster verwenden
input bool     UseMovingAverageCross = false;   // MA-Kreuz zur Bestätigung verwenden
input int      FastMA_Period = 5;               // Schneller MA-Zeitraum
input int      SlowMA_Period = 10;              // Langsamer MA-Zeitraum
input int      CheckEveryXSeconds = 10;         // Wie oft soll geprüft werden (Sekunden)

//+------------------------------------------------------------------+
//| Skript-Programmstartfunktion|
//+------------------------------------------------------------------+
void OnStart()
{
   //--- Meldung über den Start des Skripts anzeigen
   Print("Dynamic Exit Protector Started - Monitoring Trades...");
   
   //--- Erstellen eines Timers für die kontinuierliche Überwachung
   EventSetTimer(CheckEveryXSeconds);
}

//+------------------------------------------------------------------+
//| Timerfunktion - läuft alle X Sekunden ab |
//+------------------------------------------------------------------+
void OnTimer()
{
   CheckAndProtectTrades();
}

//+------------------------------------------------------------------+
//| Hauptfunktion zum Prüfen und Schützen von Geschäften |
//+------------------------------------------------------------------+
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);
         
         //--- Überspringen, wenn kein Take Profit gesetzt ist
         if(tp == 0) continue;
         
         double currentPrice = (type == POSITION_TYPE_BUY) ? SymbolInfoDouble(symbol, SYMBOL_BID) : SymbolInfoDouble(symbol, SYMBOL_ASK);
         
         //--- Berechnen, wie nahe wir dem TP sind (in Prozent)
         double distanceToTP = 0;
         double progressToTP = 0;
         
         if(type == POSITION_TYPE_BUY)
         {
            distanceToTP = tp - openPrice;
            progressToTP = (currentPrice - openPrice) / distanceToTP * 100;
         }
         else // Position VERKAUFEN
         {
            distanceToTP = openPrice - tp;
            progressToTP = (openPrice - currentPrice) / distanceToTP * 100;
         }
         
         //--- Wenn wir nahe genug am TP sind, prüfen wir auf Umkehrungen
         if(progressToTP >= ProfitActivationPercent)
         {
            bool shouldClose = false;
            string reason = "";
            
            //--- RSI-Umkehrung prüfen (falls aktiviert)
            if(UseRSIReversal && CheckRSI_Reversal(symbol, type))
            {
               shouldClose = true;
               reason = "RSI Reversal Signal";
            }
            
            //--- Candlestick-Muster prüfen (falls aktiviert)
            if(UseCandlestickPatterns && CheckCandlestickReversal(symbol, type))
            {
               shouldClose = true;
               reason = "Candlestick Reversal Pattern";
            }
            
            //--- MA Cross prüfen (falls aktiviert)
            if(UseMovingAverageCross && CheckMA_Cross(symbol))
            {
               shouldClose = true;
               reason = "Moving Average Cross";
            }
            
            //--- Zusätzliche Sicherheit: Wenn der Gewinn deutlich abnimmt
            if(IsProfitDecreasing(symbol, ticket, currentProfit))
            {
               shouldClose = true;
               reason = "Profit Retracement Detected";
            }
            
            //--- Schließen Sie den Handel, wenn eine Umkehrbedingung erfüllt ist.
            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));
               }
            }
         }
      }
   }
}

//+------------------------------------------------------------------+
//| RSI auf Umkehrsignale prüfen|
//+------------------------------------------------------------------+
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)
   {
      // Für KAUFEN-Positionen: Achten Sie darauf, dass der RSI in den überkauften Bereich geht und nach unten dreht.
      if(positionType == POSITION_TYPE_BUY)
      {
         if(rsi[0] < rsi[1] && rsi[1] > RSIOverbought)
            return true;
      }
      // Für SELL-Positionen: Achten Sie darauf, dass der RSI in den überverkauften Bereich geht und nach oben dreht.
      else
      {
         if(rsi[0] > rsi[1] && rsi[1] < RSI_Oversold)
            return true;
      }
   }
   
   return false;
}

//+------------------------------------------------------------------+
//| Prüfung auf Candlestick-Umkehrmuster |
//+------------------------------------------------------------------+
bool CheckCandlestickReversal(string symbol, ulong positionType)
{
   MqlRates rates[];
   ArraySetAsSeries(rates, true);
   
   if(CopyRates(symbol, PERIOD_CURRENT, 0, 3, rates) > 0)
   {
      // Einfaches bärisches Umkehrmuster für BUY-Positionen
      if(positionType == POSITION_TYPE_BUY)
      {
         // Auf bärische Engulfing oder Shooting Star prüfen
         if((rates[1].close > rates[1].open && rates[0].close < rates[0].open && 
             rates[0].close < rates[1].open) || // Bearish engulfing
            (rates[0].high - MathMax(rates[0].open, rates[0].close) > 
             MathAbs(rates[0].close - rates[0].open) * 2)) // Sternschnuppe
            return true;
      }
      // Einfaches bullisches Umkehrmuster für SELL-Positionen
      else
      {
         // Auf bullish engulfing oder Hammer prüfen
         if((rates[1].close < rates[1].open && rates[0].close > rates[0].open && 
             rates[0].close > rates[1].open) || // Bullish engulfing
            (MathMin(rates[0].open, rates[0].close) - rates[0].low > 
             MathAbs(rates[0].close - rates[0].open) * 2)) // Hammer
            return true;
      }
   }
   
   return false;
}

//+------------------------------------------------------------------+
//| Prüfung auf gleitenden Durchschnitt|
//+------------------------------------------------------------------+
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)
   {
      // Auf bärisches Kreuz prüfen (schneller MA kreuzt unter langsamem MA)
      if(fastMA[1] > slowMA[1] && fastMA[0] < slowMA[0])
         return true;
   }
   
   return false;
}

//+------------------------------------------------------------------+
//| Prüfen, ob der Gewinn signifikant sinkt |
//+------------------------------------------------------------------+
bool IsProfitDecreasing(string symbol, ulong ticket, double currentProfit)
{
   // In einer realen Implementierung möchten Sie vielleicht den Gewinnverlauf verfolgen
   // Dies ist eine vereinfachte Version - man könnte auch frühere Gewinnwerte speichern
   // und vergleichen, ob der Gewinn um einen bestimmten Prozentsatz gesunken ist
   
   // Für den Moment verwenden wir einen einfachen Ansatz, der auf der Preisbewegung basiert
   static double lastProfit = 0;
   static ulong lastTicket = 0;
   
   if(lastTicket != ticket)
   {
      lastProfit = currentProfit;
      lastTicket = ticket;
      return false;
   }
   
   // Wenn der Gewinn um mehr als 20 % gegenüber seinem Höchststand sinkt
   if(currentProfit < lastProfit * 0.8 && currentProfit > 0)
   {
      return true;
   }
   
   // Aktualisieren Sie den letzten Gewinn, wenn der aktuelle höher ist
   if(currentProfit > lastProfit)
   {
      lastProfit = currentProfit;
   }
   
   return false;
}

//+------------------------------------------------------------------+
//| Funktion Position schließen|
//+------------------------------------------------------------------+
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);
}

//+------------------------------------------------------------------+
//| Deinitialisierungsfunktion|
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+


Übersetzt aus dem Englischen von MetaQuotes Ltd.
Originalpublikation: https://www.mql5.com/en/code/66130

SilviosEAbest26 SilviosEAbest26

SilviosEAbest26 is a high-precision Expert Advisor for MetaTrader 5, designed to trade market reversals using a sophisticated combination of dynamic price channels and momentum filters. The system is engineered for consistent returns while maintaining strict risk management protocols.

VR Locker Lite - Handelsstrategie basierend auf einer positiven Lock VR Locker Lite - Handelsstrategie basierend auf einer positiven Lock

Funktioniert mithilfe einer positiven Lock; der Handelsroboter erstellt eine positive Lock, und der Trader entscheidet selbst, was damit zu tun ist.

Accumulation/Distribution Accumulation/Distribution

Der Accumulation/Distribution Indikator wird aus Änderung von Preis und Volumen bestimmt.

Accelerator Oszillator (AC) Accelerator Oszillator (AC)

Der Acceleration/Deceleration Indikator (AC) misst die Beschleunigung und Verlangsamung des aktuellen Marktimpulses, der Kraft der Kursbewegung.