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 the 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 is reduced significantly by using such a filter.
This type of protection 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!
- 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
- maxSlippagePoints - maximum slippage for OrderClose() function
- sleepSecondsBetweenChartOpen - to avoid terminal overload
- filePrefix - name for the saved template files
- debugMode - to write more information into the Expert log
- signalSymbol - symbol for the SP500 on your broker
- maxPercentageChange - the maximum allowed percentage change for the stock filter to trigger
- onlyTriggerOnNegativeMovement - if false the stock market filter will also trigger on strong positive movement.
- lookbackHours - period of the stock market movement
- minimumKeepClosedMinutesStockFilter - minimum time to keep the chart closed after stock market filter triggered
- useNewsFilter - whether to use the news filter
- filterCentralBankEvents - whether to filter central bank events
- filterSpeechesAndTestimonies - whether to filter speeches
- filterHighImpact - whether 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
- 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
- liveGMToffset - in case you want to set the GMT offset manually. If liveGMToffset=99 it will be determined automatically.
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.