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

 
DiPach:

Artyom meant by "... condition triggered - put a mark.", what he meant was to write in the script code to set the icon (marker) when the condition is triggered.

The MQL4 Reference has very good examples of scripts for creating icons. For example, this script that creates and moves "Buy" icons on a chart.

r772ra:

Good script, pull the required function from there,

and there you have it.

Thank you!
 
 

I want to write the structure, but I can't! It is written in the help that FileWriteStruct writes to a binary file, if the size is not specified, then the entire structure.

Who has any opinion?

It still writes to a binary.

Or send me to a branch where they can help.

Files:
 
_SERG_:

I want to write the structure, but I can't! It is written in the help that FileWriteStruct writes to a binary file, if the size is not specified, then the entire structure.

Who has any opinion?

It still writes to a binary.

Or direct me to a branch where they can help.


Where do you define the array size?

 
Vinin:


Where do you define the array size?


In the " ORD Orders[10];" declaration or via "ArrayResize( Orders, 10)", but this does not affect the error. I just checked it. (I really didn't specify the size in the script.)

I take it that there is no possibility to convert different types of data.

Terminal 646, ME 934.

 
_SERG_:

in the " ORD Orders[10];" declaration or via "ArrayResize( Orders, 10)", but this does not affect the error. Just checked. (I really didn't specify a size in the script.)

I take it that there is no possibility to convert different types of data.

Terminal 646, ME 934.


The test example reported that the file was created. Just can't find it
 
Vinin:

The test example reported that the file was created. I just can't find it.

Found it. Although I should have it in a completely different directory. So it works.
 
Vinin:

Found it. Although I have it in a completely different directory. So it works.

Can I have a look at the corrections? If the file is mine.

If the one in the help, DEMO_FileWriteStruct, so it compiles, I tried to take the function of writing to the file from it, but I do not need to control the number of lines written. Or did I understand that the structure is written byte-by-byte?

Then I have a question, should it be read byte-by-byte too? In the structure, when it is needed to load it back from the file?



 
_SERG_:

Can we have a look at the corrections?


I used the example from the help

//+------------------------------------------------------------------+
//|                                          Demo_FileWiteStruct.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- покажем окно входных параметров при запуске скрипта
#property script_show_inputs
//--- параметры для получения данных из терминала
input string          InpSymbolName="EURUSD";           // валютная пара
input ENUM_TIMEFRAMES InpSymbolPeriod=PERIOD_H1;        // таймфрейм
input datetime        InpDateStart=D'2013.01.01 00:00'; // дата начала копирования данных
//--- параметры для записи данных в файл
input string          InpFileName="EURUSD.txt";         // имя файла
input string          InpDirectoryName="Data";          // имя директории
//+------------------------------------------------------------------+
//| Структура для хранения данных свечи                              |
//+------------------------------------------------------------------+
struct candlesticks
  {
   double            open;  // цена открытия
   double            close; // цена закрытия
   double            high;  // максимальная цена
   double            low;   // минимальная цена
   datetime          date;  // дата
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   datetime     date_finish=TimeCurrent();
   int          size;
   datetime     time_buff[];
   double       open_buff[];
   double       close_buff[];
   double       high_buff[];
   double       low_buff[];
   candlesticks cand_buff[];
//--- сбросим значение ошибки
   ResetLastError();
//--- получим время появления баров из диапазона
   if(CopyTime(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,time_buff)==-1)
     {
      PrintFormat("Не удалось скопировать значения времени. Код ошибки = %d",GetLastError());
      return;
     }
//--- получим максимальные цены баров из диапазона
   if(CopyHigh(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,high_buff)==-1)
     {
      PrintFormat("Не удалось скопировать значения максимальных цен. Код ошибки = %d",GetLastError());
      return;
     }
//--- получим минимальные цены баров из диапазона
   if(CopyLow(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,low_buff)==-1)
     {
      PrintFormat("Не удалось скопировать значения минимальных цен. Код ошибки = %d",GetLastError());
      return;
     }
//--- получим цены открытия баров из диапазона
   if(CopyOpen(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,open_buff)==-1)
     {
      PrintFormat("Не удалось скопировать значения цен открытия. Код ошибки = %d",GetLastError());
      return;
     }
//--- получим цены закрытия баров из диапазона
   if(CopyClose(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,close_buff)==-1)
     {
      PrintFormat("Не удалось скопировать значения цен закрытия. Код ошибки = %d",GetLastError());
      return;
     }
//--- определим размерность массивов
   size=ArraySize(time_buff);
//--- сохраним все данные в массиве структуры
   ArrayResize(cand_buff,size);
   for(int i=0;i<size;i++)
     {
      cand_buff[i].open=open_buff[i];
      cand_buff[i].close=close_buff[i];
      cand_buff[i].high=high_buff[i];
      cand_buff[i].low=low_buff[i];
      cand_buff[i].date=time_buff[i];
     }
 
//--- откроем файл для записи массива структуры в файл (если его нет, то создастся автоматически)
   ResetLastError();
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_BIN|FILE_COMMON);
   if(file_handle!=INVALID_HANDLE)
     {
      PrintFormat("Файл %s открыт для записи",InpFileName);
      PrintFormat("Путь к файлу: %s\\Files\\",TerminalInfoString(TERMINAL_COMMONDATA_PATH));
      //--- подготовим счетчик количества байт
      uint counter=0;
      //--- в цикле запишем значения массива
      for(i=0;i<size;i++)
         counter+=FileWriteStruct(file_handle,cand_buff[i]);
      PrintFormat("В файл %s записано %d байт информации",InpFileName,counter);
      PrintFormat("Всего байтов: %d * %d * %d = %d, %s",size,5,8,size*5*8,size*5*8==counter ? "Верно" : "Ошибка");
      //--- закрываем файл
      FileClose(file_handle);
      PrintFormat("Данные записаны, файл %s закрыт",InpFileName);
     }
   else
      PrintFormat("Не удалось открыть файл %s, Код ошибки = %d",InpFileName,GetLastError());
  }
 
Vinin:


I used the example from the help

The generated file can be found in \Data\EURUSD.
npDirectoryName="Data"  InpSymbolName="EURUSD"
 
_SERG_:

The generated file can be found in \Data\EURUSD.

The terminal starts with the portable key and is located on drive D. The file is generated on drive C in a shared folder.