vitals-account-monitor/mql4/Include/Vitals/VtLegacy.mqh
72 lines
2.8 KiB
MQL5
//+------------------------------------------------------------------+
//| VtLegacy.mqh |
//| Copyright 2026, Allan Niñal |
//| https://www.allanninal.dev/mql5 |
//+------------------------------------------------------------------+
//| MT4 only: opens this account's floating-drawdown journal and, the|
//| first time (no Vitals\FDD_<login>.csv yet), imports the one the |
//| old MT4 Vitals 1.0 kept. |
//| 1.0 wrote MQL4\Files\Vitals_FDD_<login>.csv (before that |
//| TradeInfo_FDD_<login>.csv): a UTF-16 CSV, FileWrite() lines |
//| "day,money,percent" - day = server seconds / 86400 (its |
//| DayNumber(TimeCurrent())), money to 2 decimals, percent to 4, |
//| several lines per day possible (appends; the deepest wins). |
//| That is exactly this journal's format and day number, so each |
//| line maps one to one (positive junk is clamped to 0, as 1.0 |
//| did); the old files are only read, never changed. |
//+------------------------------------------------------------------+
// SPDX-License-Identifier: LicenseRef-PolyForm-Noncommercial-1.0.0 (see LICENSE)
#ifndef VTLEGACY_MQH
#define VTLEGACY_MQH
#include "VtJournal.mqh"
int VtImportLegacy(CVtJournal &j,const long login)
{
string names[2];
names[0]="Vitals_FDD_"+IntegerToString(login)+".csv";
names[1]="TradeInfo_FDD_"+IntegerToString(login)+".csv";
for(int k=0; k<2; k++)
{
if(!FileIsExist(names[k]))
continue;
int h=FileOpen(names[k],FILE_READ|FILE_CSV|FILE_SHARE_READ|FILE_SHARE_WRITE,',');
if(h==INVALID_HANDLE)
continue;
int got=0;
while(!FileIsEnding(h))
{
long d=(long)FileReadNumber(h);
double m=FileReadNumber(h);
double pc=FileReadNumber(h);
if(d<=0)
continue;
if(j.Put(d,NormalizeDouble(MathMin(m,0.0),2),NormalizeDouble(MathMin(pc,0.0),4)))
got++;
}
FileClose(h);
if(got>0)
return(got);
}
return(0);
}
void VtJournalOpenAt(CVtJournal &j,const long login)
{
FolderCreate("Vitals"); // MQL4\\Files\\Vitals (journal, caches, exports)
string path="Vitals\\FDD_"+IntegerToString(login)+".csv";
bool fresh=!FileIsExist(path);
j.Init(path,GetTickCount());
if(fresh && j.n==0 && login>0)
{
int got=VtImportLegacy(j,login);
if(got>0)
{
j.dirty=true;
j.Flush(true,GetTickCount());
PrintFormat("Vitals: imported %d journal days from the Vitals 1.0 file",got);
}
}
}
#endif
//+------------------------------------------------------------------+