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

 
Folks, well help on the pairs. How do you add if there is no MT on the general list?
 
Valeriy Yastremskiy:

FILE_SHARE_READ

128

Shared read access by multiple programs. This flag is used when opening files (FileOpen()), but does not replace the need to specify FILE_WRITE and/or FILE_READ when opening a file

It does not. And in general, it's better not to open and close the file on every tick

It allows shared reads, not shared reads
Thank you. It's working! I feel sorry for the compukter to close the file every tick, so I put closing the file in OnDeinit.
 
HeAic:
How do I replace the Sleep(500) function in the indicator?

If you really need it, make your own pause that counts processor tick times in milliseconds. It will pause, but the whole thread will be waiting.

 
  int fileHandle=FileOpen("logg.txt",FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_TXT|FILE_ANSI);   
  datetime time=TimeLocal();
int OnInit()
  {
  return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  FileClose(fileHandle);
  }
void OnTick()
  {
  FileWrite(fileHandle,"Время=",TimeLocal());
  }
Why declare a "time" variable if it is not used in"FileWrite"? If you don't declare it:
int fileHandle=FileOpen("logg.txt",FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_TXT|FILE_ANSI);   
datetime TimeLocal();
then the compiler will swear, but what's the point?
 
ascerdfg:
Why declare variable "time" if it is not used in "FileWrite"? If you don't declare it: the compiler will swear, but what is the point?
datetime TimeLocal();

THIS WHAT?????

Maybe remove that line altogether and see?

 
Valeriy Yastremskiy:

THIS IS WHAT?????

Maybe remove that line altogether and see?

It says so in the Help: https://www.mql5.com/ru/docs/dateandtime/timelocal

Call without parameters

datetimeTimeLocal();

Документация по MQL5: Дата и время / TimeLocal
Документация по MQL5: Дата и время / TimeLocal
  • www.mql5.com
Дата и время / TimeLocal - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
ascerdfg:

This is what it says in the Help file: https://www.mql5.com/ru/docs/dateandtime/timelocal

Called without parameters

datetimeTimeLocal();

FileOpen

The function opens a file with specified name and specified flags.

intFileOpen(
stringfile_name,//file name
intopen_flags,// combination of flags
shortdelimiter='\t',// delimiter
uintcodepage=CP_ACP//codepage
);

And this is how fileopen is written. This is not an example of how to write it in a program, but an indication of the type of the return value.

 qqq.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                                  https:// |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
 int fileHandle=FileOpen("logg.txt",FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_TXT|FILE_ANSI);   
//  datetime time=TimeLocal();
int OnInit()
  {
  return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  FileClose(fileHandle);
  }
void OnTick()
  {
  FileWrite(fileHandle,"Время=",TimeLocal());
  }
'qqq.mq4'       qqq.mq4 1       1
0 errors, 0 warnings, 202 msec elapsed          1       1
It makes sense to assign the time variable to the local computer time in oninit and this will be the start time of the EA)))
 
Thank you!
 
double a=20.43;
double b=20.56;
int OnInit()
  {
  return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  }
void OnTick()
  {
  Print(a-b);
  }
The result says -0.129999999999999999. Why?
 
ascerdfg:
The result prints -0.1299999999999999. Why?

Features of storing real numbers in computer memory.

Use DoubleToString() to output with the desired accuracy

In general, you should learn the basics, and then try to write programs.

Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
  • www.mql5.com
Вещественные типы (или типы с плавающей точкой) представляют значения, имеющие дробную часть. В языке MQL5 есть два типа для чисел с плавающей точкой. Способ представления вещественных чисел в машинной памяти определен стандартом IEEE 754 и не зависит от платформ, операционных систем и языков программирования. Константы с плавающей точкой...