Looking for an elegant way to record some trade data

 

Hi all,


I'm looking to find a good way to record some extra data for my trading journal. Since I'm scalping, it would be a lot of work to do everything by hand. I already have an EA that helps me manage my trades and I'd like to add those functions to it. Any hint is much appreciated, I'm a bit lost in the details here.

(Boundary conditions: There is always only one open trade on one instrument and the code is running on only one chart)


-For any given trade, I'd like to record the maximum drawdown and maximum profit. Write the ticket number and maxDD and maxProf. to a text or csv file. (if I close a trade with 50 points profit but it was in the red by 300 points, that's something I want to show up in my journal)


Attached, you'll find my try so far: [this is in OnTick() ]

-Additionally, I'd like to record some statistics about active vs passive management. For any trade, I'd like to save the initial TP and SL values and write a note into the text/csv file, once one of them has been reached. For example, I might close my trade early and a few bars later, my initial TP is hit. I'm unsure how to keep track of everything here...

Thanks a lot & kind regards!

//Following section: Select order and try to record ticket number, maxDD and max Profit for use in the trading journal...
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(ticket != OrderTicket())                  //If the ticket number has changed, we know that there is a new trade and can log the old ticket and DD and maxProfit values
        {
         
         string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
         string filename     = string(ticket)+".txt";
         int fileHandle      ;
         fileHandle     =    FileOpen(filename, FILE_READ|FILE_WRITE|FILE_TXT);
         FileWriteString(fileHandle,"TicketNumber: "+ string(ticket)+ "MaxProfit: "+string(max_Profit)+ "MaxDrawdown: "+string(max_DD)+"\r\n");
         FileClose(fileHandle);
         
         max_Profit=0;
         max_DD=0;
        }

      ticket = OrderTicket();

      if(OrderProfit()>max_Profit)
         max_Profit=OrderProfit();

      if(OrderProfit()<max_DD)
         max_DD=OrderProfit();


     }
//End of logging section...
 
Pertechnetat:

-Additionally, I'd like to record some statistics about active vs passive management. For any trade, I'd like to save the initial TP and SL values and write a note into the text/csv file, once one of them has been reached. 

Search for "native handling of SQL Databases in MQL5".
You can make an array of a structure containing all the trade information and save it to a database table. Later on you can export parts of it selectively by date and symbol to csv files/excel.
It will take some work but is very versatile in the long run.
 
pennyhunter #:
Search for "native handling of SQL Databases in MQL5".
You can make an array of a structure containing all the trade information and save it to a database table. Later on you can export parts of it selectively by date and symbol to csv files/excel.
It will take some work but is very versatile in the long run.
Thanks a lot, that's a good idea! Outsource as much as possible into the database and worry about it later. Since I'm using Edgewonk as the journal, I can tackle all problems at once by auto-generating all the inputs directly in their required format. Although I feel like I have just opened a can of worms here... :D Thanks again!
 
in data usage?
 
Sulai777 #:
in data usage?
No, in usage of my time :D. Getting up to speed in mySql and refreshing everything will certainly take it's time. But hey, that's what you get when you scalp the 15 second chart and want to throw a whole bunch of math at the resuls...
 
Pertechnetat #:
No, in usage of my time :D. Getting up to speed in mySql and refreshing everything will certainly take it's time. But hey, that's what you get when you scalp the 15 second chart and want to throw a whole bunch of math at the resuls...
I like the way you are thinking. I doubt there is a way to get rich quick here. Don't want to discourage you, the MQL5 thing is a great journey but it is really can after can after can after can. So wiggle your way in.
 
pennyhunter #:
I like the way you are thinking. I doubt there is a way to get rich quick here. Don't want to discourage you, the MQL5 thing is a great journey but it is really can after can after can after can. So wiggle your way in.

Thanks, yes I know. I've now been in this game for like 5 years. I'm already profitable in investing, but not in trading. Scalping just fits my personality and I know that a strategy has to be right for oneself. But I've come far enough to know how to proceed in developing an own idea. The recent can of worms got opened when I decided that I wanted to use Edgewonk to track the scalping results... Excel does not cut it anymore.

 

I actually somewhat solved the problem by simply writing the current maxDD and current maxProfit to the file constantly. That way, I don't have to do all the houskeeping once the trade is closed. As long as the trade is open, the info is logged into the file. Once the trade is closed, the last value has long been written and the variables are reset.


Of course, that does not solve my other problem, but it has given me the idea of using code-based hidden alerts for tracking, if a SL or TP would have been hit. For example, I might have simple if-statements that constantly check, if the price has reached value x.If that happens, a simple remark is appended to the already existing log.


Also, I got the idea that I don't HAVE to use MT for all the formatting and database creation. I'm pretty up to speed with using python for databases. I don't mind reading in all the log-files and then auto-generating the .csv file that is used for uploading to Edgewonk.

 
Pertechnetat #:

Also, I got the idea that I don't HAVE to use MT for all the formatting and database creation. I'm pretty up to speed with using python for databases. I don't mind reading in all the log-files and then auto-generating the .csv file that is used for uploading to Edgewonk.


Oh good which reminds me to look into MQL Python integration at some point. I see there is only little material in articles and I hope it is good.