GetHistory

This tool is designed to automatically archive your trading history into a structured spreadsheet format. It acts as a background logger that captures every completed trade and saves it to a local file on your computer, ensuring you have a permanent record of your performance outside of the trading platform.

How It Works

The script operates based on a time-sensitive trigger. Instead of constantly rewriting files or running unnecessarily, it monitors the clock. Specifically, it waits until a new minute begins before performing any actions. This ensures that the log is updated systematically without taxing your computer's resources.

The Process

Once the software detects a change in the minute, it executes the following steps:

  • File Creation: It generates a dedicated spreadsheet file named OrdersReport.csv.
  • Data Organization: The script automatically sets up a header row at the top of this file. This ensures that your data is organized into clear columns, including essential information such as the trade number, opening/closing times, order types, volume (lots), currency symbols, entry and exit prices, stop-loss/take-profit levels, total profit, and any specific comments you may have added.
  • History Retrieval: The tool then scans your entire trading history. It looks for every completed transaction you have made in the past.
  • Data Extraction: For every trade found, it pulls the specific details and writes them line-by-line into the CSV file.
  • Saving and Closing: Once all historical data has been transferred to the file, it safely closes the document to prevent data corruption.

Key Benefits

Because this script handles the "heavy lifting" of data collection, you don't have to manually export your history or copy-paste figures into a spreadsheet. Every time the minute rolls over, you can rely on the fact that your most up-to-date trading statistics are being compiled and saved into a clean, readable format ready for analysis.

Price Data Components
Series array that contains open time of each bar
Miscellaneous
Uses files from the file systemIt writes information to file
11 Views
0 Downloads
0 Favorites
GetHistory
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

static int mPrev;
int m;

int init()
  {
   mPrev=Minute();
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int i,handle,hstTotal=HistoryTotal();
   m=Minute();
   if(m!=mPrev)
      {
      mPrev=m;
      handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,",");
      if(handle<0) return(0);
      FileWrite(handle,"#,Open Time,Type,Lots,Symbol,Price,Stop/Loss,Take Profit,Close Time,Close Price,Profit,Comment");
      for(i=0;i<hstTotal;i++)
         {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
            {
            FileWrite(handle,OrderTicket(),TimeToStr(OrderOpenTime(),TIME_DATE|TIME_MINUTES),OrderType(),OrderLots(),OrderSymbol(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit(),TimeToStr(OrderCloseTime(),TIME_DATE|TIME_MINUTES),OrderClosePrice(),OrderProfit(),OrderComment());
            }
         }
      FileClose(handle);
      }
   return(0);
  }
//+------------------------------------------------------------------+

Comments