Description:
- The Fundamental Trader EA is designed to automate trading decisions based on news events. Unlike typical trading systems, this EA cannot be back-tested using historical data. Instead, it operates in real-time, waiting for the next news event to make informed trading decisions based on the actual versus forecasted data or actual versus previous data.
- After downloading the economic calendar, the EA identifies the next scheduled news event from the DailyFX calendar. Once the news is released, it triggers a trading decision. This EA can be applied to any chart and time frame since it utilizes the chart solely for order execution. It supports all countries listed on the DailyFX calendar, as detailed below.
NOTE:
- To get this EA up and running, you must follow the setup instructions for the main files from the following site:
- https://www.mql5.com/en/articles/1502
- This EA is built on the code from an indicator specified in the link above. You MUST first follow the instructions in the link and set up the following files:
- getright_setup.zip
- Time.mq4
- Time.mqh
- Ensure you change the default "get right" download directory to where the calendar will be downloaded; otherwise, this EA won't function properly.
- Take your time to read that article carefully and follow every instruction. It provides a thorough explanation of what those files do and how they contribute to displaying news events in your chart window.
- It's a good idea to set up that indicator first and display the news on your chart; this way, the EA will work without any issues.
- The indicator source code has been modified to create an EA that trades the news instead of just displaying it.
- Once you've set up the files from the link provided, you can download this EA along with "str2double.dll". This file should be placed in the root directory, e.g. C:\Program Files\Interbank FX Trader 4\
Trading Logic:
- The trading logic operates on two types of events when trading news:
- 1st: Actual economic data compared to forecasted economic data.
- 2nd: Actual economic data compared to previous economic data.
- The difference in economic data can influence currency price direction. A larger percentage difference between economic data increases the likelihood of a market reaction in a specific direction.
- For more information on Fundamental Trading, visit www.pfxglobal.com.
- When there's a significant percentage difference between economic data, the EA executes trades with larger lot sizes.
- When the percentage difference is minimal, the EA trades with smaller lot sizes.
- These lot sizes are defined when applying the EA to the chart with variables: lot1, lot2, lot3, lot4, lot5, lot6... up to lot18.
- The EA will select the appropriate lot size based on the percentage difference between economic data.
Risk/Reward Ratio:
- The Fundamental Trader EA is configured with a 1:3 risk/reward ratio, where the default values are risk=20 and reward=3.
- Risk represents the PIP StopLoss values, and reward is a multiplier—when risking 20 PIPs, the EA aims for a 60 PIP gain.
- These values can be adjusted when applying the EA to the chart.
Wait Time for News Event Release:
- News data is not always released at the exact scheduled time; therefore, you need to set a wait time for the EA to monitor the news events.
- The following code snippet determines the wait time for the news release. Once the wait time has lapsed, the EA moves on to the next scheduled news event.
- xTime is a variable that can be modified upon first applying the EA to a chart, with a default setting of 27 minutes.
if(Date>(TimeCurrent()-(xTime*60)))
Wait Time for Order Closure:
- You can also configure a wait time for the EA to hold an open order before closing it.
- For instance, after a news event is released, and a position is executed, you might wait 30 minutes to close the order, whether it results in profit or loss. This method is recommended by MQL4 user "ebenv".
- There are three variables that control this functionality:
- MagicNumber | A number used to track opened orders.
- enable_close_time | Set to true to enable the EA to monitor the time elapsed since the order was executed.
- wait_time | Time to wait before closing the order.
Supported Countries for Fundamental Trader:
- The Fundamental Trader EA trades every currency supported on dailyfx.com/calendar.
- Below is a code snippet that specifies which currencies to trade based on the country where the news event is released. Supported currencies include: EUR, USD, JPY, GBP, CHF, AUD, CAD, NZD.
if(stCurrency=="EUR") { ordercurrency="EURUSD"; } // trading eurusd
if(stCurrency=="USD") { ordercurrency="EURUSD"; } // trading eurusd
if(stCurrency=="JPY") { ordercurrency="USDJPY"; } // trading usdjpy
if(stCurrency=="GBP") { ordercurrency="GBPUSD"; } // trading usdgbp
if(stCurrency=="CHF") { ordercurrency="USDCHF"; } // trading usdchf
if(stCurrency=="AUD") { ordercurrency="AUDUSD"; } // trading audusd
if(stCurrency=="CAD") { ordercurrency="USDCAD"; } // trading usdcad
if(stCurrency=="NZD") { ordercurrency="NZDUSD"; } // trading nzdusd
Trading Decision:
- The following code snippet describes how the EA makes trading decisions while waiting for actual economic data when forecast data is available.
- If forecast data is not available, the EA uses previous data to guide its trades.
- The following code snippet illustrates how trades are executed based on forecast and actual data, utilizing the same algorithm when comparing previous and actual economic data.
if(StringToDouble(stActual)>StringToDouble(stForecast)) { Aert("Stronger(actual vs forecast): " + stCurrency + " " + "Time: " + stTime); int total=OrdersTotal(); for(int cnt=0; cnt
- The EA can only execute one order per news event, so it first checks if an order was executed. If an order is currently open, the EA exits.
- Next, it checks if the order was executed and closed, whether with profit or loss. If the order has been closed, the EA exits.
- These two checks prevent duplicate orders, enabling the EA to make a single trade for each news event.
- Then, it identifies which country the data is being released for and opens a trade based on the specifications in the ordersend function when the economic data is released.
- The code above is for when actual data exceeds forecast data, and the logic is similar when actual data is less than forecast data, with the only difference being the trade direction.
- The same algorithm applies when comparing previous data to actual data when forecast data is unavailable.
Lot Sizing:
- The EA compares (actual data to forecast data) or (actual data to previous data); the percentage difference determines the lot amount the EA will trade.
- The following code snippet shows how the EA calculates the percentage difference and specifies the lot size. The lot size is an external variable that can be modified to suit any broker.
- Users can adjust the lot sizes when applying the EA to the chart. Default lot size values range from (0.01, 0.02, 0.03...0.17).
double percent_d_AF=MathAbs((MathAbs(StringToDouble(stActual)-StringToDouble(stForecast))/StringToDouble(stForecast))*100); double lot_p=0; if((percent_d_AF>0 && percent_d_AF<=3)) { lot_p=lot1; } //0.1 lot if((percent_d_AF>3 && percent_d_AF<=6)) { lot_p=lot2; } //0.2 lots if((percent_d_AF>6 && percent_d_AF<=9)) { lot_p=lot3; } //0.3 lots if((percent_d_AF>9 && percent_d_AF<=12)) { lot_p=lot4; } //0.4 lots if((percent_d_AF>12 && percent_d_AF<=15)) { lot_p=lot5; } //0.5 lots if((percent_d_AF>15 && percent_d_AF<=18)) { lot_p=lot6; } //0.6 lots if((percent_d_AF>18 && percent_d_AF<=21)) { lot_p=lot7; } //0.7 lots if((percent_d_AF>21 && percent_d_AF<=24)) { lot_p=lot8; } //0.8 lots if((percent_d_AF>24 && percent_d_AF<=27)) { lot_p=lot9; } //0.9 lots if((percent_d_AF>27 && percent_d_AF<=30)) { lot_p=lot10; } //1 lot if((percent_d_AF>30 && percent_d_AF<=40)) { lot_p=lot11; } //2 lots if((percent_d_AF>40 && percent_d_AF<=50)) { lot_p=lot12; } //3 lots if((percent_d_AF>50 && percent_d_AF<=60)) { lot_p=lot13; } //4 lots if((percent_d_AF>60 && percent_d_AF<=70)) { lot_p=lot14; } //5 lots if((percent_d_AF>70 && percent_d_AF<=80)) { lot_p=lot15; } //6 lots if((percent_d_AF>80 && percent_d_AF<=90)) { lot_p=lot16; } //7 lots if((percent_d_AF>90 && percent_d_AF<=100)) { lot_p=lot17; } //8 lots if((percent_d_AF>100)) { lot_p=lot18; } //8 lots
Chart Information:

Screen Shot of Fundamental News Data
- When you first apply the EA to the chart, specify "xTime", "risk", "reward", "MagicNumber", "enable_close_time", "wait_time", and set your minimum and maximum lot sizes. Be sure to keep the default installation location for "get right".
- The EA will download the DailyFX calendar and identify the next news event, displaying data such as Date, Time, TimeZone, Currency, Description, Importance, Actual, Forecast, and Previous news event data as comments on the chart, as shown in the image above.
- In the example above, the EA is waiting for a news event expected to release at 2:00 AM. The previous economic data is known (73.5%), so the EA is prepared to act when the actual data is released. Once the economic data is available, the EA will make a trading decision based on the comparison of previous and actual economic data.
- Lastly, the EA continuously downloads calendar data on a minute-by-minute basis from the time the news event is scheduled to release.
Fundamental Trader Overview:
- This EA trades every economic event released on dailyfx.com/calendar in CSV format.
- The calendar is downloaded using the "get right" program.
- The EA downloads the calendar every minute leading up to the news release.
- The EA parses the calendar to determine which news event is next, waiting for 27 minutes for the news to be released.
- Once the economic data is released, it assesses whether to compare (actual vs. forecast) or (actual vs. previous) data.
- The EA determines lot sizes, the currency to trade, and the direction based on the economic calendar event. This information is displayed on the chart while the EA operates.
- The order is executed with a 1:3 risk/reward ratio.
- The EA is programmed to execute only one order per news event. If "enable_close_time" is set to true, the EA will wait for the specified "wait_time" in minutes before closing the open order.
Remember to follow all instructions in the following link https://www.mql5.com/en/articles/1502 to ensure the calendar downloads correctly, and your broker time is set up accurately for processing dailyfx.com/calendar data, which is in GMT.
If you have any questions, comments, or feedback, feel free to leave a comment!
Related Posts
- Harnessing MQL5 Wizard for Trading Signals: 3 Black Crows & 3 White Soldiers with MFI
- Mastering the Moving Average EA for MetaTrader 5: A Trader's Guide
- Creating a Stochastic-Based EA for Hammer and Hanging Man Patterns in MetaTrader 5
- Creating an Expert Advisor for Dark Cloud Cover and Piercing Line Patterns with CCI Confirmation
- Leveraging MQL5 Wizard: Crafting Trade Signals with Meeting Lines and Stochastic