Hi,
I'm trying to use a file to store 5 values to use in my EA, but it doesn't work as I need.
I want it to check if there are values in the file; if there´s values I want to read them to my EA variables (EH, EL, SBP, SSP, HDD).
After the program is running I want it to compare the stored values with the ones saved in the file. I want to keep the Highest for EH, the lowest for EL, the last value for SBP, the last value for SSP, and the highest for HDD.
I wrote 2 pieces of code, 1 I have after the int Start() {, and the other is the last thing on the program.
It works allright if I don't close Metatrader. If I close Metatrader and I need to get the values from the file, all those values are empty. Can you find my mystake please?
First Code
//File Management
handle=FileOpen("fonseca.dat", FILE_BIN|FILE_READ|FILE_WRITE);
if(handle>0)
{
FileReadArray(handle, Values, 0, 5);
if (EH == 0) EH = Values[0];
if (EL == 0) EL = Values[1];
if (SBP == 0) SBP = Values[2];
if (SSP == 0) SSP = Values[3];
if (HDD == 0) HDD = Values[4];
if (EH == 0) EH = AccountEquity();
if (EL == 0) EL = AccountEquity();
if (Values[0] < EH) Values[0] = EH;
if (Values[0] > EH) EH = Values[0];
if (Values[1] > EL) Values[1] = EL;
if (Values[1] < EL)
{
if (Values[1]!=0) EL = Values[1];
}
if (Values[1] == 0) Values[1] = EL;
if (Values[4] < HDD) Values[4] = HDD;
if (Values[4] > HDD) HDD = Values[4];
FileWriteArray(handle, Values, 0, 5);
FileFlush (handle);
FileClose(handle);
}
//Fim File Management
Second code
// Fim Calcular Drawdown
//File Management
handle=FileOpen("fonseca.dat", FILE_BIN|FILE_READ|FILE_WRITE);
if(handle>0)
{
FileReadArray(handle, Values, 0, 5);
if (Values[0] < EH) Values[0] = EH;
if (Values[0] > EH) EH = Values[0];
if (Values[1] > EL) Values[1] = EL;
if (Values[1] < EL)
{
if (Values[1]!=0) EL = Values[1];
}
if (Values[1] == 0) Values[1] = EL;
if (Values[4] < HDD) Values[4] = HDD;
if (Values[4] > HDD) HDD = Values[4];
FileWriteArray(handle, Values, 0, 5);
FileFlush (handle);
FileClose(handle);
}
//Fim File Management
Thanks,
JFonseca
I'm trying to use a file to store 5 values to use in my EA, but it doesn't work as I need.
I want it to check if there are values in the file; if there´s values I want to read them to my EA variables (EH, EL, SBP, SSP, HDD).
After the program is running I want it to compare the stored values with the ones saved in the file. I want to keep the Highest for EH, the lowest for EL, the last value for SBP, the last value for SSP, and the highest for HDD.
I wrote 2 pieces of code, 1 I have after the int Start() {, and the other is the last thing on the program.
It works allright if I don't close Metatrader. If I close Metatrader and I need to get the values from the file, all those values are empty. Can you find my mystake please?
First Code
//File Management
handle=FileOpen("fonseca.dat", FILE_BIN|FILE_READ|FILE_WRITE);
if(handle>0)
{
FileReadArray(handle, Values, 0, 5);
if (EH == 0) EH = Values[0];
if (EL == 0) EL = Values[1];
if (SBP == 0) SBP = Values[2];
if (SSP == 0) SSP = Values[3];
if (HDD == 0) HDD = Values[4];
if (EH == 0) EH = AccountEquity();
if (EL == 0) EL = AccountEquity();
if (Values[0] < EH) Values[0] = EH;
if (Values[0] > EH) EH = Values[0];
if (Values[1] > EL) Values[1] = EL;
if (Values[1] < EL)
{
if (Values[1]!=0) EL = Values[1];
}
if (Values[1] == 0) Values[1] = EL;
if (Values[4] < HDD) Values[4] = HDD;
if (Values[4] > HDD) HDD = Values[4];
FileWriteArray(handle, Values, 0, 5);
FileFlush (handle);
FileClose(handle);
}
//Fim File Management
Second code
// Fim Calcular Drawdown
//File Management
handle=FileOpen("fonseca.dat", FILE_BIN|FILE_READ|FILE_WRITE);
if(handle>0)
{
FileReadArray(handle, Values, 0, 5);
if (Values[0] < EH) Values[0] = EH;
if (Values[0] > EH) EH = Values[0];
if (Values[1] > EL) Values[1] = EL;
if (Values[1] < EL)
{
if (Values[1]!=0) EL = Values[1];
}
if (Values[1] == 0) Values[1] = EL;
if (Values[4] < HDD) Values[4] = HDD;
if (Values[4] > HDD) HDD = Values[4];
FileWriteArray(handle, Values, 0, 5);
FileFlush (handle);
FileClose(handle);
}
//Fim File Management
Thanks,
JFonseca