OnTick

 
Hello friends. How do we ensure that an operation is performed only once in the OnTick function.
 
Burhan Ozdemir:
Hello friends. How do we ensure that an operation is performed only once in the OnTick function.
By using OnTick(), each tick the EA will do what you want unlimited time.. 
In case you wish to do once or even more specified ticks then let me share some trick with you. 
Using the iVolume could support you when it is used with < operator. 
So:
if (iVolume(symbol, timeframe, shift) < 2) 
{
then do something;

Note that time frame most be the highest.
The shift most be 0

The above answer is not the professional solution, it is just a quick trick
 
Muhammed Abdulwadud Soubra # :
Onun tiklerini zaman zaman söylerken söyler.. 
Bir veya daha fazla belirlikene yapmak isterseniz, o zaman herkesle bir numara paylaşmama izin verin.
iVolume'u kullanmak, operatörden daha azıyla destek olabilir
Yani:
if (iVolume(sembol, zaman çerçeve, vardiya) < 2) o bir şeyler yapın
Thanks Bro I will try
 
Burhan Ozdemir: . How do we ensure that an operation is performed only once in the OnTick function.
You test for that
bool isFirstTick;
int OnInit(){ isFirstTick=true; … }
void OnTick(){
   if(isFirstTick){ isFirstTick=false; 
      // Only first tick.
   }
   // Every tick.
 

Mohammed Abdulwadud Soubra #:

if (iVolume(symbol, timeframe, shift) < 2) 

{
then do something;
  1. OPs question was doing something once, not once per bar.
  2. For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
              MT4: New candle - MQL4 programming forum #3 (2014)
              MT5: Accessing variables - MQL4 programming forum #3 (2022)

    I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
              Running EA once at the start of each bar - MQL4 programming forum (2011)

Reason: