VR Orders History Lite

Orders Execution
Checks for the total of closed orders
Miscellaneous
Uses files from the file systemIt writes information to file
0 Views
0 Downloads
0 Favorites
VR Orders History Lite
ÿþ//+==================================================================|//

//|                      VR Orders History Lite.mq4                  |//

//|               Copyright 2017, Trading-Go Project.                |//

//| Author: Voldemar, Version: 15.12.2017, Site http://trading-go.ru |//

//|==================================================================|//

//|Full version MetaTrader 4 https://www.mql5.com/ru/market/product/5635

//|Full version MetaTrader 5 https://www.mql5.com/ru/market/product/5635

//|==================================================================|//

#property script_show_inputs

#property strict

//|==================================================================|//

enum sp

  {

   One, // Comma    0 , 0000

   Two  // Point    0 . 0000

  };

//|==================================================================|//

//|                                                                  |//

//|==================================================================|//

enum type

  {

   all,           // All types of orders

   op_buy,        // Buy

   op_sel,        // Sell

   op_buy_limit,  // Buy limit

   op_sel_limit,  // Sell limit

   op_buy_stop,   // Buy stop

   op_sel_stop,   // Sell stop

   deposit,       // Deposit

   only_market,   // Only market orders

   only_stop,     // Only stop orders

   only_limit     // Only limit orders

  };

//|==================================================================|//

//|                                                                  |//

//|==================================================================|//  

struct ord

  {

   string            number;          // The number in the list 

   string            ticket;          // The ticket, Ardea

   string            symbol;          // The symbol of the order

   string            cmd;             // Trading orders

   string            volume;          // The number of lots 

   string            op_price;        // The order open price 

   string            cl_price;        // Closing price orders 

   string            op_time;         // Time order open 

   string            cl_time;         // Closing orders 

   string            stoploss;        // A stop Loss order 

   string            takeprofit;      // Take Profit orders   

   string            profit;          // Order profit

   string            comment;         // Review order 

   string            magic;           // Order magic number

   string            swap;            // Swap order

   string            comission;       // The Commission orders

   double            point;           // 0.0001 or 0.00001

   double            digits;          // The number of digits after the decimal point

  };

ord order[];

//|==================================================================|//

//|                                                                  |//

//|==================================================================|//  

input  string                    I                 = "Separator";         // I

input  sp                        sep               = One;                           // Separator (Comma or Point)

input  string                    II                = "Filter";                      // II

input  type                      Type              = all;                           // Type of orders (Buy, Sell ... All orders)

input  string                    Symbols           = "";                            // Symbol

input  int                       MagicNumber       = 0;                             // Magic Number

input  datetime                  StartTime         = D'01.01.1980 00:00:00';        // Start time 

input  datetime                  StopTime          = D'01.01.2030 00:00:00';        // Time of the end

//+---

//|==================================================================|//

//|                                                                  |//

//|==================================================================|//

void OnStart()

  {

// ===

   Comment("");

// ===

   int k=0,tk=0,ty=0,ma=0,dt=0;

   double lt=0,op=0,cl=0,sl=0,tp=0,sw=0,cm=0,pr=0,pt=0;

   string sy="",co="",InpFileName="";

   datetime ot=0,ct=0;

// ===

   Print("Script started");

   InpFileName=IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" "+AccountInfoString(ACCOUNT_NAME)+" ["+TimeToString(TimeLocal(),TIME_DATE|TIME_SECONDS)+"].csv";

   StringReplace(InpFileName,":","-");

// ===

   if(FileGetInteger(InpFileName,FILE_EXISTS))

      FileDelete(InpFileName);



// ===

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

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

         if(

            (Type==all)                                              ||

            (Type==op_buy        && OrderType()==OP_BUY)              ||

            (Type==op_sel        && OrderType()==OP_SELL)             ||

            (Type==op_buy_limit  && OrderType()==OP_BUYLIMIT)         ||

            (Type==op_sel_limit  && OrderType()==OP_SELLLIMIT)        ||

            (Type==op_buy_stop   && OrderType()==OP_BUYSTOP)          ||

            (Type==op_sel_stop   && OrderType()==OP_SELLSTOP)         ||

            (Type==deposit       && OrderType()>=6)                   ||

            (Type==only_market   && OrderType()<2)                    ||

            (Type==only_limit    && OrderType()>=2 && OrderType()<=3) ||

            (Type==only_stop     && OrderType()>=4 && OrderType()<=5)

            )

            if(OrderOpenTime()>=StartTime && OrderOpenTime()<=StopTime)

               if(OrderMagicNumber()==MagicNumber || MagicNumber==-1)

                  if((OrderSymbol()==Symbols) || (Symbols=="") || (Symbols==" ") || (Symbols==NULL))

                    {

                     tk = OrderTicket();

                     sy = OrderSymbol();

                     ty = OrderType();

                     lt = OrderLots();

                     op = OrderOpenPrice();

                     cl = OrderClosePrice();

                     ot = OrderOpenTime();

                     ct = OrderCloseTime();

                     sl = OrderStopLoss();

                     tp = OrderTakeProfit();

                     co = OrderComment();

                     ma = OrderMagicNumber();

                     sw = OrderSwap();

                     cm = OrderCommission();

                     pr = OrderProfit();

                     // ===

                     dt = (int)SymbolInfoInteger(sy,SYMBOL_DIGITS);

                     pt = SymbolInfoDouble(sy,SYMBOL_POINT);

                     if(pt==0)pt=1;

                     Print("Added Ticket "+IntegerToString(tk));



                     ArrayResize(order,k+1,10000);



                     order[k].ticket     = IntegerToString(tk);     

                     order[k].symbol     = sy;                      

                     order[k].cmd        = order_type(ty);          

                     order[k].volume     = DoubleToStr(lt,2);      

                     order[k].op_price   = DoubleToStr(op,dt);    

                     order[k].cl_price   = DoubleToStr(cl,dt);    

                     order[k].op_time    = TimeToStr(ot,TIME_DATE|TIME_SECONDS);        

                     order[k].cl_time    = TimeToStr(ct,TIME_DATE|TIME_SECONDS);       

                     order[k].comment    = co;                                          

                     order[k].magic      = IntegerToString(ma);                       

                     order[k].swap       = DoubleToStr(sw,2);                

                     order[k].comission  = DoubleToStr(cm,2);                 

                     order[k].number     = IntegerToString((i+1));           



                     if(ty==OP_BUY)

                       {

                        order[k].stoploss         = DoubleToStr(sl,dt);             

                        order[k].takeprofit       = DoubleToStr(tp,dt);           

                        order[k].profit           = DoubleToStr(pr,2);              

                       }



                     if(ty==OP_SELL)

                       {

                        order[k].stoploss         = DoubleToStr(sl,dt);             

                        order[k].takeprofit       = DoubleToStr(tp,dt);             

                        order[k].profit           = DoubleToStr(pr,2);        

                       }



                     if(ty>1)

                       {

                        order[k].profit           = "0";                    

                        order[k].stoploss         = DoubleToStr(sl,dt);           

                        order[k].takeprofit       = DoubleToStr(tp,dt);                              

                       }

                     k++;

                    }

     }

// ===

   string line="",separator=";";

   int file_handle=FileOpen("App Data Trading-Go"+"\\"+MQLInfoString(MQL_PROGRAM_NAME)+"\\"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV);

   if(file_handle!=INVALID_HANDLE)

     {



      FileWrite(

                file_handle,

                /* 1  */"N"                            +separator+//

                /* 2  */"Order Ticket"                 +separator+//

                /* 3  */"Order Symbol"                 +separator+// 

                /* 4  */"Order Type"                   +separator+//

                /* 5  */"Order Lot"                    +separator+// 

                /* 6  */"Order Open Price"             +separator+//

                /* 7  */"Order Close Price"            +separator+//

                /* 8  */"Order Open Time"              +separator+// 

                /* 9  */"Order Close Time"             +separator+//

                /* 10 */"Order Stop Loss"              +separator+//

                /* 11 */"Order Take Profit"            +separator+//

                /* 12 */"Order Profit"                 +separator+//

                /* 13 */"Order Swap "                  +separator+//

                /* 14 */"Order Comission"              +separator+//

                /* 15 */"Order Comment"                +separator+//

                /* 16 */"Order Magic Number"           +separator//

                );



      for(int z=ArraySize(order)-1;z>=0;z--)

        {

         StringReplace(order[z].volume,      sep==One?".":",",sep==One?",":".");

         StringReplace(order[z].op_price,    sep==One?".":",",sep==One?",":".");

         StringReplace(order[z].cl_price,    sep==One?".":",",sep==One?",":".");

         StringReplace(order[z].profit,      sep==One?".":",",sep==One?",":".");

         StringReplace(order[z].stoploss,    sep==One?".":",",sep==One?",":".");

         StringReplace(order[z].takeprofit,  sep==One?".":",",sep==One?",":".");

         StringReplace(order[z].swap,        sep==One?".":",",sep==One?",":".");

         StringReplace(order[z].comission,   sep==One?".":",",sep==One?",":".");



         FileWrite(

                   file_handle,

                   /* 1  */order[z].number          +separator +//

                   /* 2  */order[z].ticket          +separator +//

                   /* 3  */order[z].symbol          +separator +//

                   /* 4  */order[z].cmd             +separator +//

                   /* 5  */order[z].volume          +separator +//

                   /* 6  */order[z].op_price        +separator +//

                   /* 7  */order[z].cl_price        +separator +//

                   /* 8  */order[z].op_time         +separator +// 

                   /* 9  */order[z].cl_time         +separator +//

                   /* 10 */order[z].stoploss        +separator +//

                   /* 11 */order[z].takeprofit      +separator +//

                   /* 12 */order[z].profit          +separator +//

                   /* 13 */order[z].swap            +separator +//

                   /* 14 */order[z].comission       +separator +//

                   /* 15 */order[z].comment         +separator +//

                   /* 16 */order[z].magic           +separator  //

                   );

        }

     }

   else

      Print(GetLastError());



// === 

   FileClose(file_handle);

// =============

   Print("Script finished work");

  }

//|==================================================================|//

//|                                                                  |//

//|==================================================================|//

string order_type(int aType)

  {

   string value="";

   switch(aType)

     {

      case 0: value = "Buy";        break;

      case 1: value = "Sell";       break;

      case 2: value = "Buy limit";  break;

      case 3: value = "Sell limit"; break;

      case 4: value = "Buy stop";   break;

      case 5: value = "Sell stop";  break;

      case 6: value = "Deposit";    break;

     }

   return value;

  }

//|==================================================================|//

//|                                                                  |//

//|==================================================================|//

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