Limiting BIN files to a maxsize of lines per file

MQL4 Experts Scripts

Tâche terminée

Temps d'exécution 1 jour
Commentaires de l'employé
Friendly customer
Commentaires du client
Good job, straight to the point and honest.

Spécifications

Hi all, the simple script im currently using has the below functions Ontick:

- Takes the Bid or Ask price of the current chart pair.
- Opens/Creates a new bin file.
- Stores that Bid or Ask price at the BOTTOM of the bin file
- Reopens the bin file to read it
- Stores it into an array in order to be manipulated

I would like to be able to limit this file, because obviously right now the file just keeps getting bigger, to a certain number of lines (circular buffer?)
So that at the current tick, and lets say maxsize = 5, the file looks like this:
-E, D, C, B, A (A being the oldest bid/ask price stored at the end of the line)

on next tick
-F, E, D, C, B  (A deleted and F inserted as the most recent tick price)

The code is the below:

void OnTick()



  {

   double PriceDiff = MarketInfo("AUDCAD",(MODE_ASK));

        

   int fileHandle2 = FileOpen("Myfile.bin",FILE_BIN|FILE_READ | FILE_WRITE);

       

   FileSeek(fileHandle2, 0, SEEK_END); // Write at the end of the file.

   double data2 = PriceDiff;

   FileWriteDouble(fileHandle2,data2);

   FileClose(fileHandle2);    

   double arr[];

   string path= "";

   ResetLastError();

   int file_handle=FileOpen("Myfile.bin",FILE_READ|FILE_BIN);

   if(file_handle!=INVALID_HANDLE)

     {

      FileReadArray(file_handle,arr);

      //--- receive the array size

      int size=ArraySize(arr);

      //--- print data from the array

      for(int i=0;i<size;i++);

      Comment("Total data = ",size);

      //--- close the file

      FileClose(file_handle);


I hope the explanation is clear enough, if not we can discuss further. 

Thanks in advance
Chris

Répondu

1
Développeur 1
Évaluation
(5)
Projets
7
29%
Arbitrage
1
0% / 100%
En retard
0
Gratuit
2
Développeur 2
Évaluation
(4)
Projets
4
0%
Arbitrage
1
0% / 100%
En retard
1
25%
Gratuit
3
Développeur 3
Évaluation
(6)
Projets
7
0%
Arbitrage
0
En retard
5
71%
Gratuit
4
Développeur 4
Évaluation
(1)
Projets
2
0%
Arbitrage
0
En retard
1
50%
Gratuit
5
Développeur 5
Évaluation
(82)
Projets
86
57%
Arbitrage
25
0% / 84%
En retard
19
22%
Gratuit
6
Développeur 6
Évaluation
(64)
Projets
144
46%
Arbitrage
19
42% / 16%
En retard
32
22%
Travail
7
Développeur 7
Évaluation
(7)
Projets
13
0%
Arbitrage
5
20% / 60%
En retard
0
Gratuit

Informations sur le projet

Budget
30 - 50 USD
Délais
de 1 à 10 jour(s)