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

 
Санек:

1) - This part opens file 11112222.txt to read data from it:

//=================================BUY=========================================
    int handle2 = FileOpen("11112222.txt", FILE_CSV|FILE_READ, ";");//код открывает файл для чтения

2) - Next comes the condition if handle2>0


  if(handle2>0) // если в файле больше 0, то есть 1, то открывать BUY
   {

3) - This is the part I don't understand:


       Print(FileReadString(handle2));

4) - This part closes the file:


       FileClose(handle2); // закрытие текстового файла

5) - Since the condition handle2>0 is met, i.e. file 11112222.txt contains 1, a buy order is opened:

  //ОТКРЫТИЕ ОРДЕРА НА ПОКУПКУ      
                    if(OrdersTotal() == 0) // если нет открытых ордеров то открывать ордер на покупку
                     {
                        OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, 0, 0); // первым указывается ЛОСЬ, вторым ПРОФИТ
                        FileClose(handle2); // закрытие текстового файла
                     }
                    else
                      Print("NE USPESHNO!!!");
                      FileClose(handle2); // закрытие текстового файла

   }
//=================================конец кода BUY=========================================

Which parts have I mixed up?

1) Opens the file, but does not read its contents.

2) The handle of the file is ALWAYS greater than zero. Accordingly, the condition will always hold if the file exists regardless of its contents.

3) This is exactly reading the contents of the file. Although I don't understand why reading a string is done, if we need to read a number... But still it can be another problem. Now the main thing is to describe the sequence of actions.

4) Of course, the file must be closed and it closes.

And only the next clause needs to be conditioned depending on what you read in clause 3, but not the second clause.

 
Alexey Viktorov:

1) opens a file, but does not read its contents.

2) A file handle is ALWAYS larger than zero. Accordingly, the condition will always hold if the file exists regardless of its contents.

3) This is exactly reading the contents of the file. But I don't understand why reading a string is done, if a number is to be read... But still it can refer to another problem. Now the main thing is to describe the sequence of actions.

4) The file must be closed, of course, and it is being closed.

And only the next clause should be conditioned depending on what you read in clause 3, but not the second clause.

No... INVALID_HANDLE has value -1.

That's when it gets a file opening error, then it will get a sell signal...

Other constants

Special constants used to indicate the state of parameters and variables. Can be the following values:

Constant

Description

Value

NULL

Null of any type. Also indicates empty string state

0

EMPTY

Indicates empty state of parameter

-1

EMPTY_VALUE

Empty value in indicator buffer

2147483647 (0x7FFFFFFFF)

CLR_NONE, clrNONE

No colour. Default value, pointer to empty value. Used in custom indicators

-1

CHARTS_MAX

Maximum possible number of simultaneously opened charts in the terminal

100

INVALID_HANDLE

Incorrect handle

-1

IS_DEBUG_MODE

Sign of an mq5-program in debug mode

in debug mode is not equal to zero, otherwise 0

IS_PROFILE_MODE

Sign of an mq5-program in the profiling mode

in the profiling mode is not equal to zero, otherwise it is 0

WHOLE_ARRAY

Indicates the number of elements remaining to the end of the array, i.e. the whole array will be processed

0

WRONG_VALUE

A constant can be implicitly cast to any enum type

-1

 

Didn't see this thread, so I created a new one. please lookat https://www.mql5.com/ru/forum/206126

Как в тестере стратегий получить TimeGMT();
Как в тестере стратегий получить TimeGMT();
  • 2017.06.28
  • www.mql5.com
Справочник MQL5, Дата и время, TimeGMT TimeGMT - При работе в тестере стратегий время TimeGMT() всегда равно моделируемому серверному времени TimeT...
 
Alexey Viktorov:

1) opens a file, but does not read its contents.

2) A file handle is ALWAYS greater than zero. Correspondingly, the condition will always hold if the file exists regardless of its contents.

3) This is exactly reading the contents of the file. But I don't understand why reading a string is done, if a number is to be read... But still it can refer to another problem. Now the main thing is to describe the sequence of actions.

4) The file must be closed, of course, and it is being closed.

And only the next item should be conditioned depending on what you read in item 3, but not the second item.

Dear MQL gurus - if you're not a problem, please help me with this code, I've spent half a day on search engines, but I haven't found anything similar.

I guess it's just a few lines, but for an experienced user it's a matter of minutes)))

 

How can a dll in c++ take a string from mql4 and convert it to char*?

struct MqlStr
{
        int               len;
        char             *string;
};

static int proc_func(char* Name);

MT4_EXPFUNC int __stdcall myfunc(MqlStr sym_name)
{
        proc_func(sym_name[0].string);
        
}
int proc_func(char* Name)
{
}
This is the right code, isn't it?
 

Hi all, could you advise me please, I wrote an EA about a year ago, it was working fine. I have not used it all this time. I do not know what to do with it, I just do not know what to do with it. Can it be because I have changed Build? I am currently using the Build 1090.

 
Санек Dear MQL guru - if you're not hard to help me with this code, I spent half a day digging around in search engines, but I can't find anything similar.

It seems to be a matter of a few lines, which for a knowledgeable person is a matter of three minutes)))

Took me two hours. I have to check the system piece by piece. Run both EAs at once on adjacent charts - everything will be visible. Expert Advisor 1 = Write to file

//+------------------------------------------------------------------+
//| Запись в файл -1  0  1                                     1.mq4 |
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Инициализация - установка интервала таймера                      |
//+------------------------------------------------------------------+
void OnInit()
{
   EventSetTimer(7);
}


//+------------------------------------------------------------------+
//| Деинициализация - удаление метки                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int Зачем)
{
   ObjectDelete("Семафор");
}


//+------------------------------------------------------------------+
//| По таймеру каждые 7 секунд                                       |
//+------------------------------------------------------------------+
void OnTimer()
{
   int x=0;
   if(rand()<20000)
   {
     x=1;
     if(rand()<16000) x=-1;
   }

   ObjectCreate("Семафор",OBJ_LABEL,0,0,0);
   ObjectCreate("Семафор", OBJ_LABEL, 0, 0, 0);  // Создание
   ObjectSet("Семафор", OBJPROP_CORNER, 3);      // В правый нижний угол
   ObjectSet("Семафор", OBJPROP_XDISTANCE, 0);   // Координата X   
   ObjectSet("Семафор", OBJPROP_YDISTANCE, 40);  // Координата Y
   ObjectSetText("Семафор",(string)x+" Открываю",20,"Arial",Yellow);
   ChartRedraw(0);
   Sleep(2000);

   int handle = FileOpen("123.txt", FILE_BIN | FILE_WRITE);
   if(handle == -1)
   {
      ObjectSetText("Семафор","Ошибка",20,"Arial",Salmon);
      ChartRedraw(0);
      return;
   }

   ObjectSetText("Семафор",(string)x+" Записываю",20,"Arial",DeepSkyBlue);
   ChartRedraw(0);

   FileWriteInteger(handle, x, 4);
   Sleep(2000);

   ObjectSetText("Семафор","",20,"Arial",White);
   ChartRedraw(0);
   FileClose(handle);
}

EA 2 = Read file

//+------------------------------------------------------------------+
//| Чтение файла  -1  0  1                                     2.mq4 |
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Инициализация - установка интервала таймера                      |
//+------------------------------------------------------------------+
void OnInit()
{
   EventSetTimer(1);
}


//+------------------------------------------------------------------+
//| Деинициализация - удаление метки                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int Зачем)
{
   ObjectDelete("Семафор");
}


//+------------------------------------------------------------------+
//| По таймеру каждую секунду                                        |
//+------------------------------------------------------------------+
void OnTimer()
{
   int x=0;

   ObjectCreate("Семафор",OBJ_LABEL,0,0,0);
   ObjectCreate("Семафор", OBJ_LABEL, 0, 0, 0);  // Создание
   ObjectSet("Семафор", OBJPROP_CORNER, 2);      // В правый нижний угол
   ObjectSet("Семафор", OBJPROP_XDISTANCE, 0);   // Координата X   
   ObjectSet("Семафор", OBJPROP_YDISTANCE, 40);  // Координата Y
   ObjectSetText("Семафор","",20,"Arial",Yellow);
   ChartRedraw(0);

   Sleep(500);
   int handle = FileOpen("123.txt", FILE_BIN | FILE_READ);  // Получаем НОМЕР файла в ОС
   if(handle == -1)                // Если производится запись, файл занят, будет ошибка
   {
      ObjectSetText("Семафор","Ошибка",20,"Arial",Salmon);
      ChartRedraw(0);
      return;
   }

   x = FileReadInteger(handle,4);                          // Получаем СОДЕРЖИМОЕ файла
   ObjectSetText("Семафор",(string)x+" Прочитал",20,"Arial",DeepSkyBlue);
   ChartRedraw(0);

   FileClose(handle);
}
 
toni_stark:

Hi all, could you advise me please, I wrote an EA about a year ago, it was working fine. I have not used it all this time. I do not know what to do with it, I just do not know what to do with it. Can it be because I have changed Build? I am currently using the Build 1090.


It's quite possible, there have been a lot of innovations. Start by checking for compilation errors. With #PropertyStrict directive.

 
Vladimir Zubov:

There may well have been a lot of innovations. Start by checking for compilation errors. With the #PropertyStrict directive.

There is no such directive.

There is:

#property strict
 
Vladimir Zubov:

There may well have been a lot of innovations. Start by checking for compilation errors. With the #PropertyStrict directive.


Artyom Trishkin:

There is no such directive.

There is:


But I can't open the EA file which is on my computer with ex4 extension, but there is no such file through MetaEditor. Please tell me what is the reason.