Saving and Retrieving Trade Information from a temporary database

 

Good Day.

I'm working on an EA that uses arrays to store 3 trades from 3 symbols. In the demo account it works great but when i tried it on a real account, the array seems not working. I use the array to store the ticket number and the starting profit to which from time to time a certain function retrieves the information on each array on each symbol then compares if a certain profit stored in the array is reached. If it is reached, the profit will increase by 2.50(given that the starting profit is 5.00), that is, to serve as a trailing stoploss and if the a certain trade closes, it will also delete the data on tha array to which the ticket number is matched. Do you have an idea on how to store or retrieve data for example a text file temporarily?

Thank you very much

 
raven_chrono:

Good Day.

I'm working on an EA that uses arrays to store 3 trades from 3 symbols. In the demo account it works great but when i tried it on a real account, the array seems not working. I use the array to store the ticket number and the starting profit to which from time to time a certain function retrieves the information on each array on each symbol then compares if a certain profit stored in the array is reached. If it is reached, the profit will increase by 2.50(given that the starting profit is 5.00), that is, to serve as a trailing stoploss and if the a certain trade closes, it will also delete the data on tha array to which the ticket number is matched. Do you have an idea on how to store or retrieve data for example a text file temporarily?

Thank you very much

By using Filexxx functions, see the documentation and the codebase for examples.
 
angevoyageur:
By using Filexxx functions, see the documentation and the codebase for examples.


i have already gone through the documentation but i have not encountered same function like the file handling in c++. I already check into some codes that are posted in the forum but i cannot extract certain data that are stored on the csv.
 
raven_chrono:

i have already gone through the documentation but i have not encountered same function like the file handling in c++. I already check into some codes that are posted in the forum but i cannot extract certain data that are stored on the csv.
Show your code then, we can try to help you.
 
angevoyageur:
Show your code then, we can try to help you.


int init()
{
   data=FileOpen("database.csv",FILE_CSV|FILE_WRITE,';');
   if(data>0)
   {
      for(int ctr=0;ctr<10;ctr++)
      {
         FileWrite(data,"Data"+ctr);
      }
         
    
   }
   FileClose(data);
   return(0);
}

int deinit()
{
   ObjectsDeleteAll();
   return(0);
}

int start()
{  
   data=FileOpen("database.csv",FILE_CSV|FILE_READ|FILE_WRITE);
   int count=0;
   string stat;
   if(data>0)
   {
      while(!FileIsEnding(data) && FileReadString(data)!="Data8")
      {
        stat="found!";
        count++;
        FileWrite(data,"TEST"); //<--- this line should append the existing data
      }
      
   }
   FileClose(data);
   return(0);
}
 
raven_chrono:


Try this Script . . .

I've not had much success with FileIsEnding() never gotten to the bottom of why, maybe I will one day . . .

int data;

int init()
{
   data=FileOpen("database.csv",FILE_CSV|FILE_WRITE,';');
   if(data>0)
   {
      for(int ctr=0;ctr<10;ctr++)
      {
         FileWrite(data,"Data"+ctr);
      }
         
    
   }
   FileClose(data);
   return(0);
}

int deinit()
{
  // ObjectsDeleteAll();
   return(0);
}

int start()
{  
   data=FileOpen("database.csv",FILE_CSV|FILE_READ|FILE_WRITE);
   int count=0;
   string stat;
   if(data>0)
   {
      // while(!FileIsEnding(data) && FileReadString(data)!="Data8")
      //{
        
        FileSeek(data, 0, SEEK_END);
        stat="found!";
        count++;
        FileWrite(data,"TEST"); //<--- this line should append the existing data
      //}
      
   }
   FileClose(data);
   return(0);
}
Reason: