GerFX EA Protection Filter

8 July 2020, 10:58
Exler Consulting GmbH
0
512

This blog post should help to understand the settings of the EA Protection Filter (EAPF). 

The EAPF has many paramters, which can be confusing at the start. But in most cases you probably only need a fraction of the parameters and can ignore the rest. 

The filter can be configured to close charts/positions on the following trigger events:

  • Calendar news (like CPI or GDP releases)
  • stock market movement (if your broker has a stock market symbol)
  • Floating profit/loss (for example to exit of positions in case of a flash crash)
  • A user defined period (like closing over Christmas/New Year period) or closing on Fridays to prevent positions over the weekend. 
  • Breaking news if you use the Breaking News Filter on a separate chart. 

The typical use case would be to use it with a night scalper that does not have an own news filter or stock market crash filter. It could also make sense with certain grid strategies. However, there is no way to tell whether closing charts and positions will actually be more profitable. Some EAs might also not be suited to being stopped/started too often. 

Important to understand: EAs do not know which magic number refers to which chart. Therefore, they can only select charts by symbol and time frame. However, positions can only be selected by symbol and magic number. Therefore, the most important parameters are includeTimeFrames/excludeSymbols to filter charts and magicNumbersToCloseOpenPositions to filter positions. 

WARNING: 

  • Positions with given magic/comment will be closed even if there is no chart monitored with the same symbol. 
  • If the other EA is not monitored by chart it could lead to interactions like positions closing and opening again!


Parameter 
Description 
includeTimeFrames 
The time frames of other charts that should be monitored (comma separated list).  
excludeSymbols 
Symbols of other charts that should not be monitored  (comma separated list)  
closeFridayCurrencies 
Currencies for which the Friday close logic should be applied (if fridayCloseHour is set). 
magicNumbersToCloseOpenPositions 
Magic numbers of positions that should be monitored and closed on filter signal (comma separated list).  
commentsToClosePositionsExact 
Comments of positions that should be monitored as alternative to giving the magic number (comma separated list). Here the comment must be exactly the same as in the position. 
commentsToClosePositionsIncluding 
Similar to commentsToClosePositionsExact, but here the EAPF will only check if the given comment is included in the position comment (not an exact match).  
waitMinutesBetweenClosePositionAttempts
Minimum minutes to wait after an attempt to close positions and orders. It is meant as an protection in case the settings are not correct. For example, if you set the EAPF to close a position, but not the chart, then it could lead to multiple closing and opening of positions. With this parameter it will at least wait a given time before closing again. This is not symbol specific, but for all together. 
closePositionsBeforeCharts
If set to "On max profit/loss", the EAPF will first close positions and then charts in case the maximum profit/loss case is triggered. This might be the case in flash crashes and therefore this setting could lead to faster closing. However, it could also lead to interactions with still active charts/EAs, which might again open positions until the chart is closed as well. If set to "Always", it will always try to first close the positions. 
Also keep in mind that waitMinutesBetweenClosePositionAttempts will be checked, so that if there are unmonitored open positions, they won't be allowed to be closed for the given period.
chartCloseCondition
This can be used not not allow chart closing when there is a filled or pending order with the same symbol.
closeConditionCheckMagicAndComments
If true, only orders with the given magic numbers and comments will be included for the chart close condition (defined by magicNumbersToCloseOpenPositions, commentsToClosePositionsExact, commentsToClosePositionsIncluding).
checkPositionsEvenWithoutCharts  If true, it would also check for position closing even if there are no charts monitored. This could lead to interactions with active EAs if they are not monitored as well. 
maxOpenLoss Maximum open loss in account currency to trigger closing of monitored positions and charts (similar to triggering of the stock market crash filter). 
maxOpenProfit  Maximum open profit in account currency to trigger closing of monitored positions and charts (similar to triggering of the stock market crash filter). 
maxSlippagePoints Slippage parameter used in the OrderClose() function. To my knowledge this value is not checked by any brokers and therefore does not have an influence (maybe on some brokers it does). 
equityHardStop Equity level in account currency at which the EA would close all monitored positions and charts (similar to triggering of the stock market crash filter). 
dailyEquityStopPercentage  Equity level in percentage relative to the equity at dailyEquityHourGMT at which the EA would close all monitored positions and charts (similar to triggering of the stock market crash filter). For example, with a value of 90 would mean that the EAPF would close positions when the equity is lower than 90% of the equity at 17 GMT. If you use this option, withdrawals and deposits should be made before dailyEquityHourGMT, else it could lead to wrong triggers. 
dailyEquityHourGMT Hour at which the equity level will be set. The default is 17 GMT, which usually makes sense for night scalping strategies. 
sleepSecondsBetweenChartOpen Seconds between opening of charts. This should reduce the maximum CPU demand and hopefully lead to less errors during chart opening. 
sleepSecondsBetweenChartClose  Seconds between closing of charts. This should reduce the maximum CPU demand and hopefully lead to less errors during chart closing
filePrefix File prefix used to save the tempates. 
onlyTryPositionCloseOnceAfterChartCloseError  If true, the EAPF will only try to close positions once after an error in closing charts. This might lead to unmonitored positions from closed charts. If false, it might lead to positions being opened again by other EAs on not closed charts (and closed again by the filter).
setGlobalVariablesForAllMarketWatchSymbols If true, the EAPF will set global variables for all symbols in the market watch to indicate whether there was a trigger signal. This only works if the other EAs are able use global variables. Please see the section "For developers" at the end of this blog post. 
debugMode  If true, the EAPF will write more data in the log file, which can be used to check for trigger reasons or to find bugs. 
signalSymbol Symbol used for the stock market crash filter. Usually it is called like US500, SPX500, US500cash, or similar. 
sendPushNotifications  If true, the EAPF will send push notifications. This only works if push notitications are set up in the MT4 settings
lookbackHours Hours to look back for the stock market crash filter. 
percentageDown Percentage value when to trigger on a downward movement of the signalSymbol.
percentageUp Percentage value when to trigger on an upward movement of the signalSymbol.
lookbackHoursShort Similar to lookbackHours, but for another period. This way we can filter both 8h and 2h movements for example. 
percentageDownShort  Percentage value when to trigger on a downward movement of the signalSymbol for the lookbackHoursShort period.
percentageUpShort  Percentage value when to trigger on an upward movement of the signalSymbol for the lookbackHoursShort period.
minimumKeepClosedHoursStockFilter Minimum hours to keep the charts and positions closed after the stock market crash filter triggered. This also applies to other trigger signals, which use the same functionality (max open loss/profit and equity stop levels for example). 
onlyCheckStockPriceEveryMinute If true, the EAPF will only check stock prices every minute (to save CPU ressources, but not really needed in most cases). 
useStockFilterSundayNightAndDec25Jan1 Whether to use the stock market crash filter on Sunday night, December 25 and January 1. If true, it could lead to triggers that were caused by the movement during the last day where the market was open (e.g. Friday).  
fridayHourGMTadd48HoursToCrashEndTime Hour on Friday after which the stock market crash filter will add 48 to the crash filter end time. This should prevent opening over the weekend if the filter triggered after the given hour on Friday. 
waitForCrashTriggerGoneOutsideHours If true and the crash filter triggered during the active hours, it will wait until the stock market filter does not trigger anymore, even if that time is outside of the active hours defined in the settings. 
extendCrashEndTimeOnEveryNewTrigger If true, it will extend the crash trigger end time by minimumKeepClosedHoursStockFilter each time the trigger occurs again. 
resetStockTriggerSaturday If true, it will reset the stock trigger variable on Saturday (GMT time), regardless of other settings.
useNewsFilter Whether to use the news filter. 
filterCentralBankEvents Whether to filter central bank events like Interest Rate Decisions, or Press Conferences. 
filterSpeechesAndTestimonies Whether to filter speeches and testimonies. 
filterOtherHighImpact Whether to filter other high impact news  (excluding bank events and speeches). 
filterOtherMediumImpact Whether to filter other medium impact news (excluding bank events and speeches). 
useCustomEventsFile Whether to read news from a custom file. If this option is used, there should a be a file with news to be filtered in the common file directly. The exact path depends on your Windows user name, but it should end with \Terminal\Common\Files. The news data should have exactly the following format "date time, currency, name", so for example like this:

2020.05.02 18:00, USD, Rate Decision
2020.05.03 15:00, USD, Other event
etc. 

The EAF will categorize all news from the file as high impact. Please double check the Expert log if the events have been read correctly. 
customEventFile  The name of the customer event file. 
updateMinutesFile The interval (in minutes) to read the customer event file in case it changed. 
filterMondayOpenJapaneseHolidays Currencies to filter on Japanese Hildays (only Mondays). These days have especially low liquidity and might be more risky with regards to flash crashes. 
closeMinutesBeforeBankEvents Minutes to trigger the closing signal before bank events. 
closeMinutesBeforeSpeeches Minutes to trigger the closing signal before speeches. 
closeMinutesBeforeOtherEvents Minutes to trigger the closing signal before other events. 
pauseMinutesAfterBankEvents Minutes to pause after bank events. 
pauseMinutesAfterSpeeches Minutes to pause after speeches. 
pauseMinutesAfterOtherEvents Minutes to pause after other events. 
minimumKeepClosedMinutesNews Minimum time to keep the charts closed after a news trigger. This should not be needed, but it is meant as an additional protection in case there is an error with the news data. 
USDrateDecisionCloseCurrencies This can be used to define currencies for which charts should be closed during USD rate decisions. A similar parameter also exists for EUR and JPY.
USDrateDecisionCloseMinutesBefore This defines how long before USD rate decisions charts should be closed. A similar parameter also exists for EUR and JPY.
USDrateDecisionPauseMinutesAfter This defines how long after USD rate decisions charts should stay closed. A similar parameter also exists for EUR and JPY.
combinedNewsCurrences1 A comma separated list of currencies. These currencies would all trigger if there was a trigger event for one of them. If combinedNewsCurrences1="USD,JPY,CHF" the filter would filter USD, JPY andCHF on news for any of them.

combinedBreakingNewsCurrences1/2 does the same, but only with regards to breaking news if you also use the Breaking News Filter on the account.
combinedNewsCurrences2  It does the same as combinedNewsCurrences1 and was added so that you can use two different groups.
combinedBreakingNewsCurrences1 Similar to combinedNewsCurrences1, but it only refers to triggers from the breaking news filter. 
combinedBreakingNewsCurrences2 It does the same as combinedBreakingNewsCurrences1 and was added so that you can use two different groups.
useBreakingNewsFilterSignals If true, the EAPF will filter currencies when the Breaking News Filter triggers. This only works if you have the Breaking News Filter active on another chart. 
startHourGMTwinter  Start hour for the stock market crash filter. "GMTwinter" parameters always refer to GMT time in winter. During US summer time, the start/end hours will be shifted automatically by one hour, so there is no need to change the settings after Dailight Saving Times changed. If start and end hour are the same, it will use all hours.
endHourGMTwinter End hour for the stock market crash filter.
startHourGMTwinterNews Start hour for the news filter. If start and end hour are the same, it will use all hours.
endHourGMTwinterNews  End hour for the news filter.
startHourGMTwinterNewsCharts Start hour for the news filter with regards to chart closing. For example, you could set the EA to close positions from 0-24, but only close charts from 8-20 if that makes sense for your strategy. It only works within the start/end hour for the news filter. If start and end hour are the same, it will use all hours.
endHourGMTwinterNewsCharts 
End hour for the news filter with regards to chart closing. 
startHourGMTwinterIgnoreNews Start hour for a period where news triggers should be ignored. A value of -1 means that this option is not used. 
endHourGMTwinterIgnoreNews  End hour for a period where news triggers should be ignored. A value of -1 means that this option is not used.   
FridayCloseHourGMTwinter Hour at which charts should be closed on Friday (to prevent opening positions that would be held over the weekend). A value of -1 means that this option is not used. Only charts with currencies included in closeFridayCurrencies will be closed. 
FridayCloseMinute The minute at which charts should be closed on Friday. 
handle24and31DecemberLikeFriday If true, the EAPF will treat 24 and 31 December like Fridays and close the charts (if the Friday settings are active). 
delaySecondsOnInitialization Seconds to delay reading the charts after initialization. This is meant to reduce the error rate on VPS. 
closeChartsHourGMTwinter / openChartsHourGMTwinter  These parameters can be used to close charts every day between these hours (if one is below 0, it is disabled).
stopTradingMonth /  stopTradingDay /  startTradingMonth / startTradingDay 
These parameters can be used to close all charts for a given period (for example around New Year).
pauseCurrencies  Additionally, a custom pause can be defined for specific currencies (comma separated list).
pauseBeginMonth / pauseBeginDay pauseEndMonth / pauseEndDay  To define start and end days for the custom pause. 
checkDuringWeekends If false, it would not run checks during the weekend (for example for chart opening after Friday close).
closeWednesdayCurrencies This can be used to close charts for given currencies before Wednesday triple swap.
closeWednesdayStartHourGMTwinter This is the hour charts would be closed (in GMT winter time, in summer it will be shifted automatically like the other GMT winter hours).
closeWednesdayEndHourGMTwinter This is the hour on Thursday when charts would be opened again.
maxPositionsStartHourGMTwinter This can be used to specify the start hour for the time window during which the EAPF should monitor the maximum allowed positions (and close charts if max position reached).
maxPositionsEndHourGMTwinter This can be used to specify the end hour for the time window during which the EAPF should monitor the maximum allowed positions.
currencySymbolsToMonitor This can be used to set which currency symbols should be monitored for max position settings.
magicNumbersToMonitor This is a list of magic numbers that should be monitored for max position settings.
commentsToMonitorIncluding This can be used to define a list of comments for positions that should be used in the max position settings (does not have to be exact, including is enough).
maxNetPositionsPerSymbol This determines when the max position settings should trigger for a symbol. The number is given as the maximum number of net(!) positions. Zero or smaller will be ignored. It will close the monitored charts for the given symbol. Depending on your maxPositionsChartCloseCondition and comments/magicNumbersToCloseOpenPositions settings, it might also close the positions. Please test it on a demo account! 
maxNetPositionsPerCurrency This determines when the max position setting should trigger for a currency. Zero or smaller will be ignored. Depending on your maxPositionsChartCloseCondition and comments/magicNumbersToCloseOpenPositions settings, it might also close the positions. Please test it on a demo account! 
maxPositionsMinimumKeepClosedMinutes This determines the minimum duration of the signal when the max position case triggers.
maxPositionsChartCloseCondition This can be used not not allow chart closing when there is a filled or pending order with the same symbol (only for the max position logic). IMPORTANT: closeConditionCheckMagicAndComments will also effect this parameter.
partialCloseStartHourBrokerTime This can be used to specify the start hour for the time window during which the EAPF should check the partial close logic. If start and end hour are the same, it will use all hours.
partialCloseEndHour BrokerTime This can be used to specify the end hour for the time window during which the EAPF should check the partial close logic.
partialCloseMondayStartHour BrokerTime This parameter will overwrite the normal start hour for partial close function on Mondays. If set to a negative value, it will not be used. If start and end hour are the same (and not negative), it will use all hours.
partialCloseMondayEndHour BrokerTime This parameter will overwrite the normal end hour for partial close function on Mondays. If set to a negative value, it will not be used. If start and end hour are the same (and not negative), it will use all hours.
netPositionsPerSymbolForPartialClose This can be used to close positions partially if a certain number of net positions per symbol was reached. If equal or smaller zero, it will not be used. If you use comments for filtering, please be aware that the order comment might be changed by MT4 after partial closing!
partialCloseMaxSpreadPoints This can be used as an additional maximum spread condition for the partial close logic. If negative, it will be ignored.
partialCloseFactor This is the factor by which positions would be closed. For example, a value of 0.2 would close 20% of the position.
waitMinutesBetweenMaxPositionClose This determines the wait time after partial close until another one could trigger.
lotDigits Digits for rounding lot size during partial close.



For developers:


The EAPF also has the possibility to interact with other EAs via global variables instead of closing/opening the charts if setGlobalVariablesForAllMarketWatchSymbols=true.

However, the other EAs have to be programmed to use the global variable provided by EA Protection Filter!

So if you are a progarmmer you can add the following code, or if you are a customer you can ask the developer of your EA to add this code. It is really simple. Before sending an order just add the check if the filter is OK:

if (tradingAllowedFilter()) OrderSend(...);

And add the function tradingAllowedFilter() anywhere in the code:

datetime lastPrintTime;

bool tradingAllowedFilter() {

   if (IsTesting()) return true;

   string variableName = "EAProtectionFilter" + Symbol();

   if (GlobalVariableCheck(variableName)) {

      if (GlobalVariableGet(variableName) == 1.) {

         if (TimeCurrent() > lastPrintTime + 300) {

            lastPrintTime = TimeCurrent();

            Print("Trading not allowed because of EAProtectionFilter for "+Symbol()+".");

         }

         return false;

      }

   } else if (TimeCurrent() > lastPrintTime + 300) {

      lastPrintTime = TimeCurrent();

      Print("Global variable "+variableName+" not found. EAProtectionFilter not active?");

   }

   return true;

}




Share it with friends: