extern int Magic = 88;
extern string emp6 = "/////////////////Info settings////////////////";
extern bool show_info = true;
extern ENUM_BASE_CORNER info_corner = CORNER_LEFT_UPPER;
extern int info_size = 12;
extern int info_X = 20;
extern int info_Y = 190;
extern int info_Y_step = 20;
extern color Now_data_color = clrLightBlue;
extern color Max_data_color = clrLime;
extern color Min_data_color = clrCoral;
extern color Buys_color = clrLightBlue;
extern color Sells_color = clrRed;
extern color rectangle_color = clrDarkBlue;
extern int rectangle_width = 310;
extern int rectangle_height = 140;
extern bool reset_data = false;
string identif="simpiit9";
string obj1="profit:orders now";
string obj2="profit:orders max";
string obj3="profit:orders min ";
string obj4="BUYS now";
string obj5="SELLS now";
string GV_maxP="max_prof"+string(Magic);
string GV_minP="min_prof"+string(Magic);
string GV_maxO="max_order"+string(Magic);
string GV_minO="min_order"+string(Magic);
double min_prof,max_prof;
int min_prof_orders,max_prof_orders;
int buy,sell,Orders_Total;
double buy_lots;
double sell_lots;
///////////////////////////////////////////////////////////////////
int OnInit()
{
if(reset_data) {min_prof=0;max_prof=0;min_prof_orders=0;max_prof_orders=0;}
else
{
max_prof=GlobalVariableGet(GV_maxP);
min_prof=GlobalVariableGet(GV_minP);
max_prof_orders=int(GlobalVariableGet(GV_maxO));
min_prof_orders=int(GlobalVariableGet(GV_minO));
}
string name_delete;
for(int i=ObjectsTotal()-1;i>=0;i--)
{
name_delete=ObjectName(i);
if(StringFind(name_delete,identif)!=-1) ObjectDelete(name_delete);
}
return(INIT_SUCCEEDED);
}
////////////////////////////////////////////////////////////////
void OnDeinit(const int reason)
{
string name_delete;
for(int i=ObjectsTotal()-1;i>=0;i--)
{
name_delete=ObjectName(i);
if(StringFind(name_delete,identif)!=-1) ObjectDelete(name_delete);
}
//----
if(reset_data)
{
GlobalVariableDel(GV_maxP);
GlobalVariableDel(GV_minP);
GlobalVariableDel(GV_maxO);
GlobalVariableDel(GV_minO);
}
}
///////////////////////////////////////////
void OnTick()
{
if(show_info) draw();
}
///////////////////////////////////////////////
void draw()
{
draw_rectangle();
draw_labels();
}
//////////////////////////////////////////////
void draw_labels()
{
double curr_prof=Profit_f();
CountOpenedPositions_f();
int curr_orders=Orders_Total;
//max
if(curr_prof>max_prof)
{
max_prof=curr_prof;
max_prof_orders=curr_orders;
if(!reset_data)
{
GlobalVariableSet(GV_maxP,curr_prof);
GlobalVariableSet(GV_maxO,curr_orders);
}
}
//min
if(curr_prof<min_prof)
{
min_prof=curr_prof;
min_prof_orders=curr_orders;
if(!reset_data)
{
GlobalVariableSet(GV_minP,curr_prof);
GlobalVariableSet(GV_minO,curr_orders);
}
}
int Yy=info_Y;
Draw_f(obj1,DoubleToString(curr_prof,2)+":"+IntegerToString(curr_orders),Yy,Now_data_color);
Yy+=info_Y_step;
Draw_f(obj2,DoubleToString(max_prof,2)+":"+IntegerToString(max_prof_orders),Yy,Max_data_color);
Yy+=info_Y_step;
Draw_f(obj3,DoubleToString(min_prof,2)+":"+IntegerToString(min_prof_orders),Yy,Min_data_color);
Yy+=info_Y_step;
Draw_f(obj4,string(buy),Yy,Buys_color);
Yy+=info_Y_step;
Draw_f(obj5,string(sell),Yy,Sells_color);
Yy+=info_Y_step;
}
///////////////////////////////////////////////
void Draw_f(string name,string object,int Y_distance, color Color)
{
string name2=identif+name;
if(ObjectFind(name2)==-1)
{
ObjectCreate(0,name2,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,name2,OBJPROP_CORNER,info_corner);
ObjectSetInteger(0,name2, OBJPROP_XDISTANCE,info_X);
ObjectSetInteger(0,name2, OBJPROP_YDISTANCE, Y_distance);
ObjectSetInteger(0,name2, OBJPROP_FONTSIZE, info_size);
ObjectSetInteger(0,name2, OBJPROP_COLOR, Color);
ObjectSetString(0,name2, OBJPROP_FONT, "Arrial");
ObjectSetInteger(0,name2,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name2,OBJPROP_BACK,false);
ObjectSetInteger(0,name2,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name2,OBJPROP_SELECTED,false);
}
ObjectSetString(0,name2,OBJPROP_TEXT,name+"= "+object);
}
//////////////////////////////////////////////////////////
void draw_rectangle()
{
string name2=identif+"tsLRectan";
if(ObjectFind(name2)==-1)
{
ObjectCreate(0,name2,OBJ_RECTANGLE_LABEL,0,0,0);
ObjectSetInteger(0,name2,OBJPROP_CORNER,info_corner);
ObjectSetInteger(0,name2,OBJPROP_XDISTANCE,info_X-20);
ObjectSetInteger(0,name2,OBJPROP_YDISTANCE,info_Y-20);
ObjectSetInteger(0,name2,OBJPROP_XSIZE,rectangle_width);
ObjectSetInteger(0,name2,OBJPROP_YSIZE,rectangle_height);
ObjectSetInteger(0,name2,OBJPROP_BGCOLOR,rectangle_color);
ObjectSetInteger(0,name2,OBJPROP_BACK,false);
ObjectSetInteger(0,name2,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name2,OBJPROP_SELECTED,false);
ObjectSetInteger(0,name2,OBJPROP_HIDDEN,true);
}
}
////////////////////////////////////////////////////////////////////////////////////
void CountOpenedPositions_f()
{
buy=0;
sell=0;
buy_lots=0;
sell_lots=0;
Orders_Total=0;
for (int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS))
{
if(OrderMagicNumber()==Magic)
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) {buy++;buy_lots+=OrderLots();}
if(OrderType()==OP_SELL) {sell++;sell_lots+=OrderLots();}
}
}
}
}
Orders_Total=buy+sell;
}
///////////////////////////////////////////////////////////////////////////////////
double Profit_f()
{
double prof=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS))
{
if(OrderMagicNumber()==Magic)
{
if(OrderSymbol()==Symbol())
{
prof+=OrderProfit()+OrderSwap()+OrderCommission();
}
}
}
}
return(prof);
}