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

 
MakarFX #:

And if so

It took me a long time to figure out why your solution doesn't cause an infinite loop. Nevertheless, it also executes itself 1 time. But the above solution prompted me to create a boolean switch.
ulong ms=0;
bool msFlag=0;

void OnTimer(){
  if(msFlag!=0 && GetMicrosecondCount()-ms > 100000){
    ObjectSetInteger(0,"button1",OBJPROP_STATE,false);
    msFlag=0;
  }
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {
    if(id==CHARTEVENT_OBJECT_CLICK && sparam=="button1"){
      ms=GetMicrosecondCount();
      msFlag=1;
      } 
  }
Now the code is executed only when the button is pressed. But what happens if the terminal runs for several days? The help for another method returning time, it says that there will be an overflow.

ulong ms=0;
bool msFlag=0;

int OnInit()
{
    EventSetMillisecondTimer(1);
    ...
}

void OnTimer(){
  if(msFlag!=0 && Seconds() > 20){
    ObjectSetInteger(0,"button1",OBJPROP_STATE,false);
    msFlag=0;
  }
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {
    if(id==CHARTEVENT_OBJECT_CLICK && sparam=="button1"){
      msFlag=1;
      }
  }
The same code but with Seconds() instead of GetMicrosecondCount does not work. "Seconds() > 20" if higher - button freezes in "pressed" state. If lower - it works, but so fast that it's almost invisible (blinks).
 
Nerd Trader #:
Couldn't understand for a long time why your solution doesn't cause an infinite loop. Nevertheless, it also executes on its own 1 time. But the above solution prompted me to create a boolean switch.
Now the code is only executed when the button is pressed. But what happens if the terminal runs for several days? Help for another method returning time says an overflow will occur.

The same code but with Seconds() instead of GetMicrosecondCount does not work. "Seconds() > 20" if higher - button freezes in "pressed" state. If lower, it works, but so fast that it's almost unnoticeable (blinks).

Then it's like this

//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
      if(id==CHARTEVENT_OBJECT_CLICK && sparam=="button1")
         {ms=TimeCurrent();}
  }
//+------------------------------------------------------------------+
void OnTimer()
  {
   if(ms!=0&&TimeCurrent()>ms)
     {
      ObjectSetInteger(0,"button1",OBJPROP_STATE,false);
      ms=0;
     }
  }
//+------------------------------------------------------------------+
 
MakarFX #:

Then it's like this

No, it does not work that way, and if seconds do not work, TimeCurrent() all the more so. Mileseconds is the only workable variant so far, though it may cause an overflow.
 
Nerd Trader #:
No, it doesn't work that way, if seconds didn't work, then TimeCurrent() all the more so. So far, mile-seconds is the only workable variant, though it may cause an overflow.
It works!
 
MakarFX #:
It works!
mmm does not work for me: the button does not release on its own.
 
Nerd Trader #:
mmm doesn't work for me: the button doesn't release on its own.
The market is now closed, TimeCurrent() does not change. Check on crypto, it works on weekends
 
MakarFX #:
The market is now closed, TimeCurrent() does not change. Check on crypto, it's working on weekends
Crypto at my broker does not trade on weekends. Tried it in the tester - it doesn't work.
 
Nerd Trader #:
Crypto at my broker at the weekend is not trading. Tried it in the tester - it doesn't work.
Open A-Markets demo. The timer doesn't work in the tester.
 

Greetings, I'm getting an array.

int arr[]={6,4,6,7,55,55,7,6,77,66,66,2,2};

How do I change it so that all the numbers are present but without repeats?

int re[]={6,4,7,55,77,66,2};
 
Galim_V #:

Greetings, there is an array

How do I change it so that all the numbers are present, but without repetition?

You can do this without using libraries

int arr[]= {6,4,6,7,55,55,7,6,77,66,66,2,2};
int re[];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
  int AS=ArraySize(arr);
  int n=0;
  for(int i=0; i<AS; i++) {
    if(ArraySearch(re, arr[i])==-1) {
      n++;
      ArrayResize(re,n);
      re[n-1]=arr[i];
    }
  }
  ArrayPrint(re);
}
//===============================================================================================
//------------------------------ Функция удаляет копии с массива -------------------------------+
//===============================================================================================
int ArraySearch(int& m[], int e)
{
  for(int i=0; i<ArraySize(m); i++) {
    if(m[i]==e) return(i);
  }
  return(-1);
}
//+------------------------------------------------------------------+