5 Tages Breakout Strategie

 
Hallo liebe Coder Community,

bin noch ziemlich neu was das programmieren in MQL 4 anbelangt. Jetzt ist meine Frustrationstoleranz ziemlich nah an einem Maximum.
Über Hilfe, Kritik, Anregungen und neue Ideen würde ich mich sehr freuen.

Die Idee ist simpel. Das Muster tritt immer mal wieder auf. Über alle Märkte hinweg. Unter H4 häufen sich Fehltrades und die Genauigkeit nimmt stark ab. Mit etwas Geschick kann man aber dennoch auch auf H1 kurzfristige Zuwächse abgreifen.
Es ist eine reine Buy Strategie!

Nun zu den Bedingungen!
Wir betrachten 4 Tageskerzen. Die erste zur linken muss Bullisch sein! Die nächsten 3 Kerzen müssen ihren CLOSE Preis in der Range der ersten bullischen Kerzen haben! Dochte nach oben und unten sind ok!

Das ist unser Fenster. Ist dieses Muster erfüllt, soll am nächsten Tag bei Eröffnung der neuen Tageskerze eine Buy Order platziert werden.
Weiter überprüfen wir, ob wir Sommer oder Winterzeit haben. Damit wollen wir sicherstellen, dass unser EA zur richtigen Zeit seine Überprüfung startet.


Der Code den ich mir nun zurecht gebastelt habe, funktioniert aber nicht richtig und übersieht beim Backtest dieses Muster scheinbar. 

Der Code scheint logisch nicht korrekt zu sein.

Die angehängte .png Bilddatei zeigt das Muster im EUR CAD. Dieses Mal war es einzigartig und trat gleich zweimal hintereinander auf. Das kann man auch auf tieferen Zeitebenen wie H1 häufig feststellen. 
Markiert mit der roten und orangen Zone! 
//+------------------------------------------------------------------+
//|                              5Days BO EXPERT ADVISOR Vers. 2.mq4 |
//|                                                               ce |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "ce"
#property link      ""
#property version   "1.00"
#property strict
datetime lastCheckedTime = 0;  // To store the last day the EA checked

// Function to check if a candle is bullish
bool IsBullish(double open, double close) {
   return close > open;
}

// Function to check if a candle is within the range of another candle
bool IsWithinRange(double high, double low, double ref_high, double ref_low) {
   return high <= ref_high && low >= ref_low;  // High must be <= ref high, and low must be >= ref low
}

// Function to load candles into an array
void LoadCandles(double &candles[][5], int shift) {         //use the & operator when defining the function parameter: double &candles[][6]. This tells MQL4 that the candles array is passed by reference.
   for(int i = 0; i < 4; i++) {
      candles[i][0] = iTime(NULL, PERIOD_D1, i + shift);   // Time
      candles[i][1] = iOpen(NULL, PERIOD_D1, i + shift);   // Open
      candles[i][2] = iHigh(NULL, PERIOD_D1, i + shift);   // High
      candles[i][3] = iLow(NULL, PERIOD_D1, i + shift);    // Low
      candles[i][4] = iClose(NULL, PERIOD_D1, i + shift);  // Close
      //candles[i][5] = iVolume(NULL, PERIOD_D1, i + shift); // Volume
   }
}

// Function to place a buy order
void PlaceBuyOrder(double stopLoss, double takeProfit) {
   // Place a buy order with SL and TP
   int ticket = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, stopLoss, takeProfit, "Buy Order", 0, 0, clrGreen);
   
   if(ticket > 0) {
      Print("Buy order placed successfully with Ticket: ", ticket);
   } else {
      Print("Error placing buy order: ", GetLastError());
   }
}

// Function to determine if it's winter or summer time
bool IsSummerTime() {
   // This function checks whether it's summer based on the broker's timezone
   // Summer time is considered from the last Sunday of March to the last Sunday of October in most regions
   datetime now = TimeCurrent();
   int month = TimeMonth(now);
   
   if(month > 3 && month < 10) return true;   // Summer time (April to September)
   
   if(month == 3) {
      // Check for the last Sunday of March
      int dayOfMonth = TimeDay(now);
      int dayOfWeek = TimeDayOfWeek(now);
      if(dayOfMonth - dayOfWeek >= 24) return true;  // Last Sunday of March
   }
   
   if(month == 10) {
      // Check for the last Sunday of October
      int dayOfMonth = TimeDay(now);
      int dayOfWeek = TimeDayOfWeek(now);
      if(dayOfMonth - dayOfWeek < 25) return true;   // Before or on last Sunday
   }
   
   return false;  // Winter time by default
}

// Function to get the correct execution time
int GetExecutionHour() {
   return IsSummerTime() ? 23 : 0;  // 23:00 in Summer, 0:00 in Winter
}

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
   Print("Expert Advisor Initialized.");
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
   Print("Expert Advisor Deinitialized.");
}

//+------------------------------------------------------------------+
//| Expert once-a-day execution                                      |
//+------------------------------------------------------------------+
void OnTick() {
   datetime now = TimeCurrent();
   
   // Only run the EA if the current time is the execution hour and it's a new day
   int executionHour = GetExecutionHour();
   if(TimeHour(now) == executionHour && TimeDay(now) != TimeDay(lastCheckedTime)) {
      lastCheckedTime = now;  // Update the last checked time

      // Define the array to hold the candles
      double candles[4][6];
      int shift = 0;

      // Load candles into the array
      LoadCandles(candles, shift);

      // Check if the fourth candle (candles[3]) is bullish
      if (IsBullish(candles[3][1], candles[3][4])) {
         // Check if candles[2], candles[1], and candles[0] are within the range of candles[3]
         bool allWithinRange = true;  // Assume true, unless proven false
         
         for (int i = 0; i < 3; i++) { // Loop through candles[0] to candles[2]
            if (!IsWithinRange(candles[i][2], candles[i][3], candles[3][2], candles[3][3])) {
               allWithinRange = false;
               break; // Exit the loop if any candle is out of range
            }
         }

         // If all candles are within range, we wait for the 5th day to place a buy order
         if (allWithinRange) {
            Print("Window Matched! Waiting for the 5th day to place a buy order.");

            // Wait for the next day (5th day) to place the buy order
            while (TimeDay(Time[0]) == TimeDay(candles[3][0])) {
               // Continue waiting until the new day starts
               Sleep(1000);
            }

            // Calculate stop loss (5 pips below the low of candles[3])
            double stopLoss = candles[3][3] - 5 * Point;

            // Calculate the range of candles[3] and take profit (2 times the range)
            double range = candles[3][2] - candles[3][3];
            double takeProfit = Ask + (1.5 * range);

            // Place the buy order on the 5th day
            PlaceBuyOrder(stopLoss, takeProfit);

            return;  // After placing the order, no need to process further for this day
         }
      }
   }
}


Hat jemand vielleicht eine Idee um den Code besser zu gestallten?

Danke im Voraus für jede Hilfe, Kritik und Idee! :)  
 

Wenn Due neu bist in MQL4:

  1. Warum MT4/MQL4? Ist langsamer als MT5/MQL5: https://www.mql5.com/ru/forum/360210/page39#comment_20702140
  2. Wird nicht mehr weiter entwickelt
  3. Wird irgendwann eingestellt: https://www.mql5.com/en/forum/454319

also warum nicht gleich MT5/MQL5?

Außerdem es gibt fast nichts, was nicht schon für MQL5 programmiert wurde, suchen lernen geht schneller als programmieren lernen:

Zu break out gibt es 1500 Seite à 10 Vorschlägen: https://www.mql5.com/en/search#!keyword=break%20out

Filter nach Artikel und/oder CodeBase (links). Das hat den Vorteil, das funktioniert und läuft, ob es aber Gewinne macht ist eine andere Frage => Testen siehe das dazu: https://www.mql5.com/de/articles/mt5/strategy_tester

Новая версия платформы MetaTrader 5 build 2755: Улучшения в окне котировок и отладчике - Попробуйте добавить возможность отображать описание объектов при наведении на них указателя мыши. Поддерживаю, что вы не можете давать одно и то же
Новая версия платформы MetaTrader 5 build 2755: Улучшения в окне котировок и отладчике - Попробуйте добавить возможность отображать описание объектов при наведении на них указателя мыши. Поддерживаю, что вы не можете давать одно и то же
  • 2021.02.11
  • prostotrader
  • www.mql5.com
Потери пакетов считаются на всем сетевом интерфейсе по всему трафику. что всегда разгоняет packet loss level на интерфейсе. где из-за огромных системных задержек сеть деградирует и живет только за счет постоянных ретрансмитов пакетов сбойные сетевые компоненты сети