//+------------------------------------------------------------------+ //| iOrdersInfo.mq4 | //| A.Lopatin 2014 | //| diver.stv@gmail.com | //+------------------------------------------------------------------+ #property copyright "A.Lopatin 2014" #property link "diver.stv@gmail.com" #property version "1.00" #property strict #property indicator_chart_window #include input color TextColor = clrWhite; input string TextFont = "Arial"; input int FontSize = 11; int timer_period = 2000; string title_lbl[9]; string lines_lbl[4][9]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { EventSetMillisecondTimer(timer_period); // create timer title_lbl[0] = "-- FILTER --"; title_lbl[1] = "-- BUYS --"; title_lbl[2] = "-- BUY/L --"; title_lbl[3] = "-- BUY/S --"; title_lbl[4] = "-- SELLS --"; title_lbl[5] = "-- SELL/L --"; title_lbl[6] = "-- SELL/S --"; title_lbl[7] = "-- VOLUME --"; title_lbl[8] = "-- P/L --"; lines_lbl[0][0] = "line11"; lines_lbl[0][1] = "line12"; lines_lbl[0][2] = "line13"; lines_lbl[0][3] = "line14"; lines_lbl[0][4] = "line15"; lines_lbl[0][5] = "line16"; lines_lbl[0][6] = "line17"; lines_lbl[0][7] = "line18"; lines_lbl[0][8] = "line19"; lines_lbl[1][0] = "line21"; lines_lbl[1][1] = "line22"; lines_lbl[1][2] = "line23"; lines_lbl[1][3] = "line24"; lines_lbl[1][4] = "line25"; lines_lbl[1][5] = "line26"; lines_lbl[1][6] = "line27"; lines_lbl[1][7] = "line28"; lines_lbl[1][8] = "line29"; lines_lbl[2][0] = "line31"; lines_lbl[2][1] = "line32"; lines_lbl[2][2] = "line33"; lines_lbl[2][3] = "line34"; lines_lbl[2][4] = "line35"; lines_lbl[2][5] = "line36"; lines_lbl[2][6] = "line37"; lines_lbl[2][7] = "line38"; lines_lbl[2][8] = "line39"; return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { EventKillTimer(); /*delete labels*/ for(int i = 0; i < 9; i++ ) { ObjectDelete(title_lbl[i]); ObjectDelete(lines_lbl[0][i]); ObjectDelete(lines_lbl[1][i]); ObjectDelete(lines_lbl[2][i]); } } //+------------------------------------------------------------------+ //| 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[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { int x_coord = 10, y_coord = 15, y_step = MathRound(1.8*FontSize); COrdersCounter symbol_counter(0, Symbol(), MODE_TRADES), account_counter(0, "", MODE_TRADES), history_counter(0, "", MODE_HISTORY); symbol_counter.refreshData(); // retrieve data for market orders by current symbol account_counter.refreshData();// retrieve data for market orders of whole account history_counter.refreshData();// retrieve data for closed orders of whole account /* draw title of the table*/ draw_label(title_lbl[0], CORNER_LEFT_UPPER, x_coord, y_coord, title_lbl[0], TextColor, TextFont, FontSize); draw_label(title_lbl[1], CORNER_LEFT_UPPER, x_coord+8*FontSize, y_coord, title_lbl[1], TextColor, TextFont, FontSize); draw_label(title_lbl[2], CORNER_LEFT_UPPER, x_coord+15*FontSize, y_coord, title_lbl[2], TextColor, TextFont, FontSize); draw_label(title_lbl[3], CORNER_LEFT_UPPER, x_coord+22*FontSize, y_coord, title_lbl[3], TextColor, TextFont, FontSize); draw_label(title_lbl[4], CORNER_LEFT_UPPER, x_coord+29*FontSize, y_coord, title_lbl[4], TextColor, TextFont, FontSize); draw_label(title_lbl[5], CORNER_LEFT_UPPER, x_coord+36*FontSize, y_coord, title_lbl[5], TextColor, TextFont, FontSize); draw_label(title_lbl[6], CORNER_LEFT_UPPER, x_coord+44*FontSize, y_coord, title_lbl[6], TextColor, TextFont, FontSize); draw_label(title_lbl[7], CORNER_LEFT_UPPER, x_coord+52*FontSize, y_coord, title_lbl[7], TextColor, TextFont, FontSize); draw_label(title_lbl[8], CORNER_LEFT_UPPER, x_coord+61*FontSize, y_coord, title_lbl[8], TextColor, TextFont, FontSize); /* draw row for current symbol data */ y_coord += y_step; draw_label(lines_lbl[0][0], CORNER_LEFT_UPPER, x_coord+1*FontSize, y_coord, symbol_counter.getSymbol(), TextColor, TextFont, FontSize); draw_label(lines_lbl[0][1], CORNER_LEFT_UPPER, x_coord+11*FontSize, y_coord, DoubleToString(symbol_counter.getOrdersCount(OP_BUY),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[0][2], CORNER_LEFT_UPPER, x_coord+18*FontSize, y_coord, DoubleToString(symbol_counter.getOrdersCount(OP_BUYLIMIT),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[0][3], CORNER_LEFT_UPPER, x_coord+25*FontSize, y_coord, DoubleToString(symbol_counter.getOrdersCount(OP_BUYSTOP),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[0][4], CORNER_LEFT_UPPER, x_coord+32*FontSize, y_coord, DoubleToString(symbol_counter.getOrdersCount(OP_SELL),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[0][5], CORNER_LEFT_UPPER, x_coord+39*FontSize, y_coord, DoubleToString(symbol_counter.getOrdersCount(OP_SELLLIMIT),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[0][6], CORNER_LEFT_UPPER, x_coord+47*FontSize, y_coord, DoubleToString(symbol_counter.getOrdersCount(OP_SELLSTOP),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[0][7], CORNER_LEFT_UPPER, x_coord+53*FontSize, y_coord, DoubleToString(symbol_counter.getMarketVolume(),2), TextColor, TextFont, FontSize); draw_label(lines_lbl[0][8], CORNER_LEFT_UPPER, x_coord+62*FontSize, y_coord, DoubleToString(symbol_counter.getTotalProfit().points, 2), TextColor, TextFont, FontSize); /* draw row for current account data */ y_coord += y_step; draw_label(lines_lbl[1][0], CORNER_LEFT_UPPER, x_coord+1*FontSize, y_coord, "Account", TextColor, TextFont, FontSize); draw_label(lines_lbl[1][1], CORNER_LEFT_UPPER, x_coord+11*FontSize, y_coord, DoubleToString(account_counter.getOrdersCount(OP_BUY),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[1][2], CORNER_LEFT_UPPER, x_coord+18*FontSize, y_coord, DoubleToString(account_counter.getOrdersCount(OP_BUYLIMIT),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[1][3], CORNER_LEFT_UPPER, x_coord+25*FontSize, y_coord, DoubleToString(account_counter.getOrdersCount(OP_BUYSTOP),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[1][4], CORNER_LEFT_UPPER, x_coord+32*FontSize, y_coord, DoubleToString(account_counter.getOrdersCount(OP_SELL),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[1][5], CORNER_LEFT_UPPER, x_coord+39*FontSize, y_coord, DoubleToString(account_counter.getOrdersCount(OP_SELLLIMIT),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[1][6], CORNER_LEFT_UPPER, x_coord+47*FontSize, y_coord, DoubleToString(account_counter.getOrdersCount(OP_SELLSTOP),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[1][7], CORNER_LEFT_UPPER, x_coord+53*FontSize, y_coord, DoubleToString(account_counter.getMarketVolume(), 2), TextColor, TextFont, FontSize); draw_label(lines_lbl[1][8], CORNER_LEFT_UPPER, x_coord+62*FontSize, y_coord, DoubleToString(account_counter.getTotalProfit().points, 2), TextColor, TextFont, FontSize); /* draw row for current history data */ y_coord += y_step; draw_label(lines_lbl[2][0], CORNER_LEFT_UPPER, x_coord+1*FontSize, y_coord, "History", TextColor, TextFont, FontSize); draw_label(lines_lbl[2][1], CORNER_LEFT_UPPER, x_coord+11*FontSize, y_coord, DoubleToString(history_counter.getOrdersCount(OP_BUY),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[2][2], CORNER_LEFT_UPPER, x_coord+18*FontSize, y_coord, DoubleToString(history_counter.getOrdersCount(OP_BUYLIMIT),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[2][3], CORNER_LEFT_UPPER, x_coord+25*FontSize, y_coord, DoubleToString(history_counter.getOrdersCount(OP_BUYSTOP),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[2][4], CORNER_LEFT_UPPER, x_coord+32*FontSize, y_coord, DoubleToString(history_counter.getOrdersCount(OP_SELL),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[2][5], CORNER_LEFT_UPPER, x_coord+39*FontSize, y_coord, DoubleToString(history_counter.getOrdersCount(OP_SELLLIMIT),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[2][6], CORNER_LEFT_UPPER, x_coord+47*FontSize, y_coord, DoubleToString(history_counter.getOrdersCount(OP_SELLSTOP),0), TextColor, TextFont, FontSize); draw_label(lines_lbl[2][7], CORNER_LEFT_UPPER, x_coord+53*FontSize, y_coord, DoubleToString(history_counter.getMarketVolume(), 2), TextColor, TextFont, FontSize); draw_label(lines_lbl[2][8], CORNER_LEFT_UPPER, x_coord+62*FontSize, y_coord, DoubleToString(history_counter.getTotalProfit().points, 2), TextColor, TextFont, FontSize); } //+------------------------------------------------------------------+ void draw_label(string name, int anchor, int x_distance, int y_distance, string text, color text_color, string font_name, int font_size) { bool is_exist = false; if( ObjectFind(name) < 0 ) is_exist = ObjectCreate(name, OBJ_LABEL, 0, 0, 0); else is_exist = true; if( is_exist ) { ObjectSet(name, OBJPROP_CORNER, anchor); ObjectSetText(name, text, font_size, font_name, text_color); ObjectSet(name, OBJPROP_XDISTANCE, x_distance); ObjectSet(name, OBJPROP_YDISTANCE, y_distance); } }