In this post, let's take a look at the terminal status functions found in the MQL4 programming language described here Terminal Functions.
These functions don't have much to do with trading, but they let you know the status of the Terminal which is important for a few reasons.
While it seems like we are pretty far from making any money here, we are deepening our understanding of the terminal and how it works on the inside which will benefit us later.
Anyway, open up MetaTrader and create a new Expert Advisor called Terminal. Paste the following code into the Init() function:
int init()
{
Print("Terminal Info follows");
Print("Company: ", TerminalCompany());
Print("Name: ", TerminalName());
Print("Path: ", TerminalPath());
/* Terminal info */
Print("Terminal Status follows");
if (IsDemo()) {
Print("Status: Demo Account");
} else {
Print("Status: Live Account"); }
/* Terminal info */
if (IsConnected()) {
Print("Connection Status: Connected");
} else {
Print("Connection Status: Not Connected");
}
Print("Details of Terminal Config follow");
Print("IsDllsAllowed: ", IsDllsAllowed());
Print("IsExpertEnabled: ", IsExpertEnabled());
Print("IsLibrariesAllowed:", IsLibrariesAllowed());
Print("Testing Status follows");
Print("IsOptimization: ", IsOptimization());
Print("IsStopped: ", IsStopped());
Print("IsTesting: ", IsTesting());
Print("IsTradeAllowed: ", IsTradeAllowed());
Print("IsTradeContextBusy:", IsTradeContextBusy());
Print("IsVisualMode: ", IsVisualMode());
return(0);
Now compile the EA and correct any syntax errors.
Now exit the MetaEditor and drag the new EA onto a chart. The print output will appear under the Experts tab. You can also play around with the 'Allow Live Trading' and 'Allow DLL Imports' check boxes and see their affect on the output.
Now remove the EA from the live chart and open up the Strategy Tester window. Now run a test with your new expert over a short time period. The print output will appear under the Journal tab when testing.
Key take aways here are:
- An expert can be active on a chart without live trading being enabled
- An expert can tell whether its being run in demo mode or against a live account. This allows developers of commercial EA's to allow unlimited testing on a demo account, but require some type of user authentication on a live account.
- An expert can be programmed to behave differently when being tested!
2 other tidbits I picked up about the back-tester that are key:
1) The back tester does not test on tick data. The backtester only has 1-minute data and its simulates the ticks arriving at the terminal during a backtest to form the bar. This sometimes causes EA's that have very small take profit values to look great in a backtest, but test lousy in reality.
2) Many an EA is programmed improperly by taking action on price[0] which is the current bar in the making, rather than testing on price[1] which is the most recent completed bar. We all know that bars can change in during formation and a very bullish bar (bullish engulfing) can turn into a indecisive bar (spinning top) based on the value of the close alone. So your EA should always take action on the price action in bar [1] rather than bar [0].
That's all for now, check back later for information on Account functions.
This is an excellent blog, great work on explaining the intricaties of MQL4. I shall add you to my blog roll.
ReplyDeleteSteve
Steve-
ReplyDeleteThanks for the kinds words. I'm working toward posting the complete, working code on some EA's and we should be at that point within a week or 2.
Once we get to that that point, we can starting getting to the nitty-gritty of what actually works and what doesn't. At we can base that conclusion on back testing, forward (demo) testing and testing on a real-live account.
Thanks again for the comment,
Chris
Hey Everybody,
ReplyDeleteI've attached a list of the most recommended forex brokers:
1. Most Recommended Forex Broker
2. eToro - $50 min. deposit.
Here is a list of the best forex instruments:
1. ForexTrendy - Recommended Odds Software.
2. EA Builder - Custom Strategies Autotrading.
3. Fast FX Profit - Secret Forex Strategy.
I hope you find these lists beneficial.