Author: Lucik, 27.03.2024
Orders Execution
Checks for the total of closed ordersChecks for the total of open orders
0 Views
0 Downloads
0 Favorites
DrawOrders
ÿþ//+------------------------------------------------------------------+

//|                                                   DrawOrders.mq4 |

//|                                                      Lucik, 2024 |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Lucik, 27.03.2024"

#property version   "2.0"

#property link      "https://www.mql5.com/ru/users/lucik"

#property description " 8AC5< >@45@0 =0 3@0D8:5"

#property strict

#property indicator_chart_window



//---FilterSettings

extern string  FilterSettings="--- 0AB@>9:8 D8;LB@0F88 >@45@>2 ---";//--- 0AB@>9:8 D8;LB@0F88 >@45@>2 ---

extern string Comment1                 ="";                //1-K9 :><<5=B0@89

extern string Comment2                 ="";                //2->9 :><<5=B0@89

extern int    Magic1                   =0;                 //1-K9 Magic 4;O D8;LB@0F88 A>25B=8:>2

extern int    Magic2                   =0;                 //2->9 Magic 4;O D8;LB@0F88 A>25B=8:>2

//---CommonSettings

extern string  CommonSettings="--- 1I85 =0AB@>9:8 >@45@>2 ---";//--- 1I85 =0AB@>9:8 ---

extern int    max_history_orders       =20;                //0:A8<C< >@45@>2 8AB>@88

extern int    max_current_orders       =20;                //0:A8<C< B5:CI8E >B:@KBKE >@45@>2

extern int    lineswidth               =2;                 //">;I8=0 ;8=89

extern int    FontSize                 =15;                // 07<5@ H@8DB0 AB@5;>:

extern string arrowclose_UnicodeChar   ="" ";               //C8<2>; Unicode AB@5;:8 70:@KB8O (U+00B7)

extern string info                     ="5 2A5 A8<2>;K Unicode >B>1@060NBAO =0 3@0D8:5!"; //5 2A5 A8<2>;K Unicode >B>1@060NBAO =0 3@0D8:5!

extern string info2                    ="<5AB> =5:>B>@KE A8<2>;>2 >B>1@0605BAO '?'"; //<5AB> =5:>B>@KE A8<2>;>2 >B>1@0605BAO '?'

//---ArrowLong

extern string  ArrowsLong="--- 0AB@>9:0 AB@5;:8 >B:@KB8O Long ---";//--- 0AB@>9:0 AB@5;:8 >B:@KB8O Long ---

extern string arrowlong_UnicodeChar    ="" ";               //C8<2>; Unicode >B:@KB8O Long (U+00B7)

string arrowlonglabel                  ="ArrowLong";

extern color arrowlong_color           =clrBlue;           //&25B A8<2>;0 >B:@KB8O Long

//---LineLong

extern string  LinesLong="--- 0AB@>9:0 ;8=88 Long ---";   //--- 0AB@>9:0 ;8=88 Long ---

string linelonglabel                   ="LineLong";

extern color linelong_color            =clrBlue;           //&25B ;8=88 Long

extern ENUM_LINE_STYLE linelong_style  =STYLE_SOLID;       //!B8;L ;8=88 Long

//---ArrowShort

extern string  ArrowsShort="--- 0AB@>9:0 AB@5;:8 >B:@KB8O Short ---";//--- 0AB@>9:0 AB@5;:8 >B:@KB8O Short ---

extern string arrowshort_UnicodeChar   ="" ";               //C8<2>; Unicode >B:@KB8O Short (U+00B7)

string arrowshortlabel                 ="ArrowShort";

extern color arrowshort_color          =clrYellow;         //&25B A8<2>;0 >B:@KB8O Short

//---LineShort

extern string  LinesShort="--- 0AB@>9:0 ;8=88 Short ---"; //--- 0AB@>9:0 ;8=88 Short ---

string lineshortlabel                   ="LineShort";

extern color lineshort_color            =clrYellow;        //&25B ;8=88 >B:@KB8O Short

extern ENUM_LINE_STYLE lineshort_style  =STYLE_SOLID;      //!B8;L ;8=88 Short



string object_tooltip;

//+------------------------------------------------------------------+

int OnInit()

  {

//   Print("Orders in History on this account: ",OrdersHistoryTotal());

//   Print("Active orders on this account: ",OrdersTotal());

   ObjectsDeleteAll(0,arrowlonglabel);

   ObjectsDeleteAll(0,arrowshortlabel);

   ObjectsDeleteAll(0,linelonglabel);

   ObjectsDeleteAll(0,lineshortlabel);

   Print(SymbolInfoDouble(NULL,SYMBOL_TRADE_TICK_VALUE),"  ",MarketInfo(NULL,MODE_TICKVALUE));

   

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

   ObjectsDeleteAll(0,arrowlonglabel);

   ObjectsDeleteAll(0,arrowshortlabel);

   ObjectsDeleteAll(0,linelonglabel);

   ObjectsDeleteAll(0,lineshortlabel);

  }



//+------------------------------------------------------------------+

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[])

  {

//--------8AB>@8O

      int history_count=1;

      for(int i=OrdersHistoryTotal(); i>=0; i--)

         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

            if(OrderSymbol()==_Symbol)

              {

               if(history_count>max_history_orders) break;

               history_count++;

               

               string truecondition="not";

               string truemagiccondition="not";



               if(Comment1!="" && OrderComment()==Comment1 && Comment2=="")

                  truecondition="firstonly";

               if(Comment1!="" && OrderComment()==Comment1 && Comment2!="")

                  truecondition="first";

               if(Comment2!="" && OrderComment()==Comment2 && Comment1=="")

                  truecondition="secondonly";

               if(Comment2!="" && OrderComment()==Comment2 && Comment1!="")

                  truecondition="second";

               if(Comment1=="" && Comment2=="")

                  truecondition="none";



               if(Magic1!=0 && OrderMagicNumber()==Magic1 && Magic2==0)

                  truemagiccondition="firstonly";

               if(Magic1!=0 && OrderMagicNumber()==Magic1 && Magic2!=0)

                  truemagiccondition="first";

               if(Magic2!=0 && OrderMagicNumber()==Magic2 && Magic1==0)

                  truemagiccondition="secondonly";

               if(Magic2!=0 && OrderMagicNumber()==Magic2 && Magic1!=0)

                  truemagiccondition="second";

               if(Magic1==0 && Magic2==0)

                  truemagiccondition="none";



               if(truecondition!="not" && truemagiccondition!="not")

                 {

                  object_tooltip="Order "+string(OrderTicket())

                            +"\r\nProfit "+string(OrderProfit()+OrderSwap()+OrderCommission())+" "+AccountInfoString(ACCOUNT_CURRENCY);



                  DrawArrow("ArrowOpen");

                  DrawLine();

                  DrawArrow("ArrowClose");

                 }

              }

//--------B5:CI85

      int opened_count=1;

      for(int i=OrdersTotal(); i>=0; i--)

         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

            if(OrderSymbol()==Symbol())

              {

               if(opened_count>max_current_orders) break;

               opened_count++;

               

               string truecondition="not";

               string truemagiccondition="not";



               if(Comment1!="" && OrderComment()==Comment1 && Comment2=="")

                  truecondition="firstonly";

               if(Comment1!="" && OrderComment()==Comment1 && Comment2!="")

                  truecondition="first";

               if(Comment2!="" && OrderComment()==Comment2 && Comment1=="")

                  truecondition="secondonly";

               if(Comment2!="" && OrderComment()==Comment2 && Comment1!="")

                  truecondition="second";

               if(Comment1=="" && Comment2=="")

                  truecondition="none";



               if(Magic1!=0 && OrderMagicNumber()==Magic1 && Magic2==0)

                  truemagiccondition="firstonly";

               if(Magic1!=0 && OrderMagicNumber()==Magic1 && Magic2!=0)

                  truemagiccondition="first";

               if(Magic2!=0 && OrderMagicNumber()==Magic2 && Magic1==0)

                  truemagiccondition="secondonly";

               if(Magic2!=0 && OrderMagicNumber()==Magic2 && Magic1!=0)

                  truemagiccondition="second";

               if(Magic1==0 && Magic2==0)

                  truemagiccondition="none";



               if(truecondition!="not" && truemagiccondition!="not")

                 {

                  object_tooltip="Order "+string(OrderTicket())

                            +"\r\nProfit "+string(OrderProfit()+OrderSwap()+OrderCommission())+" "+AccountInfoString(ACCOUNT_CURRENCY);

                  DrawArrow("ArrowOpen");

                 }

              }



   return(rates_total);

  }

//+------------------------------------------------------------------+

void DrawArrow(string arrow_type)

  {

   bool              back=false;           // =0 704=5< ?;0=5

   bool              selection=false;      // 2K45;8BL 4;O ?5@5<5I5=89

   bool              hidden=false;         // A:@KB 2 A?8A:5 >1J5:B>2

   long              z_order=0;            // ?@8>@8B5B =0 =060B85 <KHLN

   datetime          time=TimeCurrent();

   double            price=(Ask+Bid)/2;

   string            arrowcode;

   string            object_name="Arrow";

   color             object_color=clrWhiteSmoke;



   if(arrow_type=="ArrowOpen")

     {

      time=OrderOpenTime();

      price=OrderOpenPrice();

      if(OrderType()==OP_BUY)

        {

         arrowcode=arrowlong_UnicodeChar;

         object_name=arrowlonglabel+"Open"+string(OrderTicket());

         object_color=arrowlong_color;

        }

      if(OrderType()==OP_SELL)

        {

         arrowcode=arrowshort_UnicodeChar;

         object_name=arrowshortlabel+"Open"+string(OrderTicket());

         object_color=arrowshort_color;

        }

     }

   if(arrow_type=="ArrowClose")

     {

      time=OrderCloseTime();

      price=OrderClosePrice();

      arrowcode=arrowclose_UnicodeChar;

      if(OrderType()==OP_BUY)

         {

          object_name=arrowlonglabel+"Close"+string(OrderTicket());

          object_color=arrowlong_color;

         }

      if(OrderType()==OP_SELL)

         {

          object_name=arrowshortlabel+"Close"+string(OrderTicket());

          object_color=arrowshort_color;

         }

      if(time==0)

         return;

     }

   

   if(ObjectFind(object_name)==-1)

      ObjectCreate(0,object_name,OBJ_TEXT,0,time,price);



   ObjectSetString(0,object_name,OBJPROP_TEXT,arrowcode);

   ObjectSetInteger(0,object_name,OBJPROP_FONTSIZE,FontSize);

   ObjectSetInteger(0,object_name,OBJPROP_COLOR,object_color);

   ObjectSetString(0,object_name,OBJPROP_TOOLTIP,object_tooltip);

   ObjectSetInteger(0,object_name,OBJPROP_ANCHOR,ANCHOR_CENTER);

   ObjectSetInteger(0,object_name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(0,object_name,OBJPROP_BACK,back);



   ChartRedraw();

  }

//+------------------------------------------------------------------+

void DrawLine()

  {

   bool            back=false;        // 8=8O =0 704=5< ?;0=5

   bool            selection=false;   // K45;8BL 4;O ?5@5<5I5=89

   bool            ray_right=false;   // @>4>;65=85 ;8=88 2?@02>

   bool            hidden=false;      // !:@KB 2 A?8A:5 >1J5:B>2

   long            z_order=0;         // @8>@8B5B =0 =060B85 <KHLN

   string          object_name="Line";

   color           object_color=clrWhiteSmoke;



   if(OrderType()==OP_BUY)

     {

      object_name=linelonglabel+string(OrderTicket());

      object_color=linelong_color;

     }

   if(OrderType()==OP_SELL)

     {

      object_name=lineshortlabel+string(OrderTicket());

      object_color=lineshort_color;

     }

      

   if(ObjectFind(object_name)==-1)

      ObjectCreate(0,object_name,OBJ_TREND,0,OrderOpenTime(),OrderOpenPrice(),OrderCloseTime(),OrderClosePrice());



   ObjectSetInteger(0,object_name,OBJPROP_COLOR,object_color);

   ObjectSetInteger(0,object_name,OBJPROP_WIDTH,lineswidth);

   ObjectSetInteger(0,object_name,OBJPROP_STYLE,linelong_style);



   ObjectSetString(0,object_name,OBJPROP_TOOLTIP,object_tooltip);

   ObjectSetInteger(0,object_name,OBJPROP_BACK,back);

   ObjectSetInteger(0,object_name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(0,object_name,OBJPROP_SELECTED,selection);

   ObjectSetInteger(0,object_name,OBJPROP_RAY_RIGHT,ray_right);

   ObjectSetInteger(0,object_name,OBJPROP_HIDDEN,hidden);

   ObjectSetInteger(0,object_name,OBJPROP_ZORDER,z_order);

  }

//+------------------------------------------------------------------+

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 ---