Discussing the article: "Automating Trading Strategies in MQL5 (Part 24): London Session Breakout System with Risk Management and Trailing Stops"

 

Check out the new article: Automating Trading Strategies in MQL5 (Part 24): London Session Breakout System with Risk Management and Trailing Stops.

In this article, we develop a London Session Breakout System that identifies pre-London range breakouts and places pending orders with customizable trade types and risk settings. We incorporate features like trailing stops, risk-to-reward ratios, maximum drawdown limits, and a control panel for real-time monitoring and management.

The London Session Breakout Strategy targets the increased volatility during the London market open by identifying the price range formed in the pre-London hours and placing pending orders to capture breakouts from that range. This strategy is important because the London session often experiences high liquidity and price movements, offering reliable opportunities for profit; however, it requires careful risk management to avoid false breakouts and drawdowns.

We will achieve this by calculating the pre-London high and low to set buy and sell stop orders with offsets, incorporating risk-to-reward ratios for take-profits, trailing stops for profit locking, and limits on open trades and daily drawdown to protect capital. We plan to use a control panel for real-time monitoring and session-specific checks to ensure trades only occur within defined ranges, making the system adaptable to varying market conditions. In a nutshell, here is a representation of the system we want to achieve.

STRATEGY BLUEPRINT

Author: Allan Munene Mutiiria

 
etherxp #:
Thank you;)

Welcome

 
Can you upload the indicator here?
 
hungxiro #:
Can you upload the indicator here?

Go through the article above please.

 
Nice article. Thank you for your efforts!
 
Kyle Young Sangster #:
Nice article. Thank you for your efforts!

Sure. Thanks for the kind feedback. Welcome.

 

I downloaded and ran this code as-is through the Strategy Tester. It finds the range each day, and draws the box on the chart. However, it doesn't take a trade each day, (assuming that it should). Over the course of 1.5 months, it took only 3 trades.


trade record


The second issue is the high / low levels and the buy / sell levels in the control panel do not update.

control panel not updating


The  high /low range levels are clearly being found on the chart, so I'm guessing the buy / sell levels should also be displayed on the chart and updated in the control panel, as they are derived directly from the high / low range levels.

What suggestions do you have to get this working correctly?

Thanks in advance.

 
Kyle Young Sangster #:

I downloaded and ran this code as-is through the Strategy Tester. It finds the range each day, and draws the box on the chart. However, it doesn't take a trade each day, (assuming that it should). Over the course of 1.5 months, it took only 3 trades.



The second issue is the high / low levels and the buy / sell levels in the control panel do not update.


The  high /low range levels are clearly being found on the chart, so I'm guessing the buy / sell levels should also be displayed on the chart and updated in the control panel, as they are derived directly from the high / low range levels.

What suggestions do you have to get this working correctly?

Thanks in advance.

Can't edit my comment; I'm using version 5.00, build 5214 of MT5

 
Kyle Young Sangster #:

I downloaded and ran this code as-is through the Strategy Tester. It finds the range each day, and draws the box on the chart. However, it doesn't take a trade each day, (assuming that it should). Over the course of 1.5 months, it took only 3 trades.



The second issue is the high / low levels and the buy / sell levels in the control panel do not update.


The  high /low range levels are clearly being found on the chart, so I'm guessing the buy / sell levels should also be displayed on the chart and updated in the control panel, as they are derived directly from the high / low range levels.

What suggestions do you have to get this working correctly?

Thanks in advance.

Hello. Thanks for the kind reply and feedback. Assuming you never really read the article, you just did plug and play; the program was developed in the AUDUSD symbol, so test it there first before going to other currencies. That will give you a deep understanding because points need adjustment as pairs change. You might need to also check the journal for possible clues as to why that would be failing, potentially due to wrong settings, but apparently the points for AUDUSD and EURUSD should almost work the same. For example, you are running it on EURUSD, so we take a similar test and try to see.

EURUSD TEST

From the image, see that there is an error there. Such would cause the test not to run correctly. 

Another potential reason would be unreliable historical data, especially when running it using very old data. In your example, you run from 2020. So let's test and see for the period evident in your screenshot.

POOR HISTORICAL DATA

After the test from period 2020.01.01 to 2020.01.31, technically Jan 2020, no trade was actually taken. As you can see, the data quality there is poor, 15% is very unreliable. The red sections show completely 0 data and when you hover over them, you can see the blank period. Now let's test on 2025 Jan data and see.

100 DATA

From the image, you can see that on 100% history quality, we have some trades, 19 of them in a month.

So from your issue, maybe you need to check the quality of your testing data since we have proved the default settings work fine on the EURUSD symbol. Hope this clarifies things and is helpful. Thanks. Happy trading.

 
Kyle Young Sangster #:

I downloaded and ran this code as-is through the Strategy Tester. It finds the range each day, and draws the box on the chart. However, it doesn't take a trade each day, (assuming that it should). Over the course of 1.5 months, it took only 3 trades.



The second issue is the high / low levels and the buy / sell levels in the control panel do not update.


The  high /low range levels are clearly being found on the chart, so I'm guessing the buy / sell levels should also be displayed on the chart and updated in the control panel, as they are derived directly from the high / low range levels.

What suggestions do you have to get this working correctly?

Thanks in advance.

As for your second issue, the article explains that, but assuming that your issue emanates from poor testing data and giving a hint, when the range is in calculation, you will always see "Calculating..." status until there is enough data to set the London range session or whichever session you define in the inputs. Assuming you are using the default settings, with prelondon hours being 3, and your time from the shared screenshot is 13, Feb, 2 bars after 22:00 which is 2*15 minutes = 30, hence giving 22:30, is outside the range calculation time, so the data on the panel should be  visible still since the previous set range is still in play unless the first session has not yet been found, and will be cleared as the range calculation is reached from midnight. See below:

const int PreLondonStartHour = 3; //--- Fixed Pre-London Start Hour
const int PreLondonStartMinute = 0; //--- Fixed Pre-London Start Minute

You might need to see the logic below for finding the range

//+------------------------------------------------------------------+
//| Check trading conditions and place orders                        |
//+------------------------------------------------------------------+
void CheckTradingConditions(datetime currentTime) {
   MqlDateTime timeStruct;            //--- Time structure
   TimeToStruct(currentTime, timeStruct); //--- Convert time
   datetime today = StringToTime(StringFormat("%04d.%02d.%02d", timeStruct.year, timeStruct.mon, timeStruct.day)); //--- Get today

   datetime preLondonStart = today + PreLondonStartHour * 3600 + PreLondonStartMinute * 60; //--- Pre-London start
   datetime londonStart = today + LondonStartHour * 3600 + LondonStartMinute * 60; //--- London start
   datetime londonEnd = today + LondonEndHour * 3600 + LondonEndMinute * 60; //--- London end
   analysisTime = londonStart;        //--- Set analysis time

   if (currentTime < analysisTime) return; //--- Exit if before analysis

   double preLondonRange = GetRange(preLondonStart, currentTime, PreLondonHigh, PreLondonLow, PreLondonHighTime, PreLondonLowTime); //--- Get range
   if (preLondonRange < MinRangePoints || preLondonRange > MaxRangePoints) { //--- Check range limits
      noTradeToday = true;            //--- Set no trade
      sessionChecksDone = true;       //--- Set checks done
      DrawSessionRanges(preLondonStart, londonEnd); //--- Draw ranges
      return;                         //--- Exit
   }

   LondonRangePoints = preLondonRange; //--- Set range points
   PlacePendingOrders(PreLondonHigh, PreLondonLow, today); //--- Place orders
   noTradeToday = true;               //--- Set no trade
   sessionChecksDone = true;          //--- Set checks done
   DrawSessionRanges(preLondonStart, londonEnd); //--- Draw ranges
}

And how it is set.

//+------------------------------------------------------------------+
//| Update panel with current data                                   |
//+------------------------------------------------------------------+
void UpdatePanel() {
   string rangeText = "Range (points): " + (LondonRangePoints > 0 ? DoubleToString(LondonRangePoints, 0) : "Calculating..."); //--- Format range text
   ObjectSetString(0, panelPrefix + "RangePoints", OBJPROP_TEXT, rangeText); //--- Update range text

   //---

}

See the image below, though we don't know the year of your testing, we will take the 2025, if it is 2020 as in your case, we don't have quality data for that so either way, we use 2025 and thus range calculation should start at midnight.

23:55

From the image, you can see the data at 23:55 is stil intact. However, when it is midnight, we shpuld reset. See below.

MIDNIGHT DATA 00:00

You can see that we reset the data at midnight for the other range calculation. Actaully, when the range calculation is done, the visualization can help you know what really went on. For example, in your case using the default settings, we will see the raneg bars from 0300 hrs to 0800 hrs because that is what we defined. See below:

RANGE HOURS

Hope this clarifies things again. You can adjust everything as per your trading style. To avoid the issues you are facing, it is advisable to use reliable testing data. Thanks.