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

 
Alexey Viktorov:

Artyom, I didn't start my answer with the words


The parabolic has strict alternation, two signals in one direction even on different bars are impossible. And you don't have to invent anything at all for that, it doesn't rattle even on zero bar, like the MA.

Rattling - I've noticed it more than once before. Maybe something has changed since then, but the point on the zero bar can disappear - it was.

I am proceeding as usual from the situation that later one may change the indicator for another one - and this block of code will already work independently - habit ...

 
Artyom Trishkin:
Would it help? I posted a template there, from which you can make yourself what you want.

Thanks, applied it roughly, but it still feels like it sometimes changes SL immediately when a trade is opened.
 
AlGuru:

Thank you, I applied it in an approximate way, but I still have a feeling that sometimes it changes SL immediately when a trade is opened.
Then you need to unwind SL values and put Print() inside the trawl too, so it would report about its work and the values it reaches - otherwise the feeling is just a feeling ;)
 
A question has arisen guys! Is there a limit to the number of digits in a magik number? How many digits should there be?
 
Rustam Bikbulatov:
Here is a question for you guys! Is there a limit to the number of digits in the magic number? How many digits should there be?


A magik is usually defined by an integer int type.

int

The integer int type has a size of 4 bytes (32 bits). Minimum value is -2,147,483,648, maximum value is 2,147,483,647.

Like this.

 
Alekseu Fedotov:


A magic is usually defined by the integer int type.

int

The integer int type has a size of 4 bytes (32 bits). Minimum value is -2,147,483,648, maximum value is 2,147,483,647.

Like this.


Thank you very much!
 

Hi all, I've written an EA and can't figure out the code. I need the function to run with every tick and every second of the server. I just called my function 2 times, throughOnTick and then throughOnTimer seems to have done everything correctly, but it still often misses a second and because of this sometimes does not work in the right moment. Help, who knows, would be very grateful). Perhaps because of a break in connection with the server ceases to work? Is it possible to make it run every second, even if there is a break in communication, and the seconds were strictly synchronized with the server time?


int OnInit()

  {

   EventSetTimer(1);

   return(INIT_SUCCEEDED);

  }

void OnTick()

{

Clicker (); //-- старт каждый тик

}

void OnTimer()

{

Clicker (); //-- старт каждую секунду

}

void Clicker()

  {

//--- тут идёт порядка 30 строк кода, вырезал чтобы никого не грузить

   Comment("Sek = " + (Seconds()));

   return;                                      // Выход из start()  

  }

 
My friends, please help a beginner MQL4 programmer with some advice.
I've written code that should determine the maximum Open price of the base for the last n bars, but for some reason the EA considers the maximum Open price of all the bars on the chart.

void OnTick()
{
   for (int i = 1; i <= BarTotal; i++)
   {
      double High_Open = iOpen(Symbol(), PERIOD_H1, i); 
      if (High_Open >= Current_High)
      {
         Current_High = High_Open;
         Print (Current_High); 
      }
   }
}

Thank you)

 
ivan-baaton:
Friends, please help a beginner MQL4 programmer with some advice.
I have written a code that should determine the maximum Open price of the base for the last n bars, but the EA for some reason considers the maximum Open price of all the bars on the chart.

...

Thank you)

Try a function like this:

//+------------------------------------------------------------------+
double GetMaxOpen(const string symbol_name,const ENUM_TIMEFRAMES timeframe,uint start_pos,const uint count){
   double array[];
   ResetLastError();
   if(CopyOpen(symbol_name,timeframe,start_pos,count,array)==count) return(array[ArrayMaximum(array)]);
   Print(__FUNCTION__," > Ошибка копирования в массив: ",GetLastError());
   return(WRONG_VALUE);
}
//+------------------------------------------------------------------+

I have not looked at it, practically wrote it on my own, so I might have missed something.

 

I have understood my error, but I have not understood how to solve it. The task is normally started every second, but the time from the beginning of the current candle is not counted correctly.

The Seconds() function outputs seconds from the data of the last known tick, but I need to somehow count the real number of seconds since the opening of the minute candle at the moment the function is called, even if there were no ticks at all for the last couple of seconds.

TimeSeconds (TimeLocal()) or ( TimeLocal() - Time[0]) will not work either, because the local time can differ from the server by several seconds. How to solve the problem?

Reason: