//+------------------------------------------------------------------+
//| Profit.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2."
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
// Настройки фона
input int XRectSize = 130;// ширина по Х
input int YRectSize = 30; // ширина по Y
input int XRectDist = 20; // отступ от угла по Х
input int YRectDist = 20; // отступ от угла по Y
input int RectCorner = 0; // какой угол
input color RectColor=Blue;// цвет фона
// Настройки теста
input int XLabelDist = 25;// отступ от угла по Х
input int YLabelDist = 25;// отступ от угла по Y
input int LabelCorner = 0;// какой угол
input color ProfitColor = White; // цвет профита
input color LossColor = Yellow; // цвет убытка
input int LabelFSize = 12; // размер шрифта
input string LabelFont = "Arial"; // тип шрифта
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0,"R");
ObjectDelete(0,"L");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutRectLabel()
{
ObjectCreate(0,"R",OBJ_RECTANGLE_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,"R",OBJPROP_XDISTANCE,XRectDist);
ObjectSetInteger(0,"R",OBJPROP_YDISTANCE,YRectDist);
//--- установим размеры метки
ObjectSetInteger(0,"R",OBJPROP_XSIZE,XRectSize);
ObjectSetInteger(0,"R",OBJPROP_YSIZE,YRectSize);
//--- установим цвет фона
ObjectSetInteger(0,"R",OBJPROP_BGCOLOR,RectColor);
//--- установим тип границы
ObjectSetInteger(0,"R",OBJPROP_BORDER_TYPE,BORDER_RAISED);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,"R",OBJPROP_CORNER,RectCorner);
//--- отобразим на переднем (false) или заднем (true) плане
ObjectSetInteger(0,"R",OBJPROP_BACK,false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutLabel(string text)
{
ObjectDelete(0,"L");
//--- создадим текстовую метку
ObjectCreate(0,"L",OBJ_LABEL,0,0,0);
//--- установим координаты метки
ObjectSetInteger(0,"L",OBJPROP_XDISTANCE,XLabelDist);
ObjectSetInteger(0,"L",OBJPROP_YDISTANCE,YLabelDist);
//--- установим угол графика, относительно которого будут определяться координаты точки
ObjectSetInteger(0,"L",OBJPROP_CORNER,LabelCorner);
//--- установим текст
ObjectSetString(0,"L",OBJPROP_TEXT,text);
//--- установим шрифт текста
ObjectSetString(0,"L",OBJPROP_FONT,LabelFont);
//--- установим размер шрифта
ObjectSetInteger(0,"L",OBJPROP_FONTSIZE,LabelFSize);
//--- установим цвет
if(AllProfit()>0) ObjectSetInteger(0,"L",OBJPROP_COLOR,ProfitColor);
else ObjectSetInteger(0,"L",OBJPROP_COLOR,LossColor);
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
PutRectLabel();
PutLabel("Profit: "+(string)NormalizeDouble(AllProfit(),2)+"$");
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
AM2