i-Breakeven
Download scriptThis script is a specialized monitoring tool designed to provide traders with a real-time, organized overview of their open trading positions. Instead of making decisions or automatically changing trades, it acts as an information dashboard that calculates and displays vital financial data directly on the trading chart.
Core Functionality
The logic of the script can be broken down into three main processes:
1. Portfolio Data Collection The script scans all currently active trades in your account. It filters for standard "Buy" and "Sell" positions and groups them by their specific financial instrument (e.g., EURUSD, Gold, etc.). For every unique instrument you are trading, the script calculates two key metrics:
- Net Equity: This adds up the profit or loss of all positions for that specific symbol, including any commissions or overnight swap fees.
- Net Lot Size: It calculates the total volume (lots) being traded per symbol, treating "Buys" as positive numbers and "Sells" as negative numbers to determine your net exposure.
2. Dynamic Breakeven Calculation One of the most significant features is its ability to calculate a "Breakeven" price for each symbol. The script takes the current net equity (profit/loss) of a specific instrument and mathematically determines the exact price point at which your total profit for that specific asset would become zero.
- If you have a balanced position where buys and sells cancel each other out (Net Lot is 0), the script identifies this as a "Lock."
- Otherwise, it provides a specific numerical price level on the screen.
3. Visual Dashboard Rendering Finally, the script draws a clean, formatted table on your trading screen. It automatically creates and updates labels to display:
- A list of all symbols you are currently involved in.
- The real-time profit/loss (Equity) for each individual symbol.
- The calculated Breakeven price for each symbol.
- A "Total" row at the bottom that summarizes your overall account equity across all positions.
Summary for the User
Think of this script as an automated accounting assistant. It continuously watches your open trades, does the heavy math of calculating net exposure and breakeven points for every different currency or asset you hold, and then presents that data in a tidy list on your screen so you can see exactly where your "zero point" is at any given moment.
//+------------------------------------------------------------------+
//| i-Breakeven.mq4 |
//| Copyright © 2007, RickD |
//| www.e2e-fx.net |
//+------------------------------------------------------------------+
#property copyright "© 2007 RickD"
#property link "www.e2e-fx.net"
//----
#define major 1
#define minor 0
//----
#property indicator_chart_window
#property indicator_buffers 0
//----
extern int Corner = 0;
extern int dy = 20;
extern color _Header = OrangeRed;
extern color _Text = RoyalBlue;
extern color _Data = CadetBlue;
extern color _Separator = MediumPurple;
//----
string prefix = "capital_";
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void init()
{
Comment("");
clear();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void deinit()
{
Comment("");
clear();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void clear()
{
string name;
int obj_total = ObjectsTotal();
//----
for(int i = obj_total - 1; i >= 0; i--)
{
name = ObjectName(i);
if(StringFind(name, prefix) == 0)
ObjectDelete(name);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void start()
{
clear();
string Sym[];
double Equity[];
double Lots[];
ArrayResize(Sym, 0);
ArrayResize(Equity, 0);
ArrayResize(Lots, 0);
int cnt = OrdersTotal();
//----
for(int i = 0; i < cnt; i++)
{
//----
if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
continue;
int type = OrderType();
//----
if(type != OP_BUY && type != OP_SELL)
continue;
bool found = false;
int size = ArraySize(Sym);
//----
for(int k = 0; k < size; k++)
{
//----
if(Sym[k] == OrderSymbol())
{
Equity[k] += OrderProfit() + OrderCommission() + OrderSwap();
//----
if(type == OP_BUY)
Lots[k] += OrderLots();
//----
if(type == OP_SELL)
Lots[k] -= OrderLots();
found = true;
break;
}
}
//----
if(found)
continue;
int ind = ArraySize(Sym);
ArrayResize(Sym, ind + 1);
Sym[ind] = OrderSymbol();
ArrayResize(Equity, ind + 1);
Equity[ind] = OrderProfit() + OrderCommission() + OrderSwap();
ArrayResize(Lots, ind + 1);
//----
if(type == OP_BUY)
Lots[k] = OrderLots();
//----
if(type == OP_SELL)
Lots[k] = -OrderLots();
}
string name = prefix + "symbols";
//----
if(ObjectFind(name) == -1)
{
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
}
ObjectSet(name, OBJPROP_XDISTANCE, 30);
ObjectSet(name, OBJPROP_YDISTANCE, 35);
ObjectSetText(name, "Symbol", 10, "Tahoma", _Header);
ObjectSet(name, OBJPROP_CORNER, Corner);
name = prefix + "equity";
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 130);
ObjectSet(name, OBJPROP_YDISTANCE, 35);
ObjectSetText(name, "Equity", 10, "Tahoma", _Header);
ObjectSet(name, OBJPROP_CORNER, Corner);
name = prefix + "breakeven";
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 220);
ObjectSet(name, OBJPROP_YDISTANCE, 35);
ObjectSetText(name, "Breakeven", 10, "Tahoma", _Header);
ObjectSet(name, OBJPROP_CORNER, Corner);
name = prefix + "tmp1";
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 20);
ObjectSet(name, OBJPROP_YDISTANCE, 35+dy);
ObjectSetText(name, "-----------------------------------------------------",
10, "Tahoma", _Separator);
ObjectSet(name, OBJPROP_CORNER, Corner);
double sum = 0;
string level0 = "";
size = ArraySize(Sym);
//----
for(i = 0; i < size; i++)
{
//----
if(Lots[i] == 0)
{
level0 = "Lock";
}
else
{
int dig = MarketInfo(Sym[i], MODE_DIGITS);
double point = MarketInfo(Sym[i], MODE_POINT);
double COP = Lots[i]*MarketInfo(Sym[i], MODE_TICKVALUE);
double val = MarketInfo(Sym[i], MODE_BID) - point*Equity[i] / COP;
level0 = DoubleToStr(val, dig);
}
name = prefix + "symbol"+i;
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 30);
ObjectSet(name, OBJPROP_YDISTANCE, 35 + dy*(i + 2));
ObjectSetText(name, Sym[i], 10, "Tahoma", _Text);
ObjectSet(name, OBJPROP_CORNER, Corner);
name = prefix + "equity" + i;
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 120);
ObjectSet(name, OBJPROP_YDISTANCE, 35 + dy*(i + 2));
string eq = DoubleToStr(Equity[i], 2);
//----
if(Equity[i] > 0) eq = "+" + eq;
eq = "$" + eq;
ObjectSetText(name, eq, 10, "Tahoma", _Data);
ObjectSet(name, OBJPROP_CORNER, Corner);
name = prefix + "breakeven"+i;
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 230);
ObjectSet(name, OBJPROP_YDISTANCE, 35 + dy*(i + 2));
ObjectSetText(name, level0, 10, "Tahoma", _Data);
ObjectSet(name, OBJPROP_CORNER, Corner);
sum += Equity[i];
}
name = prefix + "tmp2";
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 20);
ObjectSet(name, OBJPROP_YDISTANCE, 35 + dy*(i + 2));
ObjectSetText(name, "-----------------------------------------------------",
10, "Tahoma", _Separator);
ObjectSet(name, OBJPROP_CORNER, Corner);
name = prefix + "total";
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 30);
ObjectSet(name, OBJPROP_YDISTANCE, 35+dy*(i+3));
ObjectSetText(name, "Total", 10, "Tahoma", _Text);
ObjectSet(name, OBJPROP_CORNER, Corner);
name = prefix + "equity_total";
//----
if(ObjectFind(name) == -1)
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_XDISTANCE, 120);
ObjectSet(name, OBJPROP_YDISTANCE, 35+dy*(i+3));
eq = DoubleToStr(sum, 2);
//----
if(Equity[i] > 0)
eq = "+" + eq;
eq = "$" + eq;
ObjectSetText(name, eq, 10, "Tahoma", _Data);
ObjectSet(name, OBJPROP_CORNER, Corner);
}
//+------------------------------------------------------------------+
Comments