Writing to the file on a new line - page 7

 
EfremovSergey:

It's about the same as "busy" flag (first in, first out), only times more complicated, but the idea is interesting, I like it, thanks.

Probably, it would be easier to disable shared editing FILE_SHARE_WRITE and let those who opens only read FILE_READ read and those who opens read and write FILE_READ|FILE_WRITE get an error and re-open the file. This would probably be easier.

 
EfremovSergey:

I don't really understand what this means in the context of FileClose saving.

It means that not only when the file is closed, the changes made are saved to disk.

 
string    sep=";";                                                  // знак разделителя
ushort    usep=StringGetCharacter(sep,0);                           // код знака разделителя
string    arr[];                                                    // массив данных для открытия ордера
int       h=0;                                                      // handle_1
int       h1=0;                                                     // handle_2

int OnInit()
  
  {

   EventSetMillisecondTimer(3000);

   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)

  {
   EventKillTimer();
  }

void OnTimer()

  {

   h=FileOpen("Copy.txt",FILE_READ|FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_TXT|FILE_COMMON,";");   // open файл

   FileSeek(h,0,SEEK_SET);                      // перевод курсора в начало файла

   while(FileIsEnding(h)==false)               // построчное чтение до конца файла

     {

      string    s=FileReadString(h);                                    // чтение строки

      StringSplit(s,usep,arr);                                        // перенос подстрок в массив

      // открытие ордера с данными из массива

      OrderSend(arr[0],StrToInteger(arr[1]),StrToDouble(arr[2]),StrToDouble(arr[3]),100,0,0);

      if(FileIsEnding(h)==false)                                  // промежуточная проверка

         continue;                                               // возврат в начало по условию if

      h1=FileOpen("Copy.txt",FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_TXT|FILE_COMMON,";");  // очистка файла

      FileClose(h1);                                                   // закрытие handle_2

     }

   FileClose(h);                                                     // закрытие handle_1

   Comment ("\n H: ", h, "\n H1: ", h1);                            // вывод хэнделов на экран

  }

On the read side, there is a flagging that allows the file to be emptied without closing it, after all the data has been extracted.

On the write side, we have a flagging, which does not allow to open the file, if it is already opened by another Expert Advisor.

//--- Открываем файл

      int h1=FileOpen("Copy.txt",FILE_READ|FILE_WRITE|FILE_TXT|FILE_COMMON,";");

      FileSeek(h1, 0, SEEK_END);

      FileWrite(h1,Symbol(),OP_BUYSTOP,OrderLots()*Koof,OrderStopLoss(),Slippage,0,0,IntegerToString(OrderTicket()));

      FileClose(h1);
 
// закрываем файл

The code is just for example, it lacks check functions of handling handles and tickets and stuff like that, but it is close to the desired result.

Thanks a lot again everyone and much appreciation for the information and useful tips.