CSV Data File

 

The attched EA logs the account equity and balance to a csv file but does so on a cummulative basis, so it shows all changes over time. It there any way to change it so that it only extracts the latest data as per this file (say every hour) and reads this to a clean csv file with one row of the latest data only?

Thanks

Files:
 

This EA below writes the running account balance, account Equity and Free Margin to a csv file and updates it when the balance changes by 1%. I would really like help to change the code so it updates every 60 minutes with ONLY the latest data without writing any history i.e. will only show one row of data in the csv file.

Many thanks


int deinit()
{
return(0);
}


int start()
{
static double balance = 0;
static double equity = 0;

double b = AccountBalance();
double e = AccountEquity();
double m = AccountFreeMargin();

if ( b != balance || MathAbs( equity - e ) > 0.01 * b ) {
balance = b;
equity = e;
logEquity( b, e, m );
}

return(0);
}

void logEquity(double b,double e,double m)
{
string FILE = "accountdata.csv";
datetime time = CurTime();
int handle = FileOpen( FILE, FILE_CSV | FILE_WRITE | FILE_READ, ',' );
if ( handle == -1 ) {
Print( "Error creating ", FILE, ": ", GetLastError() );
return;
}
FileSeek( handle, 0, SEEK_END );
int count = FileWrite( handle, time, AccountNumber(), b, e, m );
if ( count < 0 ) {
Print( "Error writing to ", FILE, ": ", GetLastError() );
}
FileClose( handle );
}

Reason: