Limiting BIN files to a maxsize of lines per file

2020.06.30 Experts Scripts

Job finished

Execution time 1 day
Feedback from employee
Friendly customer
Feedback from customer
Good job, straight to the point and honest.

Specification

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

Responded

1
Developer 1
2020.06.30
Rating
5
(4)
Projects
5
20%
Arbitration
0
Overdue
0
Working
2
Developer 2
2020.06.30
Rating
4.75
(4)
Projects
3
0%
Arbitration
2
0% / 50%
Overdue
1
33%
Working
3
Developer 3
2020.06.30
Rating
0
Projects
0
0%
Arbitration
0
Overdue
0
Free
4
Developer 4
2020.06.30
Rating
5
(1)
Projects
2
0%
Arbitration
0
Overdue
1
50%
Free
5
Developer 5
2020.06.30
Rating
4.89
(73)
Projects
79
56%
Arbitration
21
0% / 81%
Overdue
24
30%
Busy
6
Developer 6
2020.06.30
Rating
4.92
(61)
Projects
137
45%
Arbitration
18
39% / 11%
Overdue
38
28%
Loaded
7
Developer 7
2020.07.01
Rating
5
(6)
Projects
11
0%
Arbitration
3
33% / 67%
Overdue
1
9%
Free

Project information

Budget
30 - 50 USD
VAT (18%): 5.4 - 9 USD
Total: 35.4 - 59 USD
For the developer
27 - 45 USD
Deadlines
from 1 to 10 day(s)