Monitor Account Balance and Send Email Alerts in Metatrader When Account Drops Below Threshold

I no longer trade using Metatrader. I noticed users kept hitting an invalid link on my website to this search phrase. So the purpose of this post is to catch those invalid links related to Metatrader. I would recommend learning Python and…

I no longer trade using Metatrader. I noticed users kept hitting an invalid link on my website to this search phrase. So the purpose of this post is to catch those invalid links related to Metatrader. I would recommend learning Python and custom developing your algorithms. It will be much more rewarding.

I had a strategy that I programmed awhile ago that completely drained my account. The strategy itself was fine. In fact it was doing so good I decided to apply it from some of my currency pairs to XAU/USD. After applying I caught a flight to LAX to pick up a Porsche I had found online. I had never traded gold before but judging from the backtest it should have performed relatively well. The problem was I did not anticipate the large spread on gold. The spread was enough to send my strategy constantly opening and closing positions. The buy rules and sell rules were being met because of the huge spread. Once I landed I had picked up the Porsche and headed to my hotel, not realizing at the time I had left my briefcase and laptop in the back of the taxi that I caught at LAX. When I arrived at my hotel I checked my phone only to realize one of my accounts was down around 70%, only 30% of my capital remaining. I immediately freaked out and started my investigation. It was then I realized the large spread in gold was constantly opening and closing positions. Costing me the spread every 5 minutes or so. I called Oanda as I then realized I lost my laptop I could not shut off the robot. Closing the trades manually from my phone only made the account drain faster.

Now you see my reason for writing this code. The purpose of it is to grab your account balance at a specific time and then if it drops below a threshold to send an email notification. This code is in mqh format. Which is an include file. The reason for this is so that it can be applied to any expert advisor.


//+------------------------------------------------------------------+
//| DailyBalanceCheck.mq4 |
//| Copyright © 2011, Jeremy R. Whittaker |
//| http://www.JeremyWhittaker.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Jeremy R. Whittaker"
#property link "http://www.JeremyWhittaker.com"

double todaysBalance, dDouble;
int iHandle, iErrorCode;
extern string sFileName=”dailyBalance.csv”;
int iDecimalPlaces=2;
int sendWarningCount, sendBalanceCount;

void dailyBalanceCheck(){
int count;
double onePercent;

if(todaysBalance<1){
fnReadFile();
todaysBalance=dDouble;
}

if(Hour()==16 && Minute()==59){
count=0;
sendWarningCount=0;
sendBalanceCount=0;
}

if(Hour()==1700 && Minute()==0){
if(count==0){
todaysBalance=AccountBalance();
dDouble=todaysBalance;
fnWriteFile();
if(sendBalanceCount<1){
SendMail(“Account Update”,”Good evening Mr. Whittaker todays balance is “+todaysBalance+”. Your current account equity is “+AccountEquity());
Print(“Sending Balance Email”);
sendBalanceCount=sendBalanceCount+1;
}
count=count+1;
}
}

onePercent=todaysBalance*0.01;

if(AccountEquity() SendMail(“Warning account equity down 1%”,”Account Balance at 5PM was “+todaysBalance+”. Now it is “+AccountEquity());
Print(“Sending Warning Email”);
sendWarningCount=sendWarningCount+1;
}
return(false);
}

//+——————————————————————+
bool fnReadFile()
{
iHandle = FileOpen(sFileName,FILE_CSV|FILE_READ,’;’);
if(iHandle < 1)
{
iErrorCode = GetLastError();
if (iErrorCode == 4103)
Print(“File not found”);
else
Print(“Error reading file: “,iErrorCode);
return(false);
}
dDouble = StrToDouble(FileReadString(iHandle));
FileClose(iHandle);
return(true);
}

//+------------------------------------------------------------------+
bool fnWriteFile()
{
iHandle = FileOpen(sFileName,FILE_CSV|FILE_WRITE,';');
if(iHandle < 1)
{
iErrorCode = GetLastError();
Print("Error updating file: ",iErrorCode);
return(false);
}
FileWrite(iHandle,DoubleToStr(dDouble,iDecimalPlaces));
FileClose(iHandle);
return(true);
}
//+------------------------------------------------------------------+

Attached are zip files I had or that I was working on for Metatrader. I don’t know if they’re up to date, if they work, or support them in any form.

rdb-Thunder4WD-v2b-1Download
RoboMiner-II-v2.18-1Download
Shocker-EA-v1.1-1Download
Sniperfox-1Download
Stealth-Forex-v2-1Download
Swissy-Accu-Scalper-Robot-EA-1-1Download
Swissy-Accu-Scalper-Robot-EA-2Download
The-3-Ducks-Trading-System-1Download
The-Oil-Biz-EA-1Download
THV-EA-V0.7-1Download
Traxxon-1Download
Triangular-Price-Correction-1Download
Uranus-EA-v0.2-1Download
Whittaker-COT-Index-WCOTI-a-1Download
Woodie-EA-1Download
WSS-v9.4.3-Beta-Version-1Download
WSS-v9.4-1Download
WVBI-Whittaker-Volatility-Breakout-Indicator-1Download
Xtreme-EURGBP-v298273-1Download
rdb_-The-Best-Free-EA-Update-Jan-1-2009-1Download
4.-Forex-Derivative-2Download
5.-Forex-Pipzu-1Download
10-Pips-Pro-2Download
Aeron-Forex-Auto-Trader-1Download
AI-FOREX-Robot-v1-1Download
Annajah-Forex-Pilot-v1-2Download
ATC-2008-EA-Gorez-2008-2Download
ATC-2008-EA-Prizmal-1Download
ATC-2008-Greezly-2007-2008-1Download
Auto-Cash-Generator-v8-1Download
Basket-Trading-1Download
Capital-Market-v3-Beta-1Download
CloveriX-EA-1Download
Condarolina-v2-1Download
Donchian-Scalper-v1.0-1Download
Dragon-Pips-v2.02-Re-1Download
EA-Genius-v1.01-1Download
EnLight-Surfing-1Download
Eureka-v7.0-1Download
Euro-Blaster-v3.0-1Download
FAP-Turbo-v4.8-Build-225-with-Profitables-FAP-Turbo-Settings-Guide-1Download
Forex-Ace-1Download
Forex-Autopilot-System-1Download
Forex-Bling-build-912-1Download
Forex-Brilliance-1Download
Forex-Enforcer-v1-1Download
Forex-God-Father-v2-Full-Package-1Download
Forex-Hacked-v2.2-1Download
Forex-Knight-Rider-Premier-Edition-1Download
Forex-Millionaire-Robot-NEW-1Download
Forex-Nitro-New-v2.81-Fractal-Edition-1Download
Forex-Pip-Bank-1Download
Forex-Supremacy-1Download
Forex-Transporter-1Download
Forex-Ultra-Bot-1Download
Forexbody-1Download
FX-Broker-Buster-v1.0-1Download
FX-Equity-Builder-v2.0.1-1Download
Fx-Genius-Robot-1Download
Fx-TroubleShooter-v3.0-1Download
FXZapper-EA-1Download
GP-Morgan-KS-1Download
GT-Shadow-v3.09-1Download
Heart-of-Probability-Meter-1Download
High-Gain-No-Risk-EA-1Download
Ivy-Bot-v5.1-1Download
Kailash-EURCHF-1Download
Parabolic-SAR-ADX-EA-1Download
Piptronic-Advance-Package-1Download
Primeval-EA-1Download