Price Data Components
Orders Execution
Miscellaneous
0
Views
0
Downloads
0
Favorites
Bal_Eq_Ind_v1
// +------------------------------------------------------------------+
// | i-BalEq.mq4 |
// | Kim Igor aka KimIV |
// | http: // www.kimiv.ru |
// | 01.10.2006 Schedule of balance and equity. |
// +------------------------------------------------------------------+
#property copyright " Kim Igor aka KimIV "
#property link " http://www.kimiv.ru "
// - ---
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 1
//-------External parameters of the indicator
extern double Deposit = 1000; // the initial deposit
// To consider only the current symbol
extern bool CurSymbolOnly = False;
//-------Buffer for the indicator
double dBuf0[], dBuf1[];
//-------Global variables of the indicator
int oob[]; // index of opening bar
int oty[]; // order type
double olo[]; // lot
string osy[]; // symbol
double oop[]; // opening price
int ocb[]; // index of closing bar
double ocp[]; // closing price
double osw[]; // swap
double opr[]; // profit
// +------------------------------------------------------------------+
// | Custom indicator initialization function |
// +------------------------------------------------------------------+
void init()
{
IndicatorDigits(2);
// - ---
SetIndexBuffer(0, dBuf0);
SetIndexLabel(0, "Balance");
SetIndexStyle(0, DRAW_LINE);
// - ---
SetIndexBuffer(1, dBuf1);
SetIndexLabel(1, "Equity");
SetIndexStyle(1, DRAW_LINE);
}
// +------------------------------------------------------------------+
// | Custom indicator iteration function |
// +------------------------------------------------------------------+
void start()
{
double b, e, p, t;
int i, j, k;
// - ---
ReadDeals();
if (oob[0] < 0)
return;
k = ArraySize(oob);
// - ---
for (i = Bars; i >= oob[0]; i--)
{
dBuf0[i] = EMPTY_VALUE;
dBuf1[i] = EMPTY_VALUE;
}
for (i = oob[0]; i >= 0; i--)
{
b = Deposit;
e = 0;
for (j = 0; j < k; j++)
{
if (i <= oob[j] && i >= ocb[j])
{
p = MarketInfo(osy[j], MODE_POINT);
t = MarketInfo(osy[j], MODE_TICKVALUE);
if (t == 0)
t = 10;
if (p == 0)
{
if (StringFind(osy[j], "JPY") <0)
p = 0.0001;
else
p = 0.01;
}
if (oty[j] == OP_BUY)
e += osw[j] + (iClose(osy[j], 0, i) - oop[j]) / p*olo[j]*t;
else
e += osw[j] + (oop[j] - iClose(osy[j], 0, i)) / p*olo[j]*t;
}
else if (i <= ocb[j])
{
b += osw[j] + opr[j];
}
}
dBuf0[i] = b;
dBuf1[i] = b + e;
}
}
// +------------------------------------------------------------------+
// | Reading of transactions |
// +------------------------------------------------------------------+
void ReadDeals()
{
ArrayResize(oob, 0);
ArrayResize(oty, 0);
ArrayResize(olo, 0);
ArrayResize(osy, 0);
ArrayResize(oop, 0);
ArrayResize(ocb, 0);
ArrayResize(ocp, 0);
ArrayResize(osw, 0);
ArrayResize(opr, 0);
int h = OrdersHistoryTotal(), i, k;
// - ---
for (i = 0; i < h; i++) // read closed orders
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (!CurSymbolOnly || OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY || OrderType() == OP_SELL)
{
k = ArraySize(oob);
ArrayResize(oob, k + 1);
ArrayResize(oty, k + 1);
ArrayResize(olo, k + 1);
ArrayResize(osy, k + 1);
ArrayResize(oop, k + 1);
ArrayResize(ocb, k + 1);
ArrayResize(ocp, k + 1);
ArrayResize(osw, k + 1);
ArrayResize(opr, k + 1);
oob[k] = iBarShift(NULL, 0, OrderOpenTime()); // index of opening bar
oty[k] = OrderType(); // type
olo[k] = OrderLots(); // lot
osy[k] = OrderSymbol(); // symbol
oop[k] = OrderOpenPrice(); // opening price
ocb[k] = iBarShift(NULL, 0, OrderCloseTime()); // index of closing bar
ocp[k] = OrderClosePrice(); // closing price
osw[k] = OrderSwap(); // swap
opr[k] = OrderProfit(); // profit
}
}
}
}
h = OrdersTotal();
// - ---
for (i = 0; i < h; i++) // read active orders
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (!CurSymbolOnly || OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY || OrderType() == OP_SELL)
{
k = ArraySize(oob);
ArrayResize(oob, k + 1);
ArrayResize(oty, k + 1);
ArrayResize(olo, k + 1);
ArrayResize(osy, k + 1);
ArrayResize(oop, k + 1);
ArrayResize(ocb, k + 1);
ArrayResize(ocp, k + 1);
ArrayResize(osw, k + 1);
ArrayResize(opr, k + 1);
oob[k] = iBarShift(NULL, 0, OrderOpenTime ()); // index of opening bar
oty[k] = OrderType(); // type
olo[k] = OrderLots(); // lot
osy[k] = OrderSymbol(); // symbol
oop[k] = OrderOpenPrice(); // opening price
ocb[k] = 0; // index of closing bar (no closing bar yet)
ocp[k] = 0; // closing price (no closing price yet)
osw[k] = OrderSwap(); // swap
opr[k] = OrderProfit(); // profit
}
}
}
}
}
// +------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---