Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 353

 
tvv:

I don't get it. This option indicates the location of the file - \MetaQuotes\Terminal\Common. Without this option I won't be able to grab the file that was generated in the tester. Without this option the file will be searched in MQL4\Files - and I won't be able to put the file from the tester there.

It was the absence of this flag that I pointed out.

 
Alexey Viktorov:

It was the absence of this flag that I pointed out.

Thanks for your help - it's just a typo - I know this flag. The problem is not solved - the file doesn't want to open in shared read mode - even without using the tester. As long as this file is open by the indicator - the script can't open it. Notepad, on the other hand, opens it without any problems.

 
tvv:

Thanks for the help - it's just a typo - I know that flag. The problem is not solved - the file doesn't want to open in shared read mode - even without using the tester. As long as this file is opened by the indicator - the script can't open it. Notepad, on the other hand, opens it without any problem.

Try forcing data to disk periodically by FileFlush().


hmmm: another thing I didn't notice right away

tvv:

ExtHandle=FileOpen(c_symbol+(string)20+".csv",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_READ|FILE_SHARE_READ|FILE_COMMON);
The file in the script is opened as follows: ExtHandleR=FileOpen("EURUSD20.csv",FILE_BIN|FILE_READ|FILE_SHARE_READ);
Please point out my error.

It's strange that it reads. There should be a FILE_CSV flag.
FileFlush - Файловые операции - Справочник MQL4
FileFlush - Файловые операции - Справочник MQL4
  • docs.mql4.com
При выполнении операции записи в файл физически данные могут оказаться в нем только через некоторое время. Для того чтобы данные сразу же сохранились в файле, нужно использовать функцию FileFlush(). Если не использовать функцию, то часть данных, еще не попавших на диск, принудительно записывается туда только при закрытии файла функцией...
 
Alexey Viktorov:

Try periodically forcing data to disk with FileFlush().


Hint: Another thing I noticed a while back

It's strange that it reads. There should be a FILE_CSV flag.

.CSV is a file extension - you can use any extension - I chose it so you can look it up in Notepad. Here is an interesting article - https://www.mql5.com/ru/articles/2720. My code complies with the rules described there - but I can't read the file programmatically. in FILE_SHARE_READ mode. For file EURUSD20.HST with extension .HST - flag must be FILE.BIN, so that in MT 4 file can be opened offline.

Основы программирования на MQL5: Файлы
Основы программирования на MQL5: Файлы
  • 2016.09.28
  • Dmitry Fedoseev
  • www.mql5.com
Функции для работы с файлами есть почти во всех языках программирования, и MQL5 в этом смысле — не исключение. Хотя при программировании советников и индикаторов на MQL5 работать с использованием файлов приходится не всегда, (а скорее даже — очень редко), но тем не менее, каждый экспертописатель рано или поздно с этим сталкивается. Диапазон...
 
tvv:

.CSV is a file extension - it can be anything - I chose it so I could look it up in Notepad. Here is an interesting article - https://www.mql5.com/ru/articles/2720. My code complies with the rules described there - but I can't read the file programmatically. in FILE_SHARE_READ mode. For file EURUSD20.HST with extension .HST - flag must be FILE.BIN, so that in MT 4 file can be opened offline.

I tried to work not in the tester but just on a normal chart (EURUSD M1) - I run the indicator that generates the TF M20.

To open the file:

ExtHandle= FileOpen("EURUSD20.csv",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_READ|FILE_SHARE_READ).

The file will then appear in the MQL4\Files folder. Then we run the script on a regular chart (EURUSD M5) which copies the content of EURUSD20.csv to EURUSD20.HST. File EURUSD20.HST is generated in the history folder in the same directory as MQL4.

The script code:

ExtHandleR=FileOpen("EURUSD20.csv",FILE_BIN|FILE_READ|FILE_SHARE_READ) read file;

ExtHandleW=FileOpenHistory("EURUSD20.hst",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ);

Everything works only when I remove the indicator from the M1 chart. That is, I don't have the file sharing read mode working.

 

Hello! What is the metatrader glitch on the eurodollar chart? A daily candle for Sunday 9.10.2011 appeared, on the hour chart there is only one hour 23:00 for that date. This is probably due to the change of clocks to winter time. How to fix it? There was no such candle before.

 
tvv: Everything works only when I remove the indicator from the M1 chart. That is, I don't have read split file mode working.

The problem is solved as follows: The program writing the file must close FileClose after each write operation, thus freeing the file for another program to read. This is because the data is first written to the buffer and is not physically present in the file for some time. Closing the file releases the buffer into the file. Before the next write

   // Открытие или создание файла и перемещение указателя в конец
   Файл = FileOpen(ИмяФайла, FILE_CSV | FILE_READ | FILE_WRITE, " "); // еще COMMON  SHARE...
   FileSeek(Файл, 0, SEEK_END);

the file is reopened and the pointer is moved to the end of the

 

Hello! Can you tell me if it is correct to say that the number of points obtained will be the same in both expressions? It's really important to me!

"Цена закрытия последнего закрытого ордера"-Ask>=30*Point

Ask-"Цена закрытия последнего закрытого ордера">=30*Point //Если цена Выше

More precisely, can't the points be negative??? Or is it still.....))

 

Good evening.

I started studying mql5 and have some questions, so please help.

The task is to get the values of the last n candlesticks into an array and sort the array by choosing only the unbeaten candlesticks.

I have written the function:

double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
   {
      double high=0;
      int k=0;
      int s=0;
      ArraySetAsSeries(High,true);
         if(CopyHigh(Symbol(),Period(),0,NumCand,High)==-1)
               {
               Print("Не удалось скопировать значения цен High! Код ошибки = ",GetLastError());
               }  
               
      
       for(int x=NumCand-1; x==0; x--)
            {
            if(IsStopped())
            break;
                  for (int j = NumCand-x-1; j == 0; j--) 
                  {
                  if (High[j+1] > High[j])
                     {
                     // Если хай не побит записываем в массив
                     temp[k] = High[j+1];
                     k++;
                     }   
                   }
            }
      s=sizeof(temp);               
      high=temp[index];
      return(high);
   } 

It generates an errorarray out of range.

 high=temp[index];

As far as I understood, this error is caused by addressing a non-existing cell of the array.

But I could not find the error from the move, please advise where I messed up, or maybe there is a more elegant sorting.

 
WhiteBerkut:

Good evening.

I started studying mql5 and have some questions, so please help.

The task is to get the values of the last n candlesticks into an array and sort the array by choosing only the unbeaten candlesticks.

I have written the function:

It generates an errorarray out of range.

As far as I understood, this error is caused by addressing a non-existing cell of the array.

But I could not find the error from the move, please advise where I messed up, or maybe there is a more elegant sorting.

Compare index value with array dimension. Note that array elements are numbered starting from zero, and the number of the last one is 1 less than the index dimension. And NumCand is equal to what?