EA Protection Filter
EA Protection Filter provides a news filter as well as a stock market crash filter, which can be used in combination with other EAs. Therefore, it serves as an additional protective layer for other EAs that do provide such filters.
During backtest analysis of my own night scalpers, which already use a stock market crash filter, I noticed that the historic drawdown, especially during stock market crash phases like 2007-2008, was reduced significantly by using such a filter.
This type filter usually only makes sense in combination with scalpers that want to avoid fast markets, so don't use it on impulse/price action strategies!
Also, there is no guarantee that using this filter will be more profitable compared to the normal trading.
How it works:
In MT4 an EA is not allowed to modify other EAs for safety reasons. However, it is possible to close and re-open charts, which can be used to turn on/off other EAs.
The EA will also be able to close existing open positions or pending orders based on the given magic numbers or comments you provide as input.
- Please test the filter on DEMO account first!
- Open an M1 chart for the stock market symbol (for example US500) before starting the filter to force MT4 to load the historic data.
- First arrange all charts and EAs that you want to use in combination with this protection filter. Then save the profile in case something goes wrong: File -> Profile -> Save As...
- Please allow requests to http://fxdata.cc and http://backup.fxdata.cc.
- Attach this EA to a new chart of any symbol after (!) all other EAs are loaded.
- Before you close the MT4 or remove the EA press the button on the chart "Turn filter OFF (opens all charts)" to re-open all charts. Else it will not remember closed charts.
- It cannot be guaranteed that the other EAs are compatible with this filter. Make sure that the EAs are ok with being removed and initialized possibly multiple times a day ( best ask the developer).
- Charts can only be filtered by symbol/timeframe, but open trades only by magic/comment. So you have to find a combination that makes sense for your EAs.
- includeTimeFrames - a comma separated list of time frames that should be monitored. For example, if you have non-scalpers on H1 that should not be closed, delete H1 from this list.
- excludeSymbols -a comma separated list of symbols that should be excluded (if you have other EAs that should not use this filter)
- magicNumbersToCloseOpenPositions - a comma separated list of magic numbers, for which positions should be closed
- commentsToClosePositionsExact - a comma separated list of comments, for which positions should be closed (exact match)
- commentsToClosePositionsIncluding - same as the last parameter, but here the comment only has to be included, not an exact match
- sleepSecondsBetweenChartOpen - to avoid terminal overload
- filePrefix - name for the saved template files
- debugMode - more information in Expert log
- signalSymbol - symbol for the SP500 on your broker
- maxPercentageChange - the maximum allowed percentage change for the stock filter to trigger
- minimumKeepClosedMinutesStockFilter - minimum time to keep the chart closed after stock market filter triggered
- filterCentralBankEvents - to filter central bank events
- filterSpeechesAndTestimonies - to filter speeches
- filterHighImpact - to filter other high impact events
- closeMinutesBeforeEvents - minutes before events when charts and positions will be closed
- pauseMinutesAfter... - minutes after events for which the charts will be kept closed
- minimumKeepClosedMinutesNews - minimum time to keep the chart closed after news filter triggered
- useBreakingNewsFilterSignals - If you have the breaking news filter, its signals can be used. It works only within start/end hour of the normal news filter!
- startHourGMTwinter - start hour for the stock market filter. In summer all times will be automatically shifted 1 hour.
- endHourGMTwinter - end hour for the stock market filter
- startHourGMTwinterNews - start hour for the news filter
- endHourGMTwinterNews - end hour for the news filter
If the stock crash filter triggers after this hour on a Friday, the crash end time will be increased by 48. This way the charts should stay closed until Monday morning (depending on your minimumKeepClosedHoursStockFilter setting).
If you don't want this logic to be used, just set a high value of 24 or higher.
If you use the news data from my server (useCustomEventsFile=false), this parameter has no effect.
Also, if an error occurs during chart opening, it will try to get back the initial setup by closing all charts with the same symbol and time frame and re-opening them again.
combinedNewsCurrences2 does the same and was added so that you can use two different groups.
combinedBreakingNewsCurrences1/2 does the same, but only with regards to breaking news if you also use the Breaking News Filter on the account.
- Changed the stock filter parameters so that it is possible to define different values for up/down movement as well as for two different lookback duration (lookbackHours/lookbackHoursShort).
The new parameters are percentageDown, percentageUp, percentageUpShort and percentageDownShort.
- Added parameters close/openChartsHourGMTwinter. If they are set, the filter should close all charts during a given time period each day.
- Added parameter sendPushNotifications. If true, it will send push notifications when the stock market filter triggers (if push notifications are set up correctly on the MT4 terminal). It will send max once every 5 hours.
- Removed the paramter liveGMToffset, which did not have any function anymore after changing to the new GMT offset solution.
- The EA now uses the auto GMT solution similar to my EAs which should be more exact with regards to filtering the news during the week. However, it partly still uses MT4 TimeGMT() function so that it can modify charts during the weekend. TimeGMT() relies on the correct Windows time, so it should still be set correctly. If not the EA will give an Alert during initialization.
- Added parameter checkPositionsEvenWithoutCharts. If true, the filter will check open position for news even if there is no chart closed at the time. Will use more CPU since it checks every tick.
- For Japanese holidays on Monday open you can now define a list of currencies that should be filtered. Default is filterMondayOpenJapaneseHolidays="JPY,CHF".
- Added an option dontCloseSymbolsWithOpenOrders. If it is set to true, then charts will only be closed if there is no open position for the same symbol.
- It is now possible to load events from a custom file. This way you can use the EA without being dependent on the news server. New parameters:
useCustomEventsFile - whether to use the custom file. Then ONLY the events in the file will be used and no other data from the server. Every event in the file will be used without additional filters.
customEventFile - The name of the file you want the EA to read. It should be placed in the common file directory (...\MetaQuotes\Terminal\Common\Files) and should have exactly the following format "date time, currency, name", so for example like this:
2018.05.02 18:00, USD, Rate Decision
- Added the possibility to define a custom pause interval for currencies (pauseCurrencies, pauseBeginMonth, pauseBeginDay, pauseEndMonth, pauseEndDay).
- The filter can now use signals from the breaking news filter with parameter useBreakingNewsFilterSignals (if the breaking news filter is puchased separately).
- filterMediumImpact: If true the EA will also filter medium impact events.
- closeMinutesBeforeBankEvents, closeMinutesBeforeSpeeches and closeMinutesBeforeOtherEvents can now be used to set different time intervals when the positions should be closed before coming news.
Also changed trading pause so that it will only close after the same hour as the Friday close on the day given by stopTradingMonth and stopTradingDay.
The open Profit/Loss and the number of monitored positions will be shown on the chart as visual feedback.
- Added stopTradingMonth ,stopTradingDay, startTradingMonth and startTradingDay so that users can define a trading pause where all monitored charts and positions will be closed.
If true it will always use the Friday close time (+ 48 hours + minimumKeepClosedHoursStockFilter hours) as time to open charts again (Monday morning).
If false it will open charts again on Saturday and don't check stock filter until after Monday morning. So it will always allow Sunday night's trading even if there is a gap in stock markets.
The problem is if there is an error after trying to close a chart multiple times, then it might be that the chart and other EA is still active. Therefore, we don't want to get into a situation where the other EA opens positions and the filter directly closes them again multiple times. If you have onlyTryPositionCloseOnceAfterChartCloseError=true it will only try to close the position once in case there was an error (only for the symbols that had an error).
However, if the symbol has already closed charts and the position close is not successful the first time, it could then lead to unmonitored positions. But the probability should be small.
But if it only check for opening and you also want the positions to be closed, you should include the magic in the filter input and also have at least one chart with the given symbol open.
- The filter will now also close charts during the weekend to prevent trading on market open in case there was a news release before.
waitMinutesBetweenClosePositionAttempts - When news or stock filter triggers the EA will close all positions depending on the given settings. It will then wait at least waitMinutesBetweenClosePositionAttempts minutes until again checking to close positions.
- Added parameters FridayCloseHourGMTwinter and FridayCloseMinute. The EA will close all charts at the given time and close open position to avoid holding positions over the weekend. However, some EAs are specifically designed to trade during the weekend. Set FridayCloseHourGMTwinter=-1 if you want to disable this function.
They allow to set different windows for the news filter:
Between startHourGMTwinterNews and endHourGMTwinterNews the news filter will be active and close positions (but not charts).
Between startHourGMTwinterNewsCharts and endHourGMTwinterNewsCharts the news filter will also close charts (only if also within the normal news filter time window).
Also added a parameter delaySecondsOnInitialization. It will cause the EA to wait a few seconds on normal initialization. For example, after you restart MT4 it makes sure that the EA will read the charts after all EAs on other charts have been initialized. After pressing F7 to change settings it will not cause a delay.
It will also now show the reference time to which the percentage change of SP500 will be calculated. Be aware that on first initialization it will load X bars, so it might be that the reference time has not the same minute compared to the current time.
- There ois now a parameter onlyCheckStockPriceEveryMinute in case the user also only wants to check stock prices every minute.
- The charts list will now use multiple rows if more than 8 charts are monitored.
MT4 ignores the sleep() function when removing an EA, which means that if you have many closed charts, it will try to open all at once without time in between. This can cause CPU overload and errors in opening the charts.
So if you have many closed charts, first press F7, set openAllChartsAndTurnOffFilter=true and wait until all charts are open. Then the filter will be turned off and you can remove it from the chart.