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

 
Artyom Trishkin:

Checked myself - everything compiles in mql4.

You made a mistake somewhere else.

This is not my code, it's Vasily Sokolov's class. Two people have complained to me that it doesn't compile under MT4. I got an error too, build 1090. Could you please check this class on MT4 compilation? It looks like some kind of nonsense. Thanks in advance.

https://www.mql5.com/ru/articles/1334#summary - the class itself is at the bottom of the article.

Рецепты MQL5 - Реализуем ассоциативный массив или словарь для быстрого доступа к данным
Рецепты MQL5 - Реализуем ассоциативный массив или словарь для быстрого доступа к данным
  • 2015.03.23
  • Vasiliy Sokolov
  • www.mql5.com
Эта статья описывает удобный класс для хранения информации - ассоциативный массив или словарь. Благодаря этому классу можно получать доступ к информации по ее ключу. Ассоциативный массив напоминает обычный массив, однако вместо индекса он использует некий уникальный ключ, например, перечисление ENUM_TIMEFRAMES или какой-либо текст. Что...
 
Alexey Volchanskiy:

This is not my code, it's Vasiliy Sokolov's class. I've had two people complain that it doesn't compile under MT4. I got an error too, build 1090. Could you please check this class on MT4 compilation? It looks like some kind of nonsense. Thanks in advance.

https://www.mql5.com/ru/articles/1334#summary - the class itself is at the bottom of the article

Compiled by
 
Artyom Trishkin:
Compiled by

Show me how you tested it.

 
Victor Nikolaev:

Show me how you tested it.

Vitya, I can't show you now - I'm not at my computer.
I use this Basil class in my bible. For both platforms.
And also - just inserted these lines into the private section of my first encountered quaternary class. And everything compiled.
 
Victor Nikolaev:

Show me how you tested it.

This class

Files:
Dictionary.mqh  45 kb
 
Greetings.
I create a file named = ticket+symbol.
I write into the file the opening price of the position and the current price, the letter "P" or "L" depending on the location of the price.
It is necessary to write the data of those positions, the open time of which is not older than 30 min.
The problem is that the data is written only for one position, the latest one.
Writing into other files is not made. There are 4 positions.
How to solve it?

datetime t_pre=0,t_lo;
string param="";string sy=""; int op=-1; int mn=-1;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
  PO=MarketInfo(Symbol(),MODE_POINT);
   vspread=(int)MarketInfo(Symbol(),MODE_SPREAD);
   datetime _o_t;
   double _Profit,_lot,_Swap,_pr,_tp,_sl,lA=-1;
   int _Ticket,_Type;
   string _Comm;
   int      i,k=OrdersTotal();

   if(sy=="0") sy=Symbol();
   for(i=0; i<k; i++) 
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) 
        {
         if(OrderSymbol()==sy || sy=="") 
           {
            if(OrderType()==OP_BUY || 
               OrderType()==OP_SELL) 
              {
               if(op<0 || OrderType()==op) 
                 {
                  if(mn<0 || OrderMagicNumber()==mn) 
                    {

                     _o_t=OrderOpenTime();

                     _pr=OrderOpenPrice();

                     _Ticket=OrderTicket();

                     _Type=OrderType();
                     ИмяФайла=_Ticket+Symbol()+".txt";
                     if(_o_t+60<TimeCurrent())
                        if(t_pre+60<TimeCurrent() && _o_t+1800>TimeCurrent())
                          {
                           if(_Type==OP_BUY){if(Bid>_pr)text_="P"; else text_="L";}
                           if(_Type==OP_SELL){if(Bid<_pr)text_="P"; else text_="L";}
                           t_pre=TimeCurrent();
                           string Текст,Строка;

                           // Открытие или создание файла и перемещение указателя в конец
                           int Файл= FileOpen(ИмяФайла,FILE_CSV|FILE_READ|FILE_WRITE," ");
                           if(Файл == -1)
                             {
                              Alert("Ошибка при открытии файла ",ИмяФайла);
                              return;
                             }
                           FileSeek(Файл,0,SEEK_END);

                           // Если новый файл записать строку заголовков колонок
                           if(FileSize(Файл)==0)FileWrite(Файл,"           Время Полу   BID     Цена ");

                           // Сбор информации и запись в файл
                           FileWrite(Файл,
                                     TimeToStr(TimeCurrent()),
                                     text_,
                                     dstr(Bid),
                                     "  ",
                                     dstr(_pr));
                           FileClose(Файл);
                           Файл=0;

                          }
                    }
                 }
              }
           }
        }
     }

   Comment("");
  }
// Преобразование числа double в строку с запятой или точкой в соответствии с локализацией
string dstr(double Цена)
  {
   if(!RUS) return DoubleToStr(Цена, Digits);
   return StringSetChar(DoubleToStr(Цена, Digits), StringFind(DoubleToStr(Цена, Digits), "."), ',');
  }


 
Artyom Trishkin:

That's the class.


Well, well, well. I've found another bug. I once had the MT4 terminal for development incompletely updated. The terminal version is 1090 and the editor version is 1562. On other terminals union compiles normally, editor's version is 1601! It must be because the editor was already open at the time of the update, so the old version was left. Man, I spent half a day on this garbage.

Anyway, everything compiles fine under editor 1601.

 
lil_lil:
Greetings.
I create a file named = ticket+symbol.
I write into the file the opening price of the position and the current price, the letter "P" or "L" depending on the location of the price.
It is necessary to write the data of those positions, the open time of which is not older than 30 min.
The problem is that the data is written only for one position, the latest one.
Writing into other files is not made. There are 4 positions.
How to solve it?

Skip FileSeek- search for the end of the file and after FileOpen it is written to the beginning every time

 

Alexey Volchanskiy:

Well, well, well. I've found another bug. I had my MT4 development terminal incompletely updated at the time. The version of the terminal is 1090 and the editor is 1562. On other terminals union compiles normally, editor's version is 1601! It must be because the editor was already open at the time of the update, so the old version was left. Man, I spent half a day on this garbage.

Anyway, everything compiles fine under editor 1601.

Well, good for you ;)

 
STARIJ:

you missed FileSeek() - search for the end of the file and after FileOpen it is written to the beginning every time

There isFileSeek(File,0,SEEK_END); and everything is written to the file from a new line.

The problem is that there are 4 files and you need to write data on four positions, each in a separate file, each file has a position ticket in the name, but data are written only to one, the last file, data on the last position.