Basic Strategy – Adjustment2 – Trading Day

In the following post, it became clear that the Broker spreads increase dramatically during certain periods of the day and that it is not advisable to trade during these periods:

Record Spread, Stop and Freeze Levels

It can also be dangerous to leave trades open during the weekend because an important news event may occur during the weekend, when the markets are closed, which may result in a huge gap event when they open.

An EA has been provided with the following key properties:

  • It closes all trades after a certain hour just before the weekend.
  • It only allows trades to be opened within a certain time range during the day.
  • If a positive value is provided, it can close trades during a certain hour of the day.   For example it could be used to close trades at 22:00 GMT before the broker spreads widen.
  • It can be used to only trade when the spread is below a maximum number of points.
  • A spread widening time range can be provided, where all trades are closed if the distance to the StopLoss is less than a certain number of points.   This has been included to model the widening of spreads at roughly 22:00 GMT.   This is not used if the input is less than or equal to zero.

In addition to this, I have also included 2 extra scripts.   HighlightMissingDays goes through the bars in the chart and helps highlight large gaps between candles that are over 1 day, i.e. a Weekend.   It also helps highlight time periods where opening a new trade is not allowed.   The MakeTradesMoreVisible script goes through the trend-lines on a chart and changes any line that begins with a hash so that the line is solid and thicker.   Personally I find that there are times when I would like to analyse when trades are opened and closed and need thicker more visible lines to help with that.

MQL Code:  BasicStrategy_Adjust2_TradingDay
Class: C_Chart_Drawing
Class: C_TradeManagement
Class: C_OPTIMIZATION_LOG
Script: HighlightMissingDays
Script: MakeTradesMoreVisible

The following charts show typical results that can be obtained from running the Expert Advisor and then highlighting the missing days and making the trades more visible.   The first chart shows a graph where trades are closed at the end of the day.   The second chart shows a graph where trades are not closed at the end of the day.   The tick red and blue lines are the trades.

 

Add a Comment