This should be a script - Account History EA

Ickyrus
893
Ickyrus  

Wrote this EA as learning exercise - would need refining in the file already open and file alrady exists error code department but for now serves a simple and hopfully useful purpose.

Perhaps if a Moderator thinks it worthy of being added to the code base they could do so as I am not confident enough to do so.

//+------------------------------------------------------------------+
//|                                                      AccHist.mq4 |
//|                                                           Marcus |
//|                                            andrewqaz@hotmail.com |
//|                                                                  |
//|  Creates account history CSV file \experts\files                 |
//+------------------------------------------------------------------+

#include <WinUser32.mqh> //add if using comitsuicide

#property copyright "Marcus Meldrum - freeware"
#property link      "andrewqaz@hotmail.com"
extern string FileName="AcctHist.CSV" ;

int handle ;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
  handle=FileOpen("myaccthist.csv",FILE_CSV|FILE_WRITE,",");   
  if(handle>0)
    {
     Print("History total",OrdersHistoryTotal() ) ;
     FileWrite(handle, "Ticket","Magic","OTime","Type","Lots","Symbol","OPrice","S/L","T/P","CTime","CPrice","Swap","Profit","Comment");     
     for(int i=0;i<OrdersHistoryTotal();i++)
      {       
       OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) ;
       FileWrite(
         handle,
         OrderTicket(),                //int
         OrderMagicNumber(),           //int
         TimeToStr(OrderOpenTime()),   //datetime
         oType2str(OrderType()),       //int
         OrderLots(),                  //double
         OrderSymbol(),                //string
         OrderOpenPrice(),             //double
         OrderStopLoss(),              //double
         OrderTakeProfit(),            //double
         TimeToStr(OrderCloseTime()),  //int
         OrderClosePrice(),            //double
         OrderSwap(),                  //double
         OrderProfit(),                //double
         OrderComment()                //string         
        ) ; //end file write
      } //end for
     FileClose(handle);
     Alert("FileWrite Done") ; 
     commitSuicide() ;
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+
/////////////////////////    
void commitSuicide() //Don't forget to use #include <WinUser32.mqh> for this function
{
  int h = WindowHandle(Symbol(), Period());
  if (h != 0) PostMessageA(h, WM_COMMAND, 33050, 0);
}
///////////
string oType2str(int type)
{
switch (type)
  {
   case OP_BUY : return("Buy") ;// - buying position,
   case OP_SELL : return("Sell") ; //- selling position,
   case OP_BUYLIMIT : return("Buy Limit") ; //- buy limit pending position,
   case OP_BUYSTOP : return("Buy Stop") ; //- buy stop pending position,
   case OP_SELLLIMIT : return("Sell Limit") ; //- sell limit pending position,
   case OP_SELLSTOP : return("Sell Stop") ; //- sell stop pending position.
  }
} //end oType2str
///////////////
Files:
acchist.mq4  3 kb
gordon
2327
gordon  
Ickyrus:

Wrote this EA as learning exercise - would need refining in the file already open and file alrady exists error code department but for now serves a simple and hopfully useful purpose.

There are 2 undocumented order types that should be included -> https://www.mql5.com/en/forum/122847 and you should use DoubleToStr() with proper number of digits, or prices will be cut off for 5 digit brokers...

Ickyrus
893
Ickyrus  

Hmm could use DoubleToStr(OrderTakeProfit(),Digits) perhaps
-
Also add magicnumber filter and timefilter but you can do that 'playing' easily and quickly in a spreadsheet.
-
Not too sure on how to process the possible file errors and would be more convienient to use the non-mlq file operations for user choice of where the file is saved default would be "My Documents"
-
Maybe later.

[Deleted]  
gordon wrote >>

There are 2 undocumented order types that should be included -> https://www.mql5.com/en/forum/122847 and you should use DoubleToStr() with proper number of digits, or prices will be cut off for 5 digit brokers...



gordon you've probably seen those two order types in your history for your live account's (they are used by the broker) - "balance" when opening a new account and setting the initial deposit funds and credit when they need to "fix" a bad trade or adjust the account's balance for expenses/credits that aren't assessed on a per-trade basis (such as monthly account management fees, etc).

gordon
2327
gordon  
1005phillip:



gordon you've probably seen those two order types in your history for your live account's (they are used by the broker) - "balance" when opening a new account and setting the initial deposit funds and credit when they need to "fix" a bad trade or adjust the account's balance for expenses/credits that aren't assessed on a per-trade basis (such as monthly account management fees, etc).

I know... I am just saying that the above EA doesn't take that into account. The function oType2Str() (in the code above) only takes the basic 6 order types into consideration, ignoring balance and credit statements (which are considered an 'order' when selecting from the history pool).

Ickyrus
893
Ickyrus  

I think gordon is right as the idea is to print out what the user sees in their account history.

[Deleted]  
Ickyrus wrote >>

I think gordon is right as the idea is to print out what the user sees in their account history.


I was more just trying to answer one of the questions (or my interpretation of the premise of his first question) posed by gordon in the thread he linked perchance he had not encountered the explanation (his thread was old and I wasn't sure if it would be relevant to post my response in his old thread).

Of course for the relevance of this thread the script needs to account for all 8 order types but it still doesn't address the issue raised in question #3 of gordon's linked thread.

An incomplete order history can be incomplete by way of lacking info regarding the existence of specific order types (addressed by gordon and yourself) as well as by way of lacking the specific order history timespan one intends the script to capture.

On the topic of the OP - what is the intended benefit of the script over that of the existing options to save one's account history via the "Save as Report" or "Save as Detailed Report" options in the pop-up menu when you right-click anywhere in the Account History window?

Ickyrus
893
Ickyrus  
1005phillip wrote >>


I was more just trying to answer one of the questions (or my interpretation of the premise of his first question) posed by gordon in the thread he linked perchance he had not encountered the explanation (his thread was old and I wasn't sure if it would be relevant to post my response in his old thread).

Of course for the relevance of this thread the script needs to account for all 8 order types but it still doesn't address the issue raised in question #3 of gordon's linked thread.

An incomplete order history can be incomplete by way of lacking info regarding the existence of specific order types (addressed by gordon and yourself) as well as by way of lacking the specific order history timespan one intends the script to capture.

On the topic of the OP - what is the intended benefit of the script over that of the existing options to save one's account history via the "Save as Report" or "Save as Detailed Report" options in the pop-up menu when you right-click anywhere in the Account History window?


Well as a CSV I can manipulate it in Excel
I did try and do a save as detailed report and got an html page which said it was an option that my broker was working on as a future feature. I can only seem to save the report in html format which is a tiny bit anoying.
As a CSV I can easily group the magic numbers togeter to get sub-totals and find best performance. Finally I can make monthly reports for the Taxman as proof of where I am getting or not getting my money from.

gordon
2327
gordon  
1005phillip:

... it still doesn't address the issue raised in question #3 of gordon's linked thread.

That's a good point. In the Tester the history pool always includes all history but in Demo/Live it depends on user preferences... Nothing much to do about it though.

Ickyrus, there are some scripts similar in the codebase that might interest you (for educational purposes) -> https://www.mql5.com/en/code/8126 (and there should be others... search).

[Deleted]  
Ickyrus wrote >>


Well as a CSV I can manipulate it in Excel
I did try and do a save as detailed report and got an html page which said it was an option that my broker was working on as a future feature. I can only seem to save the report in html format which is a tiny bit anoying.
As a CSV I can easily group the magic numbers togeter to get sub-totals and find best performance. Finally I can make monthly reports for the Taxman as proof of where I am getting or not getting my money from.


You can manipulate the html output file in Excel as well, just open the file with Excel instead of your web browser.

The detailed report adds a balance/order count graph as well as all the statistical analyses on your account that you are accustomed to seeing in the strategy tester. You aren't missing any trade data details by not having the detailed statement.

I understand your desire to import the info into Excel, I do this as well so I know where you are coming from. FWIW though having personally been thru an IRS tax audit relating to my forex accounting I can tell you that it is the html generated statement that they want/like to see and they could care less about the Excel files. They regarded all my excel files as irrelevant at best and a possible sources of errors/fraud at worst (the auditor said as much as she handed me back my stack of printouts).

Consider the Excel files as more of an internal accounting system which helps you have confidence that you know where your numbers are coming from, but if the IRS ever gets involved in verifying your accounting they are going to want to see those html statements for their own verification process anyways. (btw the IRS found in my favor with the audit)

Ickyrus
893
Ickyrus  

I personally don't like filling my hard drive up with large amounts of extra formatting data. I don't like re-formatting html cell information
to suit my own needs.. Personally if I can keep it simple and without clutter then I know that my processor task
sharing timing is not being eaten into with un-necessary flim-flam. I don't particularaly like having 'artistic' look and feel
forced on me by designers who only think about how good something looks and don't think about or understand practical needs.
My time is wasted waiting for the computer to complete large amounts of processing because of some very bad design ideas.
If you like what you see and don't question it fine. Knowing what could have been is just frustrating. Your lucky if you like what you are given.