Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1119

 
Alexey Viktorov:

You tell me...

Type

Size in bytes

Minimum positive value

Maximum value

Analog in C++

float

4

1.175494351e-38

3.402823466e+38

float

double

8

2.2250738585072014e-308

1.7976931348623158e+308

double


file size in bytes, the size occupied by type double in bytes, and it is obligatory to divide by zhzhezhezhezhezhezhezhezhezhez



What is zzzzzzzz? It doesn't add up, man, can't you make it easier?
 
Top2n:
What's a zzzzzz? It doesn't add up, can't you take it easy?
Please use your brain just a little bit. I can only advise you, not do it for you. What's your data, what's the dimension of the array... I don't want to remember all that and lead you to victory.
 

Получается, что если массив динамический, то формула /16, не совсем подходит, хотя второе же измерение фиксировано, к там уже -  

Выходит, что вторичный массив записывается на первичный, возможно перед записью что то сделать нужно
FileSeek(handle,0,SEEK_END);
Люди записывают переменные в массив, возможно поможет? типо такого

int dataArraySize = ArraySize(dataArray); //записываем в переменную размер массива
int fileHandle = FileOpen("filename.dat"FILE_BIN | FILE_WRITE); // открываем файл на запись в бинарном режиме.
FileWriteInteger(fileHandle, dataArraySize);//записываем в файл размер массива
FileWriteDouble(fileHandle, dataArraySize);//записываем в файл все элементы массива

 


The code of the line supplementing the bin file with a new bar

if(count==size)
        {
      //  ArrayResize(arrS,coun);  
         for(int q=0; q<ARRAY_SIZE_X; q++) // Перебор по периоду, колонка X
           {
            arrS[q]=sm.d[q].m[rates_total-1];                // M(I) SMA
            coun++; 
           }
         ResetLastError();
         int handle=FileOpen(path,FILE_WRITE|FILE_BIN);
         if(handle!=INVALID_HANDLE)
           {
            //--- запишем данные массива в конец файла
            FileSeek(handle,0,SEEK_SET);
            FileWriteArray(handle,arrS);
            Print("arrS = ",arrS[0]," arrS = ",arrS[1]," arrS = ",arrS[3]);
            //--- закрываем файл
            FileClose(handle);
           }
         else
            Print("Failed to open the file, error ",GetLastError());
         count=1;
        }
 
Top2n:

Получается, что если массив динамический, то формула /16, не совсем подходит, хотя второе же измерение фиксировано, к там уже -  

Выходит, что вторичный массив записывается на первичный, возможно перед записью что то сделать нужно
FileSeek(handle,0,SEEK_END);
Люди записывают переменные в массив, возможно поможет? типо такого

int dataArraySize = ArraySize(dataArray); //записываем в переменную размер массива
int fileHandle = FileOpen("filename.dat"FILE_BIN | FILE_WRITE); // открываем файл на запись в бинарном режиме.
FileWriteInteger(fileHandle, dataArraySize);//записываем в файл размер массива
FileWriteDouble(fileHandle, dataArraySize);//записываем в файл все элементы массива

 


The code of the line that supplements the bin file with a new bar

if(count==size)
        {
      //  ArrayResize(arrS,coun);  
         for(int q=0; q<ARRAY_SIZE_X; q++) // Перебор по периоду, колонка X
           {
            arrS[q]=sm.d[q].m[rates_total-1];                // M(I) SMA
            coun++; 
           }
         ResetLastError();
         int handle=FileOpen(path,FILE_WRITE|FILE_BIN);
         if(handle!=INVALID_HANDLE)
           {
            //--- запишем данные массива в конец файла
            FileSeek(handle,0,SEEK_SET);
            FileWriteArray(handle,arrS);
            Print("arrS = ",arrS[0]," arrS = ",arrS[1]," arrS = ",arrS[3]);
            //--- закрываем файл
            FileClose(handle);
           }
         else
            Print("Failed to open the file, error ",GetLastError());
         count=1;
        }


I don't remember where I read it, but if you open a file for writing only, everything in it gets deleted.

int handle=FileOpen(path,FILE_WRITE|FILE_BIN);

The file has to be opened for reading and writing

int handle = FileOpen(path, FILE_READ|FILE_WRITE|FILE_BIN);
If we open the file for reading only, then the write flag can and even better not be specified.
 
Alexey Viktorov:

I can't remember where I read it, but if a file is only opened for writing, everything in it is deleted.

int handle=FileOpen(path,FILE_WRITE|FILE_BIN);

The file has to be opened for reading and writing

int handle = FileOpen(path, FILE_READ|FILE_WRITE|FILE_BIN);
If we open the file for reading only, then the write flag can and even better not be specified.
Forgive me, but I have already solved)) the problem was one of these too)) By poking around))))
 

I thought that was it.

I write new data to the beginning, it writes to the full beginning, is there any way to increase the size of the beginning))

I mean is it limited to write to the beginning ? or continue saving to the end only ?

FileSeek(handle,0,SEEK_SET);

And if I save to the end, and continue to add to the end, how do I read from the end to the right amount ? Or rather, how to capture from bin file the right chunk fromN to the end

Or did I do it with the wrong commands!?!?

I save two arrays to the end - it is written as I understand by increasing the weight of the bin correctly.

Then I try to transfer data to the array with the task to capture the last record, file bins are bigger than the array.

  ResetLastError();
   int file_handle=FileOpen(path,FILE_READ|FILE_BIN);
   if(file_handle!=INVALID_HANDLE)
     {
      //--- прочитаем все данные из файла в массив
      //file_siz=FileSize(file_handle)/8000;
      //FileSeek(file_handle,file_size,SEEK_END);
      FileReadArray(file_handle,arr);
      //--- получим размер массива
      int siz=ArraySize(arr);
      //--- распечатаем данные из массива
      Print("arr = ",arr[1][3]," Bid = ",arr[1][2]," Ask = ",arr[0][3]);
      Print("file_siza = ",file_siz);
      //--- закрываем файл
      FileClose(file_handle);
FileSeek(file_handle,file_size,SEEK_SET);  что делает  - определяет положение массива или в бине?
 

If I read the required section from the binary file with

FileReadArray(file_handle,arr,0,WHOLE_ARRAY);

The algorithm processes the array itself, the missing cells are translated similarly to the position in the bin, which in turn gives the requested range in the limit of the same position as in the bin, only with zeros.

 
Top2n:

If I read the required section from the binary file with

FileReadArray(file_handle,arr,0,WHOLE_ARRAY);

The algorithm processes the array itself, missing cells are translated similarly to binary position, which in turn gives the requested range in the limit of the same position as in the binary, only with zeros.

I don't understand what can go wrong...

You just open the file for reading.

handle = FileOpen(path, FILE_READ|FILE_BIN);

shift the pointer to the right number of bytes in the right direction

FileSeek(handle, -32, SEEK_END);
// В данном случае от конца файла на 32 байта

32 bytes is 8 integer values or 4 floating point values.

If the array is two-dimensional, this means that we shift by 4 lines if the array is of int type, or by 2 lines if the array is of double type

Then, we read the values into the array declared beforehand as a dynamic arr[][2]; this is a two-dimensional array.

FileReadArray(handle, arr);

THAT'S IT!!!

Next, determine the size of the array

int size = ArrayRange(arr, 0);

and then print the values.

int i, z;

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

  {
   for(z = 0; z < 2; z++)
    {
     Print("arr[", i, "][", z, "]", arr[i][z]);
    }
  }
 
Alexey Viktorov:

I don't understand what can go wrong...

Thank you, you! It worked)))

 

I have an EA, I want it to be able to choose which days to trade on, and which not.

Mon - false

Tues - true

Cp- ...

Please advise how to implement it?

Reason: