Page 2 of 2

Re: The Annual Review: A Structured Look at Twelve Months

Posted: Fri Oct 23, 2026 10:06 pm
by PTScalper
Workflow Integration:

Phone-to-Workstation Sync: Because MT5 synchronizes account history at the broker server level, any trade you open or close on your phone is instantly caught by OnTradeTransaction on the desktop terminal.

Series-Based Archiving: If you let this run unattended on your HP Z2 workstation during your 2 to 6-week trading blocks, you will have a pristine CSV file generated in the MQL5\Files directory exactly when you step away for your recovery weeks.

C# / .NET Expansion: Given your enterprise backend experience, you could replace the FileWrite logic with MQL5's WebRequest to push a JSON payload of the trade directly to a custom ASP.NET Core REST API, permanently storing your scalping data into a local MS SQL or PostgreSQL database.

Re: The Annual Review: A Structured Look at Twelve Months

Posted: Fri Oct 23, 2026 10:07 pm
by PTScalper
In MQL5, datetime variables natively store the number of seconds elapsed since January 1, 1970. Because of this Unix epoch foundation, extracting the exact trade duration in seconds requires only a direct mathematical subtraction of the opening time from the closing time.

For spot scalping on M15 timeframes, capturing precise time-in-market exposure is critical data for your post-series review, revealing exactly how long capital was at risk before hitting the target or stop.

Re: The Annual Review: A Structured Look at Twelve Months

Posted: Fri Oct 23, 2026 10:07 pm
by PTScalper
Here is the complete updated EA. The CSV headers have been modified to include "Duration(s)", and the calculation logic is injected immediately after the open_time is retrieved.

Code: Select all

//+------------------------------------------------------------------+
//|                                            AutoJournaling_EA.mq5 |
//+------------------------------------------------------------------+
#property strict

input string InpFileName = "AutoJournal.csv";

int OnInit()
  {
   // Initialize CSV with headers including Duration(s)
   int file_handle = FileOpen(InpFileName, FILE_CSV|FILE_READ|FILE_WRITE|FILE_ANSI, ",");
   if(file_handle != INVALID_HANDLE)
     {
      if(FileSize(file_handle) == 0)
        {
         FileWrite(file_handle, "DealTicket", "PositionID", "Symbol", "Type", "Volume", "OpenTime", "CloseTime", "Duration(s)", "OpenPrice", "ClosePrice", "Commission", "Swap", "Profit");
        }
      FileClose(file_handle);
     }
   else
     {
      Print("Error opening file: ", GetLastError());
      return(INIT_FAILED);
     }
     
   return(INIT_SUCCEEDED);
  }

void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
   if(trans.type == TRADE_TRANSACTION_HISTORY_ADD)
     {
      ulong deal_ticket = trans.deal;
      if(HistoryDealSelect(deal_ticket))
        {
         long deal_entry = HistoryDealGetInteger(deal_ticket, DEAL_ENTRY);
         
         if(deal_entry == DEAL_ENTRY_OUT)
           {
            WriteDealToJournal(deal_ticket);
           }
        }
     }
  }

void WriteDealToJournal(ulong deal_ticket)
  {
   long position_id = HistoryDealGetInteger(deal_ticket, DEAL_POSITION_ID);
   string symbol = HistoryDealGetString(deal_ticket, DEAL_SYMBOL);
   long type = HistoryDealGetInteger(deal_ticket, DEAL_TYPE);
   double volume = HistoryDealGetDouble(deal_ticket, DEAL_VOLUME);
   datetime close_time = (datetime)HistoryDealGetInteger(deal_ticket, DEAL_TIME);
   double close_price = HistoryDealGetDouble(deal_ticket, DEAL_PRICE);
   double commission = HistoryDealGetDouble(deal_ticket, DEAL_COMMISSION);
   double swap = HistoryDealGetDouble(deal_ticket, DEAL_SWAP);
   double profit = HistoryDealGetDouble(deal_ticket, DEAL_PROFIT);
   
   datetime open_time = 0;
   double open_price = 0.0;
   
   if(HistorySelectByPosition(position_id))
     {
      int total = HistoryDealsTotal();
      for(int i = 0; i < total; i++)
        {
         ulong dt = HistoryDealGetTicket(i);
         if(HistoryDealGetInteger(dt, DEAL_ENTRY) == DEAL_ENTRY_IN)
           {
            open_time = (datetime)HistoryDealGetInteger(dt, DEAL_TIME);
            open_price = HistoryDealGetDouble(dt, DEAL_PRICE);
            break;
           }
        }
     }

   // Calculate exact duration in seconds
   long duration_seconds = (long)(close_time - open_time);
   
   string sType = (type == DEAL_TYPE_BUY) ? "Buy" : (type == DEAL_TYPE_SELL) ? "Sell" : "Other";
   
   int file_handle = FileOpen(InpFileName, FILE_CSV|FILE_READ|FILE_WRITE|FILE_ANSI, ",");
   if(file_handle != INVALID_HANDLE)
     {
      FileSeek(file_handle, 0, SEEK_END);
      
      // Append duration_seconds to the output
      FileWrite(file_handle, deal_ticket, position_id, symbol, sType, volume, TimeToString(open_time), TimeToString(close_time), duration_seconds, open_price, close_price, commission, swap, profit);
      FileClose(file_handle);
      Print("Journal updated with closed deal: ", deal_ticket, " | Duration: ", duration_seconds, "s");
     }
  }

Re: The Annual Review: A Structured Look at Twelve Months

Posted: Sat Oct 24, 2026 2:33 pm
by Shadow Trader
Total costs deserve a line of their own in R, because in currency they look small next to the result. Converting them shows how much of the gross edge the year actually kept.

Say a year of 240 trades paid an average of 0.1R per trade in spread and commission. That is 24R of costs, and if the net result was plus 36R, the gross edge before costs was 60R, so costs took 40 percent of it.

That figure changes what next year's goals should be. Cutting the weakest third of trades, say 80 that were roughly flat before costs, saves 8R without touching the edge and lifts the net to 44R.

The breakdown by setup and session in the list is where those trades usually show up. A session with plenty of trades and a gross result near zero is a cost machine, even if it never shows a losing month.

It is also worth checking the cost per trade across the quarters. If it crept up, that usually points to more trading around news or at thin hours, rather than the broker getting worse. Does anyone set a cost ceiling as one of the measurable targets?

Re: The Annual Review: A Structured Look at Twelve Months

Posted: Thu Nov 05, 2026 10:03 am
by Fairman
Interesting that you skip the written journal and go straight from the broker export. I can see the appeal, the numbers don't flatter anyone. My worry is that the export tells you what happened but never why. Profit factor falling from 1.6 to 1.2 over the year could be spread creeping up, or it could be you taking more trades after 3pm when you were tired, and the statement can't separate those two.

A middle road might be to add one column to the exported file, just a tag on each trade. Something like "planned", "chased" or "revenge". It costs ten seconds per trade. Then at the review you can split, say, 900 trades into 700 planned at +0.15R each and 200 chased at -0.2R each. The total looks fine at +65R, but the chased group cost you 40R. That is the kind of thing a pure statement review will hide.

I'd agree the cost efficiency angle is sharp, though. Spread and commission as a share of gross profit is a number most people never compute. What does yours come out at, roughly? And after 18 years, does the yearly review ever change anything you actually do?