import csv column into ea

To add comments, please log in or register
Samir Ahmane
60
Samir Ahmane  


ResetLastError();
   int filehandle=FileOpen("history_1.csv",FILE_READ|FILE_CSV,';');
   if(filehandle!=INVALID_HANDLE)
     {
     
      Print("FileOpen OK");
      
     }
   else
      Print("Operation FileOpen failed, error ",GetLastError());

   long GetValue = FileGetInteger (filehandle,1);
   Print ("Result: "+GetValue);

Hi, I need to import a .csv column into an ea. I am attaching the source code of the script that write the .csv file below, I want to get control over every value in .csv file. The data in the .csv file will change in real-time. I'm also attaching the script which is writing the data on the .csv file. Thanks in advance for all the help you'de be giving!

Files:
William Roeder
20214
William Roeder  
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help
          urgent help.

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum

Samir Ahmane
60
Samir Ahmane  
William Roeder:
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help
          urgent help.

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum

Hi William! I hope you're doing good, I'm not here to pay for an EA or a trading function, I'm here to learn and attempting to get better at coding by solving more complex problems, I'm still enrolling at programming courses. Has nothing to do with an EA, anyway, thanks for your clarifications! Have a good day. The attempted code is attached above in a source file.

William Roeder
20214
William Roeder  
Samir Ahmane: the attempted code is attached above in a source file.

No it not. You said that it's "script which is writing the data." Show us your code that reads the file and state the nature of your problem. MT4: Learn to code it.

Samir Ahmane
60
Samir Ahmane  
William Roeder:

No it not. You said that it's "script which is writing the data." Show us your code that reads the file and state the nature of your problem. MT4: Learn to code it.

   ResetLastError();
   int filehandle=FileOpen("history_1.csv",FILE_READ|FILE_CSV,';');
   if(filehandle!=INVALID_HANDLE)
     {
     
      Print("FileOpen OK");
      
     }
   else
      Print("Operation FileOpen failed, error ",GetLastError());

   long GetValue = FileGetInteger (filehandle,1);
   Print ("Result: "+GetValue); 
Sorry, haven't understood what you meant.
Samir Ahmane
60
Samir Ahmane  
William Roeder:

No it not. You said that it's "script which is writing the data." Show us your code that reads the file and state the nature of your problem. MT4: Learn to code it.

William, I would really appreciate your help, as I am getting near to the solution, I'm getting the value from the .csv file, but I'm only able to get the first value on the first row here is the code. Does it need a ENUM value to specify which value you want to define? Thanks in advance.


void OnStart()
  {
  
//---
  
   ResetLastError();
   int filehandle=FileOpen("history_1.csv",FILE_READ|FILE_CSV,';');
   if(filehandle!=INVALID_HANDLE)
     {
     
      Print("FileOpen OK");
      
     }
   else
      Print("Operation FileOpen failed, error ",GetLastError());

   long GetValue = FileGetInteger (filehandle,1);
   Print ("Result: "+GetValue);
   double n_13 = FileReadNumber(filehandle);
   Alert (n_13);
  }
  
William Roeder
20214
William Roeder  
  1.    long GetValue = FileGetInteger (filehandle,1);
    Don't hard code constants. The documentation says the second parameter is a ENUM_FILE_PROPERTY_INTEGER What does 1 mean?

  2.    double File_txt=FileOpen("history_1.csv",FILE_WRITE,';');
    
    Your script doesn't create a CSV file and FileOpen doesn't return a double.
Samir Ahmane
60
Samir Ahmane  
William Roeder:
  1. Don't hard code constants. The documentation says the second parameter is a ENUM_FILE_PROPERTY_INTEGER What does 1 mean?

  2. Your script doesn't create a CSV file and FileOpen doesn't return a double.

Thank you William, I resolved the problem. Here is the source code below; the variable 'a_n' is going to represent the history of the account balance on each of the last 13 trades. Yet, it is not representing the account balance accurately, I can fix this problem since all it needs is basic calculus. The Orders Profits are represented with the variable ' vars[n]'. Thank you for your help!


//+------------------------------------------------------------------+
//|                                                        Value.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

/*I am defining a double variable for account balance, because we need to add balance to n other we'll get negative
values that will result in a irrelevant drawdown value*/

   double Balance=AccountBalance();

/*We are getting the last error, and below, we are openning a csv file for reading, and we are defining it as file handle
and if the filehandle is not invalide, then, we print that the file openning was successful, else, the operation failed*/

   ResetLastError();
   int filehandle=FileOpen("history_1.csv",FILE_READ|FILE_CSV,' ');
   if(filehandle!=INVALID_HANDLE)
     {

      Print("FileOpen OK");

     }
   else
      Print("Operation FileOpen failed, error ",GetLastError());



   double n_13=FileReadNumber(filehandle);
   Print(n_13);



   double vars[13];
   int count=0;

   while(!FileIsEnding(filehandle) && count<13)
     {
      vars[count]=FileReadNumber(filehandle);
      count++;
     }

   double a_13=n_13+vars[0]+vars[1]+vars[2]+vars[3]+vars[4]+vars[5]+vars[6]+vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_12=vars[0]+vars[1]+vars[2]+vars[3]+vars[4]+vars[5]+vars[6]+vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_11=vars[1]+vars[2]+vars[3]+vars[4]+vars[5]+vars[6]+vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_10=vars[2]+vars[3]+vars[4]+vars[5]+vars[6]+vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_9=vars[3]+vars[4]+vars[5]+vars[6]+vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_8=vars[4]+vars[5]+vars[6]+vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_7=vars[5]+vars[6]+vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_6=vars[6]+vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_5=vars[7]+vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_4=vars[8]+vars[9]+vars[10]+vars[11]+Balance;
   double a_3=vars[9]+vars[10]+vars[11]+Balance;
   double a_2=vars[10]+vars[11]+Balance;
   double a_1=vars[11]+Balance;
}
To add comments, please log in or register