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

 
Taras Slobodyanik #:

it is better to use IsVisualMode instead of IsTesting

You can do it without IsVisualMode and without IsTesting

The question was about something else

 

about magic=rand()

It's strange that the local tervers didn't exclaim "Yobtv"...

Since you study programming here, check how long it takes to fake it. What are the chances of getting a magic duplicate in more or less real conditions ? and is it worth stepping on such a rake

 
Valeriy Yastremskiy #:

This is also possible. The chances of a match are slim.

There's also an extra check for a match, so it's OK docks.

 
Maxim Kuznetsov #:

about magic=rand()

It's strange that the local tervers didn't exclaim "Yobtv"...

Since you study programming here, check how long it takes to fackup. What are the chances of getting a magic duplicate under more or less real conditions ? and is it worth stepping on such a rake

From reference:
"To ensure that you get a non-repeating sequence, use MathSrand(GetTickCount()), since GetTickCount() has been incrementing since the operating system started and will not be repeated for 49 days"

 
MakarFX #:
oh, that works, thanks... ahahh, only now the button is opening 150 orders every tick without stopping...

did so

if (IsTesting()) 
     {
      if(ObjectGetInteger(0,"button1",OBJPROP_STATE)==true)
        {
          ...
          ObjectSetInteger(0,"button1",OBJPROP_STATE,false);
        }
     }
 
Maxim Kuznetsov #:

it's strange that the local terver experts didn't exclaim with a chorus: "Yobtv"...

no one wants to persuade, no one wants to argue, let the man learn... he'll figure it out on his own

 
Maxim Kuznetsov #:

about magic=rand()

it's strange that local tervers didn't exclaim with a chorus "Yobtv"...

///

Duck, how many times?

 
Nerd Trader #:
oh that works, thanks... ahahh, only now the button has me opening 150 orders every tick without stopping...

did so

Do this

if (IsTesting()) 
     {
      if(ObjectGetInteger(0,"button1",OBJPROP_STATE)==true)
        {
          ObjectSetInteger(0,"button1",OBJPROP_STATE,false);
          ...
        }
     }
 

The script is from this thread.

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
enum EResult {Ok,AllocError};

template<typename T>
EResult GetRepeat(const T &arr[],T &ret[],uint count)
  {
   int size=ArraySize(arr);   // Присваиваем переменной количество элементов массива arr
   if(ArrayResize(ret,size)!=size)
      return AllocError;// Устанавливаем новый размер массиву ret, равный size
   int ii=0;
   for(int i=0; i<size;)
     {
      T tmp=arr[i];        // переменная перегруженной функции с значениями массива arr
      uint repeatCount=1;  // будем считать одинаковые подряд значения массива arr
      while(++i<size&&arr[i]==tmp) // если следующее значение то же
         ++repeatCount;              // плюсуем repeatCount
      if(repeatCount>=count)
         ret[ii++]=tmp;
     }
   return ArrayResize(ret,ii)==ii?Ok:AllocError;// новый размер массива ret
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   int si=0;
   int arr[]= {1,2,4,4,4,4,4,4,7,55,55,7,7,7,7,79,77,66,66,2,2,2,2,2};
   int ret[];
   if(!GetRepeat(arr,ret,cou))
      si=ArraySize(ret);
   for(int i=0; i<si; i++)
      Print(si," ret[i] =",ret[i]);
  }    
//+------------------------------------------------------------------+

I don't understand this line.

if(!GetRepeat(arr,ret,cou))

Why with "!" ? Why is the enumerated type selected?

 

I don't know why this is done, but it is essentially a boolean function.


The author must have thought of something like this:

The enum elements start with zero: Ok=0, AllocError=1

that is, GetRepeat returns either 0 or 1,

and in cp: 0 is false, 1 is true,

respectively ! GetRepeat is a negation of the return value


It's a head-scratcher, because it's so easy not to mess with your head and people's head:

bool GetRepeat(...)
   {
   ...
   return ArrayResize(ret,ii)==ii;
   }