Margin_DrawDown_Tracker

Download script
Author: Copyright � 2007, P. Kubitzki. All Rights Reserved
Margin_DrawDown_Tracker

This tool is designed as a real-time monitoring system for your trading account, specifically built to act as an early warning system against two of the biggest risks in trading: excessive drawdown and dangerously low margin levels.

Core Functionality

The script constantly monitors your live trading activity. It calculates your current account health by looking at your available equity versus the margin required to hold your open positions. It then compares these figures against safety limits that you can set manually.

Key Monitoring Features

  • Margin Level Tracking: The tool calculates your "Margin Level" percentage. If this level drops below a specific threshold you define, it identifies that your account is becoming over-leveraged or at risk of a margin call.
  • Drawdown Monitoring: It tracks your floating profit/loss. If your account losses reach a pre-defined negative limit (your "Drawdown" limit), the tool recognizes this as a critical risk event.
  • Peak Statistics Tracking: Beyond just alerts, the script keeps a running record of your account's extremes. It identifies and displays:
    • The highest floating profit achieved during the current session.
    • The maximum margin required by your trades.
    • The deepest drawdown reached.

Alerting System

To ensure you don't have to stare at the screen constantly, the script includes an automated notification system. When a safety limit is breached:

  1. Visual Alert: It triggers an immediate pop-up warning on your trading platform.
  2. Email Notification: It sends an automated email to your connected account with a custom subject line and message, ensuring you are notified even if you are away from your computer.
  3. Smart Triggering: The script is designed to be "smart"—it only sends the alert once per event (changing its status from "No Alert" to "Alert Sent"). This prevents your inbox from being flooded with repeated messages for the same incident.

On-Screen Dashboard

The tool provides a clear, text-based summary directly on your trading chart. This dashboard gives you a real-time glance at your current leverage, your highest profits, your maximum drawdown, and the current status of your alert triggers. It essentially serves as a "dashboard" for your account's safety limits.

Orders Execution
Checks for the total of open orders
Miscellaneous
It issuies visual alerts to the screenIt sends emails
8 Views
0 Downloads
0 Favorites
Margin_DrawDown_Tracker
//+------------------------------------------------------------------+
//|                                      Margin_DrawDown_Tracker.mq4 |
//|                                    Copyright © 2007, P. Kubitzki |
//|                                              fxtogo4me@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, P. Kubitzki. All Rights Reserved"
#property link      "http://www.SecretsFromTheHeart.com"

double MaxAccountMargin = 0.0;
double MaxDrawDown = 0.0;
double MinMarginLevel = 100000.0; //default start value
extern double MinMarginForAlert = 500.0; //(margin call if less than 100), if margin goes down to this number a message is sent to my cell phone
extern double MaxDrawDownForAlert = -3000.00;
double AccountMarginLevel = 0.0;
extern string Subject = "FXDD - Demo";
extern string MarginLevelMessage = "MARGIN LEVEL GETTING TOO LOW!!!";
extern string DrawDownMessage = "Draw Down hitting limit!!!";
extern int MarginAlertTrigger = 1; //1 = no alert yet, 2 = alert triggered
extern int DrawDownAlertTrigger = 1; //1 = no alert yet, 2 = alert triggered
double MaxFloatingProfit = 0.0;
int AcctLeverage = 0;

int deinit()
  {

  return(0);
 }
  
int init()

   {
 
    return(0);
   }
 
 
  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   if( OrdersTotal() == 0) return;
    AccountMarginLevel = (AccountEquity() / AccountMargin()) * 100.0;

    ChartComment(); 
     if (MinMarginLevel <= MinMarginForAlert && MarginAlertTrigger == 1)
     {
        Alert( "WARNING MARGIN GETTING TOO LOW!!!" );      
        SendMail( Subject, MarginLevelMessage );
        MarginAlertTrigger = 2;
     }      
     if ( AccountProfit() <= MaxDrawDownForAlert && DrawDownAlertTrigger == 1)
     {
        Alert( "Draw Down hitting limit!!!" );      
        SendMail( Subject, DrawDownMessage );
        DrawDownAlertTrigger = 2;
     }      
   return(0);
  }
  
void ChartComment() 
{

     if (AccountMarginLevel < MinMarginLevel)
           MinMarginLevel = AccountMarginLevel;
     if (AccountMargin() > MaxAccountMargin)
           MaxAccountMargin = AccountMargin();
     if (AccountProfit() < MaxDrawDown)
           MaxDrawDown = AccountProfit(); 
     if (AccountProfit() > MaxFloatingProfit)
           MaxFloatingProfit = AccountProfit();
     AcctLeverage = AccountLeverage();
         
     Comment ("Copyright © 2007 P. Kubitzki, www.SecretsFromTheHeart.com","\nAccount Leverage is ",AcctLeverage,":1","   MaxFloatingProfit = ",MaxFloatingProfit,"\nMaxAccountMargin = ",MaxAccountMargin,"           MaxDrawdown = ",MaxDrawDown,"\nMinMarginForAlert =  ",MinMarginForAlert,"   MaxDrawDownForAlert = ",MaxDrawDownForAlert,"\nAlertTriggers: 1 = No Alert, 2 = Alert Sent","\nMarginAlertTrigger =",MarginAlertTrigger,"   DrawDownAlertTrigger = ",DrawDownAlertTrigger);
 
}
//+------------------------------------------------------------------+


Comments