Errors, bugs, questions - page 2226

 
Andrey Khatimlianskii:

Waiting in the KB ;)

The solution turned out to be much simpler than I thought.

An example of indicator, in which you can find out Timer's status. You just need to add one line #include <Timer.mqh> and OnTimer() under control.

#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#include  <Timer.mqh>

int OnInit()
  {
   if(iTimer.On) Print("Таймер включен, период таймера = "+IntegerToString(iTimer.curPer)+" миллисеккунд"); else Print("Таймер выключен");
   EventSetMillisecondTimer(2201);
   return(INIT_SUCCEEDED);
  }
////////////////////////////////////////////  
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   return(rates_total);
  }
///////////////////////////////////////////// 
void OnTimer()
  {
   if(iTimer.On) Print("Таймер включен, период таймера = "+IntegerToString(iTimer.curPer)+" миллисеккунд"); else Print("Таймер выключен");
   EventKillTimer();
   if(iTimer.On) Print("Таймер включен, период таймера = "+IntegerToString(iTimer.curPer)+" миллисеккунд"); else Print("Таймер выключен");
  }

And here is the class itself:

//+------------------------------------------------------------------+
//|                                                        Timer.mqh |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                         https://www.mql5.com/ru/users/nikolay7ko |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, Nikolay Semko"
#property link      "https://www.mql5.com/ru/users/nikolay7ko"
#property link      "SemkoNV@bk.ru"  

///////////////////////////////////////////////////////////////////////////
class CTimer
  {
public:
                     CTimer() {curPer=0; On=false;}
                    ~CTimer() {}
   bool              On;
   int               curPer;
   void              AddNewProgTimerSec(int per){EventSetTimer(per); curPer=per*1000; On=true;}
   void              AddNewProgTimerMilliSec(int per) {EventSetMillisecondTimer(per); curPer=per; On=true;}
   void              KillProgTimer() {EventKillTimer(); curPer=0; On=false;}
  };
///////////////////////////////////////////////////////////////////////////
static CTimer iTimer;

#define EventSetMillisecondTimer iTimer.AddNewProgTimerMilliSec
#define EventSetTimer iTimer.AddNewProgTimerSec
#define EventKillTimer iTimer.KillProgTimer
Result:
2018.07.12 21:10:37.177	TestСTimer (EURUSD.m,M5)	Таймер выключен
2018.07.12 21:10:39.385	TestСTimer (EURUSD.m,M5)	Таймер включен, период таймера = 2201 миллисеккунд
2018.07.12 21:10:39.385	TestСTimer (EURUSD.m,M5)	Таймер выключен
Files:
Timer.mqh  3 kb
 
Nikolai Semko:

The solution was much simpler than I thought.
...


I wanted to write about the level of coding in the community in general, but let's omit to avoid trouble...
In my opinion, a good way to solve the problem is to implement a singleton or static class, which implements timer control and provides the ability to "subscribe" to a timer event,
"subscription" is implemented by passing a pointer to a function to be called at certain intervals.

 

The trading results are different from the test on all ticks. Can you tell me where to dig - are the quotes overdrawn or what?

All ticks test - always gives the same result. Real trade - gives us extra trades on the same period.

The Expert Advisor has not turned off for 2 weeks. The test has also been running for 2 weeks. I have run it 50 times - it always gives the same result.

 
Anton Ohmat:

The trading results are different from the test on all ticks. Can you tell me where to look - are the quotes overdrawn or what?

All ticks test - always gives the same result. Real trading - gives extra trades on the same period.

The Expert Advisor has not stopped for 2 weeks. The test has also been running for 2 weeks. I ran it 50 times - it was always the same

Is the test performed using "all ticks" or "real ticks"?

 
For all ticks, the topmost parameter
 
Anton Ohmat:
For all ticks - topmost parameter

In "All ticks" mode, the ticks are modelled by the tester from the minute bars. Here is an article about the different test modes. https://www.mql5.com/ru/articles/2612

Тестирование торговых стратегий на реальных тиках
Тестирование торговых стратегий на реальных тиках
  • www.mql5.com
В данной статье мы покажем результаты тестирования простой торговой стратегии в 3-х режимах: "OHLC на M1" с использованием только цен Open,High, Low и Close минутных баров; затем детальное моделирование в режиме "Все тики", и самое достоверное тестирование в режиме "Каждый тик на основе реальных тиков" с использованием записанных тиков из...
 
just ran it - got the same result
 
Sergey Dzyublik:


I wanted to write about the level of coding in the community in general, but let's omit to avoid trouble...
In my opinion, a good way to solve the problem is to implement a singleton or static class, which implements timer control and provides the ability to "subscribe" to the timer event,
"subscription" is implemented by passing a pointer to a function to be called at certain intervals.

You must be a very good programmer if you say such sensible things. And thanks for the political correctness :)).
I certainly have a vision of how to create a handy polytimer. Your view has expanded my vision even further. Thank you.

 
Sergey Dzyublik:

the problem is solved through the implementation of a singleton

How can a singleton be implemented in MQL5?
 
fxsaber:

Error in FileLoad. If two local Agents with FILE_COMMON flag try to read data through FileLoad, one of the Agents fails.

It is possible to set appropriate flags in FileOpen, but not in FileLoad. Therefore, please allow access to the file via FileLoad if another FileLoad reads it.

How can these flags help you? Here is an examplehttps://www.mql5.com/ru/forum/1111/page1628#comment_2702870

Two Expert Advisors try to read datavia FileOpen (with the flag FILE_SHARE_READ ). Result:One of the Expert Advisors crashes


Ошибки, баги, вопросы
Ошибки, баги, вопросы
  • 2016.08.03
  • www.mql5.com
Общее обсуждение: Ошибки, баги, вопросы