Lida1





//+------------------------------------------------------------------+
//|                                                        Lida1.mq4 |
//|                                          Copyright © 2009, xroot |
//|                                               http://pycckue.org |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Lida1 v0.4 by xroot"
#property link      "xroot@pycckue.org"

#property indicator_separate_window

#define MAX_PAIRS 20 

string open_trade_symbols[MAX_PAIRS];
int num_sell_orders[MAX_PAIRS];
int num_buy_orders[MAX_PAIRS];
double total_sell_amount[MAX_PAIRS];
double total_buy_amount[MAX_PAIRS];
double avg_sell[MAX_PAIRS];
double avg_buy[MAX_PAIRS];
double commissions[MAX_PAIRS];   //commissions are the same for both order types
double sell_lots[MAX_PAIRS];
double buy_lots[MAX_PAIRS];
double swap[MAX_PAIRS];          // swaps are the same for both order types

color txt_color = Gray;
color neutral_color = Gray;
color negative_color = Red;
color positive_color = Green;
string font_str = "Courier New";
int window_index = -1;
string ind_name = "Lida 0.4";

// column offsets
int col_symbol       = 40;
int col_plsell       = 100;
int col_samtk        = 160;
int col_avgsell      = 215;
int col_avgbuy       = 270;
int col_bamtk        = 330;
int col_plbuy        = 395;
int col_amtk         = 460;
int col_grosspl      = 520;
int col_netpl        = 600;
int col_commissions  = 650;
int col_swap         = 710;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  IndicatorShortName(ind_name);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   ObjectsDeleteAll(WindowFind(ind_name));
   return(0);
}
  
// aligns numbers
//
string
align_str( double x, int num_digits)
{
   int rc = 3;
   string str = "";
   double x1 =0;
   string final_str = "";
      
   if (num_digits >= 4) {
      num_digits = 4;
      rc -= 2;
   }
   
   if (num_digits == 3) {
      num_digits = 2;
   }
   
   if (x < 0)
      rc--;
      
   if ( x == 0)
      rc += num_digits;
                 
   x1 = MathAbs(x);
   
   x1 /= 10;
   while( x1 >= 1) {
      rc -= 1;
      x1 /= 10;
   }
   
   for (int i=0; i<rc; i++) {
      str = StringConcatenate(str, " ");   
   }
   
   if (x == 0)
      final_str = StringConcatenate( str, "-");
   else
      final_str = StringConcatenate(str, DoubleToStr(x, num_digits));
      
   return (final_str);
}
  
void
doit()
{
// put blanks in
//ArrayInitialize(open_trade_symbols, "");
for (int r=0;r<MAX_PAIRS;r++) {
   open_trade_symbols[r] = "XXX";
   num_sell_orders[r] = 0;  
   num_buy_orders[r] = 0;
   total_sell_amount[r] = 0;
   total_buy_amount[r] = 0;
   avg_sell[r] = 0;
   avg_buy[r] = 0;
   commissions[r] = 0;
   buy_lots[r] = 0;
   sell_lots[r] = 0;
   swap[r] = 0;
}

// populate open_trade_symbols[] with currency pairs of open Orders 
   for ( int i = 0; i < OrdersTotal(); i++) {
      if ( OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
            for ( int j =0; j < MAX_PAIRS; j++) {
               if ( open_trade_symbols[j] == OrderSymbol()) {
                   break;
               }  
               if ( open_trade_symbols[j] == "XXX") {
                   open_trade_symbols[j] = OrderSymbol();
                   break;
               }
            }
      }
   }

// for each currency pair count count the number of trades
   for ( int ij = 0; ij < OrdersTotal(); ij++) 
   {
      if ( OrderSelect(ij,SELECT_BY_POS,MODE_TRADES)) 
      {
         for (int ii = 0;ii<MAX_PAIRS;ii++) {
            if (open_trade_symbols[ii] != "XXX")
            {
               if ( open_trade_symbols[ii] == OrderSymbol() )
               {
                  if ( OrderType() == OP_SELL) 
                  {
                     num_sell_orders[ii]++;
                     total_sell_amount[ii] += OrderProfit();
                     commissions[ii] += OrderCommission();
                     sell_lots[ii] += OrderLots();
                     avg_sell[ii] += OrderLots() * OrderOpenPrice();
                     swap[ii] += OrderSwap();
                  } else if ( OrderType() == OP_BUY) {
                     num_buy_orders[ii]++;
                     total_buy_amount[ii] += OrderProfit();
                     commissions[ii] += OrderCommission();
                     buy_lots[ii] += OrderLots();
                     avg_buy[ii] += OrderLots() * OrderOpenPrice();
                     swap[ii] += OrderSwap();                 
                  } else {
                     // stop and limit orders here
                  }
               }  
            }
         }
      }
   }

// calculate the average buy/sell values
for (int k=0; k< MAX_PAIRS; k++) {
   if (open_trade_symbols[k] != "XXX") {
      if (buy_lots[k] > 0)
         avg_buy[k] = avg_buy[k] / buy_lots[k];
      if (sell_lots[k] > 0)
         avg_sell[k] = avg_sell[k] / sell_lots[k];
   }
}

}

void make_headers()
{
   txt_color = DimGray;
   ObjectCreate("Symbol", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("Symbol","Symbol", 8, font_str, txt_color);
   ObjectSet("Symbol", OBJPROP_CORNER, 0);
   ObjectSet("Symbol", OBJPROP_XDISTANCE, col_symbol);
   ObjectSet("Symbol", OBJPROP_YDISTANCE, 2);
     
   ObjectCreate("plsell", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("plsell","P/L Sell", 8, font_str, txt_color);
   ObjectSet("plsell", OBJPROP_CORNER, 0);
   ObjectSet("plsell", OBJPROP_XDISTANCE, col_plsell);
   ObjectSet("plsell", OBJPROP_YDISTANCE, 2);
     
   ObjectCreate("S Amt (K)", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("S Amt (K)","S Amt(K)", 8, font_str, txt_color);
   ObjectSet("S Amt (K)", OBJPROP_CORNER, 0);
   ObjectSet("S Amt (K)", OBJPROP_XDISTANCE, col_samtk);
   ObjectSet("S Amt (K)", OBJPROP_YDISTANCE, 2);
     
   ObjectCreate("Avg Sell", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("Avg Sell","Avg Sell", 8, font_str, txt_color);
   ObjectSet("Avg Sell", OBJPROP_CORNER, 0);
   ObjectSet("Avg Sell", OBJPROP_XDISTANCE, col_avgsell);
   ObjectSet("Avg Sell", OBJPROP_YDISTANCE, 2);
     
     
   ObjectCreate("Avg Buy", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("Avg Buy","Avg Buy", 8, font_str, txt_color);
   ObjectSet("Avg Buy", OBJPROP_CORNER, 0);
   ObjectSet("Avg Buy", OBJPROP_XDISTANCE, col_avgbuy);
   ObjectSet("Avg Buy", OBJPROP_YDISTANCE, 2);
     
   ObjectCreate("B Amt (K)", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("B Amt (K)","B Amt(K)", 8, font_str, txt_color);
   ObjectSet("B Amt (K)", OBJPROP_CORNER, 0);
   ObjectSet("B Amt (K)", OBJPROP_XDISTANCE, col_bamtk);
   ObjectSet("B Amt (K)", OBJPROP_YDISTANCE, 2);
     
   ObjectCreate("P/L Buy", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("P/L Buy","P/L Buy", 8, font_str, txt_color);
   ObjectSet("P/L Buy", OBJPROP_CORNER, 0);
   ObjectSet("P/L Buy", OBJPROP_XDISTANCE, col_plbuy);
   ObjectSet("P/L Buy", OBJPROP_YDISTANCE, 2);
     
   ObjectCreate("AMT (K)", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("AMT (K)","AMT(K)", 8, font_str, txt_color);
   ObjectSet("AMT (K)", OBJPROP_CORNER, 0);
   ObjectSet("AMT (K)", OBJPROP_XDISTANCE, col_amtk);
   ObjectSet("AMT (K)", OBJPROP_YDISTANCE, 2);
   
   ObjectCreate("Gross P/L", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("Gross P/L","Gross P/L", 8, font_str, txt_color);
   ObjectSet("Gross P/L", OBJPROP_CORNER, 0);
   ObjectSet("Gross P/L", OBJPROP_XDISTANCE, col_grosspl);
   ObjectSet("Gross P/L", OBJPROP_YDISTANCE, 2);
    
   ObjectCreate("Net P/L", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("Net P/L","Net P/L", 8, font_str, txt_color);
   ObjectSet("Net P/L", OBJPROP_CORNER, 0);
   ObjectSet("Net P/L", OBJPROP_XDISTANCE, col_netpl);
   ObjectSet("Net P/L", OBJPROP_YDISTANCE, 2);
     
   ObjectCreate("Commissions", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("Commissions","Commiss", 8, font_str, txt_color);
   ObjectSet("Commissions", OBJPROP_CORNER, 0);
   ObjectSet("Commissions", OBJPROP_XDISTANCE, col_commissions+8);   // :-)
   ObjectSet("Commissions", OBJPROP_YDISTANCE, 2);

   ObjectCreate("Swap", OBJ_LABEL, window_index, 0, 0);
   ObjectSetText("Swap","Swap", 8, font_str, txt_color);
   ObjectSet("Swap", OBJPROP_CORNER, 0);
   ObjectSet("Swap", OBJPROP_XDISTANCE, col_swap+15);                // ;-)
   ObjectSet("Swap", OBJPROP_YDISTANCE, 2);
    
}

void
displayit()
{
   int hpos = 0;   // accumulates position of the column
   int vpos = 0;   // accumulates position of the line
   int digits = 2;
   
   for (int i=0;i<MAX_PAIRS;i++) {
      txt_color = DimGray;
      if ( open_trade_symbols[i] != "XXX") {
         ObjectCreate("Symbol"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         ObjectSetText("Symbol"+ DoubleToStr(i,0),open_trade_symbols[i], 8, font_str, txt_color);
         ObjectSet("Symbol"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("Symbol"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_symbol);
         ObjectSet("Symbol"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);      // :-)
         txt_color = neutral_color;
     
         ObjectCreate("plsell"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         if (total_sell_amount[i]< 0) {
            txt_color = negative_color;
         } else if (total_sell_amount[i] == 0) {
            txt_color = neutral_color;
         } else {
            txt_color = positive_color;
         }    
         digits = 2;
         ObjectSetText("plsell"+ DoubleToStr(i,0), align_str(total_sell_amount[i], digits), 8, font_str, txt_color);
         ObjectSet("plsell"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("plsell"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_plsell);
         ObjectSet("plsell"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
         txt_color = neutral_color;
     
         digits = 0;
         ObjectCreate("S Amt (K)"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         ObjectSetText("S Amt (K)"+ DoubleToStr(i,0),align_str(sell_lots[i]*100, digits), 8, font_str, txt_color);
         ObjectSet("S Amt (K)"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("S Amt (K)"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_samtk);
         ObjectSet("S Amt (K)"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
     
         digits = MarketInfo(open_trade_symbols[i], MODE_DIGITS);
         ObjectCreate("Avg Sell"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         ObjectSetText("Avg Sell"+ DoubleToStr(i,0),align_str(avg_sell[i], digits), 8, font_str, txt_color);
         ObjectSet("Avg Sell"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("Avg Sell"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_avgsell);
         ObjectSet("Avg Sell"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
     
         digits = MarketInfo(open_trade_symbols[i], MODE_DIGITS);
         ObjectCreate("Avg Buy"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         ObjectSetText("Avg Buy"+ DoubleToStr(i,0),align_str(avg_buy[i], digits), 8, font_str, txt_color);
         ObjectSet("Avg Buy"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("Avg Buy"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_avgbuy);
         ObjectSet("Avg Buy"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
     
         ObjectCreate("B Amt (K)"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         ObjectSetText("B Amt (K)"+ DoubleToStr(i,0),align_str(buy_lots[i]*100, 0), 8, font_str, txt_color);
         ObjectSet("B Amt (K)"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("B Amt (K)"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_bamtk);
         ObjectSet("B Amt (K)"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
     
         ObjectCreate("P/L Buy"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         if (total_buy_amount[i]< 0) {
            txt_color = negative_color;
         } else if (total_buy_amount[i] == 0) {
            txt_color = neutral_color;
         } else {
            txt_color = positive_color;
         }    
         ObjectSetText("P/L Buy"+ DoubleToStr(i,0),align_str(total_buy_amount[i], 2), 8, font_str, txt_color);
         ObjectSet("P/L Buy"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("P/L Buy"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_plbuy);
         ObjectSet("P/L Buy"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
         txt_color = positive_color;
     
         ObjectCreate("AMT (K)"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         if ((buy_lots[i]-sell_lots[i])< 0) {
            txt_color = negative_color;
         } else if ((buy_lots[i]-sell_lots[i]) == 0) {
            txt_color = neutral_color;
         } else {
            txt_color = positive_color;
         }    
         ObjectSetText("AMT (K)"+ DoubleToStr(i,0),align_str((buy_lots[i]-sell_lots[i])*100, 0), 8, font_str, txt_color);
         ObjectSet("AMT (K)"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("AMT (K)"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_amtk);
         ObjectSet("AMT (K)"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
         txt_color = neutral_color;

     
         ObjectCreate("Gross P/L"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         if ((total_sell_amount[i]+total_buy_amount[i])< 0) {
            txt_color = negative_color;
         } else if ((total_sell_amount[i]+total_buy_amount[i]) == 0){
            txt_color = neutral_color;
         } else {
            txt_color = positive_color;
         }
         ObjectSetText("Gross P/L"+ DoubleToStr(i,0),align_str((total_sell_amount[i]+total_buy_amount[i]), 2), 8, font_str, txt_color);
         ObjectSet("Gross P/L"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("Gross P/L"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_grosspl);
         ObjectSet("Gross P/L"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
         txt_color = neutral_color;
     
         ObjectCreate("Net P/L"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         if ((total_sell_amount[i]+total_buy_amount[i]+commissions[i]+swap[i])< 0) {
            txt_color = negative_color;
         } else if ((total_sell_amount[i]+total_buy_amount[i]+commissions[i]+swap[i]) == 0) {
            txt_color = neutral_color;
         } else {
            txt_color = positive_color;
         }
         ObjectSetText("Net P/L"+ DoubleToStr(i,0),align_str((total_sell_amount[i]+total_buy_amount[i])+commissions[i]+swap[i], 2), 8, font_str, txt_color);
         ObjectSet("Net P/L"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("Net P/L"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_netpl);
         ObjectSet("Net P/L"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
         txt_color = neutral_color;
     
         ObjectCreate("Commissions"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         if (commissions[i] < 0) {
            txt_color = negative_color;
         } else if (commissions[i] == 0) {
            txt_color = neutral_color;
         } else {
            txt_color = positive_color;
         }    
         ObjectSetText("Commissions"+ DoubleToStr(i,0),align_str(commissions[i], 2), 8, font_str, txt_color);
         ObjectSet("Commissions"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("Commissions"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_commissions);
         ObjectSet("Commissions"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
         txt_color = neutral_color;

         ObjectCreate("Swap"+ DoubleToStr(i,0), OBJ_LABEL, window_index, 0, 0);
         if (swap[i] < 0) {
            txt_color = negative_color;
         } else if (swap[i] == 0) {
            txt_color = neutral_color;
         } else {
            txt_color = positive_color;
         }    
         ObjectSetText("Swap"+ DoubleToStr(i,0),align_str(swap[i], 2), 8, font_str, txt_color);
         ObjectSet("Swap"+ DoubleToStr(i,0), OBJPROP_CORNER, 0);
         ObjectSet("Swap"+ DoubleToStr(i,0), OBJPROP_XDISTANCE, col_swap);
         ObjectSet("Swap"+ DoubleToStr(i,0), OBJPROP_YDISTANCE, i*10+14);
         txt_color = neutral_color;
         
      }
   }
}

int start()
{
   window_index = WindowFind(ind_name);
   if (window_index  < 0) {
      Print("could not find indicator window");
      return (-1);
   }

   ObjectsDeleteAll(window_index);
   make_headers();     
   doit();
   displayit(); 

   return(0);
}





Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders


Other Features: