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

 

I'm trying to figure out my counter and rewrite it in classes, but I still can't output the working parallel functions. I think m_pause should be declared differently. How should it be done correctly?


#ifdef __MQL4__
#endif 
//+------------------------------------------------------------------+
//| Счётчик                                                          |
//+------------------------------------------------------------------+
class CCounter
  {
private:
   //--- Шаг счётчика
   int               count;
   //--- Счётчик 
   int               chekcount;
   //---      
   int               m_pause;

public:
   //--- Проверяет прохождение указанного временного интервала 
   int               CheckCounter(const int pause);

   void ZeroCounter(void){count=0;chekcount=0;}
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CCounter::CheckCounter(const int pause)
  {
   m_pause=pause;
   count++;
   Print(" Class    count= ",count);
   Print(" Class    pause= ",pause);
   Print(" Class    m_pause= ",m_pause);

   if(count>=chekcount+m_pause)
     {
      chekcount=count;
     }
   return(chekcount);
  }
//+------------------------------------------------------------------+
#include <Test_Class_Tmier_libr_1.mqh>
CCounter TC;

void OnTick()
  {
Print("0 TC.CheckCounter(10)= ",TC.CheckCounter(10));   
Print("1 TC.CheckCounter(15)= ",TC.CheckCounter(15));
}

 
Nauris Zukas:

I'm trying to figure out my counter and rewrite it in classes, but I still can't output the working parallel functions. I think m_pause should be declared differently. How should it be done correctly?


You need to check it in the timer.

And there should be two CCounter objects - each for a different counter.

 
Artyom Trishkin:

The timer has to be checked.

Thanks, but I don't understand why the timer needs to check? For every tick the Expert Advisor accesses the CCounter and counts the ticks "count++".

 
Nauris Zukas:

Thanks, but I don't understand why the timer needs to be checked? For every tick, the EA accesses the CCounter and counts the ticks "count++".

So it's not in the timer...

 
Artyom Trishkin:

And there must be two CCounter objects - each for its counter.

Not sure what you mean by "two CCounter objects". I read the article https://www.mql5.com/ru/articles/351, it says "Once loaded, the class becomes an object". Does it mean I'll have to make copies of classes for each counter? So it turns out the same copies with different names that I can do without classes? The goal was to get rid of copying using classes, because I need more than a hundred of them. I was told that it's possible to do it with a class, so I started messing around with classes. Or what am I saying about "two CCounter objects"?

Vitaly Muzichenko 2017.09.26 15:43 RU
Nauris Zukas:

Stuck, it seems to me, in such a simple place. What to do with global int chekcount=0; int count=0; in case I want to run several counter() functions in parallel?

Just use a class or make copies of functions with different names.

Основы объектно-ориентированного программирования
Основы объектно-ориентированного программирования
  • 2011.12.06
  • Dmitry Fedoseev
  • www.mql5.com
На самом деле все намного проще. Чтобы пользоваться ООП вовсе не нужно знать, что означают эти слова - можно просто использовать предоставляемые ООП возможности, даже не зная как они называются. Но все же, надеюсь, в процессе прочтения статьи все желающие не только научатся использовать ООП в достаточной мере, но и разъяснят себе значения этих...
 
Nauris Zukas:

Not sure what you mean by "two CCounter objects". I read the article https://www.mql5.com/ru/articles/351, it says "Once loaded, the class becomes an object". Does it mean I'll have to make copies of classes for each counter? So it turns out the same copies with different names that I can do without classes? The goal was to get rid of copying using classes, because I need more than a hundred of them. I was told that it's possible to do it with a class, so I started messing around with classes. Or what am I saying about "two CCounter objects"?

Vitaly Muzichenko 2017.09.26 15:43 RU

Only use a class, or make copies of functions with different names.

Just create as many class objects as you need. And use each one for your counting.
CArrayObj is for you
 
Artyom Trishkin:
Just create as many class objects as you need. And use each one for your counting.
CArrayObj to help you

Thank you, I will read what this CArrayObj is and try to figure it out. :)

 

How do I create a one-dimensional array of the prices of all open orders? This is probably a very simple question for you, but please advise)

 
vikzip:

How do I create a one-dimensional array of the prices of all open orders?

Go through all the orders in a loop and write the open prices into the array.

 
Alexey Viktorov:

Go through all the orders in the loop and write the opening prices in the array.


Thank you!

Reason: