Orders Execution
Checks for the total of open orders
0 Views
0 Downloads
0 Favorites
mp1
//+------------------------------------------------------------------+
//|                                                          MP1.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Distance                                                         |
//+------------------------------------------------------------------+
enum d0
  {
   in_pips,  //in  pips
   in_ticks  //in  ticks 
  };
input d0 Distance=in_pips;
//+------------------------------------------------------------------+
//| List                                                             |
//+------------------------------------------------------------------+
enum d1
  {
   Rating_currency, //Rating  currency
   Rating_distance, //Rating  distance
   Alphabetical     //Alphabetical
  };
input d1 List=Rating_currency;
extern int Shift_points=0;  // Shifts in pixels
extern int Shift_currency   = 0;
extern int Shift_percent    = 0;
extern int Shift_X          = 0;
extern int Shift_Y          = 70;
extern int Density_lines    = 12;
extern int Font_size        = 9;
extern color Color_plus     = MediumSeaGreen;
extern color Color_minus    = Crimson;
double k;
int q=-1;
int r1,r2,r3,r4,type;
string h;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   k=0.125*Font_size;
   r1=Shift_X+(int)(k*5);
   r2=Shift_X+(int)(k*(67+Shift_points));
   r3=Shift_X+(int)(k*(115+Shift_currency));
   r4=Shift_X+(int)(k*(175+Shift_percent));
   if(Distance>0)
     {
      type=MODE_TICKSIZE;
      h="Ticks.";
     }
   else
     {
      type=MODE_POINT;
      h="Pips.";
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   string d,o;
   for(int j=0; j<q+2; j++)
     {
      o=(string)j;
      d="Symbol."+o;
      ObjectDelete(d);
      d=h+o;
      ObjectDelete(d);
      d="Currency."+o;
      ObjectDelete(d);
      d="Percent."+o;
      ObjectDelete(d);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double s=AccountBalance();
   if(s<=0) return(0);
   int z[52],g,i,t,e,n;
   color clr;
   string symbol[52],s1[52],s2[52],s3[52],s4[52],c,f,n1,n2,n3,n4;
   double x[52],x1[52],x2[52],x3[52],pip,cur,pct,y,p,l;
   y=100/s;
//----
   for(i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      n=OrderType();
      if(n>OP_SELL) continue;
      p=OrderProfit()+OrderCommission()+OrderSwap();
      c=OrderSymbol();
      f=c;
      cur+=p;
      pct+=y*p;
      l=MarketInfo(c,type);
      if(l>0)
        {
         if(n==OP_BUY)
            s=(MarketInfo(c,MODE_BID)-OrderOpenPrice())/l;
         else
            s=(OrderOpenPrice()-MarketInfo(c,MODE_ASK))/l;
         pip+=s;
        }
      //----
      for(e=0; e<t; e++)
        {
         if(symbol[e]==f) f="none";
        }
      //----
      if(f!="none")
        {
         symbol[t]=f;
         t++;
        }
      //----
      for(e=0; e<t; e++)
        {
         if(symbol[e]==c)
           {
            z[e]=e;
            s1[e]=c;
            x1[e]+=s;
            s2[e]=DoubleToStr(x1[e],0);
            x2[e]+=p;
            s3[e]=DoubleToStr(x2[e],2);
            x3[e]+=y*p;
            s4[e]=DoubleToStr(x3[e],4)+" %";
            if(List==1)
               x[e]=x1[e];
            else
               x[e]=x2[e];
           }
        }
     }
//----
   if(List<2)
     {
      for(n=0; n<t; n++)
        {
         s=-1000000;
         for(i=n; i<t; i++)
           {
            if(s<x[i])
              {
               s=x[i];
               g=z[i];
               e=i;
              }
           }
         x[e]=x[n];
         x[n]=s;
         z[e]=z[n];
         z[n]=g;
        }
     }
   else
     {
      string b[]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
      n=0;
      for(i=0; i<26; i++)
        {
         for(e=n; e<t; e++)
           {
            f=s1[e];
            g=z[e];
            c=StringSubstr(f,0,1);
            if(c=="#" || c=="6") c=StringSubstr(f,1,1);
            if(b[i]==c)
              {
               s1[e]=s1[n];
               s1[n]=f;
               z[e]=z[n];
               z[n]=g;
               n++;
              }
           }
        }
     }
//----
   symbol[t]="------------------------------------------------------------";
   s2[t]="  ";
   s3[t]="  ";
   s4[t]="  ";
   symbol[t+1]="     "+DoubleToStr(t,0);
   s2[t+1]=DoubleToStr(pip,0);
   s3[t+1]=DoubleToStr(cur,2);
   s4[t+1]=DoubleToStr(pct,4)+" %";
//----
   if(t<q)
     {
      for(i=t; i<q+2; i++)
        {
         c=(string)i;
         f="Symbol."+c;
         ObjectDelete(f);
         f=h+c;
         ObjectDelete(f);
         f="Currency."+c;
         ObjectDelete(f);
         f="Percent."+c;
         ObjectDelete(f);
        }
     }
//----
   for(i=0; i<t+2; i++)
     {
      if(i<t)
        {
         g=z[i];
         if(x2[g]>=0)
            clr=Color_plus;
         else
            clr=Color_minus;
        }
      else
        {
         g=i;
         if(cur>=0)
            clr=Color_plus;
         else
            clr=Color_minus;
        }
      f=(string)i;
      n1="Symbol."+f;
      n2=h+f;
      n3="Currency."+f;
      n4="Percent."+f;
      if(t!=q)
        {
         e=(int)(i*k*Density_lines)+Shift_Y;
         ObjectCreate(n1,OBJ_LABEL,0,0,0,0,0,0,0);
         ObjectSet(n1,OBJPROP_XDISTANCE,r1);
         ObjectSet(n1,OBJPROP_YDISTANCE,e);
         ObjectSet(n1,OBJPROP_SELECTABLE,false);
         ObjectCreate(n2,OBJ_LABEL,0,0,0,0,0,0,0);
         ObjectSet(n2,OBJPROP_XDISTANCE,r2);
         ObjectSet(n2,OBJPROP_YDISTANCE,e);
         ObjectSet(n2,OBJPROP_SELECTABLE,false);
         ObjectCreate(n3,OBJ_LABEL,0,0,0,0,0,0,0);
         ObjectSet(n3,OBJPROP_XDISTANCE,r3);
         ObjectSet(n3,OBJPROP_YDISTANCE,e);
         ObjectSet(n3,OBJPROP_SELECTABLE,false);
         ObjectCreate(n4,OBJ_LABEL,0,0,0,0,0,0,0);
         ObjectSet(n4,OBJPROP_XDISTANCE,r4);
         ObjectSet(n4,OBJPROP_YDISTANCE,e);
         ObjectSet(n4,OBJPROP_SELECTABLE,false);
        }
      ObjectSetText(n1,symbol[g],Font_size,"Arial",clr);
      ObjectSetText(n2,s2[g],Font_size,"Arial",clr);
      ObjectSetText(n3,s3[g],Font_size,"Arial",clr);
      ObjectSetText(n4,s4[g],Font_size,"Arial",clr);
     }
   q=t;
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---