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

 
Can you tell me how to summarise all the values in the text?
void Hmin(){datetime   h = iBars(NULL,PERIOD_H1); 
       ObjectCreate(0,"Hmin"+h,OBJ_TEXT,1,TimeCurrent(),0);     
       double Hmin=ObjectDescription("Hmin"+h);     
       ObjectSetText("Hmin"+h,MathMin(Hmin,AccountEquity()-AccountBalance()),15,"Arial",clrWhite);
       ObjectSetInteger(0,"Hmin"+h,OBJPROP_ANCHOR,ANCHOR_RIGHT);  
           }
This code only creates them
 
Дмитрий:

Good afternoon, please help me to understand...

MathMax returns the maximum of two numeric values, i.e. it returns the maximum numeric value from two identical arrays high[rates_total] with a difference of -1 and -2 bars?

In simple words: In the first array 12345 and in the second 1234, will this function return 5?

No. The function will return 12345.

 
Дмитрий:

Good afternoon, please help me to understand...

MathMax returns the maximum of two numeric values, i.e. it returns the maximum numeric value from two identical arrays high[rates_total] with a difference of -1 and -2 bars?

In simple words: the first array has 12345 and the second has 1234, will this function return 5?

It will return the maximum value of the two, which are high[rates_total-1] and high[rates_total-2].

If address high[rates_total-1] contains value 12345, and address high[rates_total-2] contains value 1234, which of these two values is greater?

12345 is clearly greater than 1234 by an order of magnitude. The value 12345 of high[rates_total-1] will be returned.

 
Artyom Trishkin:

The maximum value of the two at high[rates_total-1] and high[rates_total-2] will be returned.

If address high[rates_total-1] contains value 12345, and address high[rates_total-2] contains value 1234, which of these two values is greater?

12345 is clearly greater than 1234 by an order of magnitude. The value 12345 of high[rates_total-1] will be returned.

Thanks... But there is a question about rationality of the string if high[rates_total-1] is already one bar greater than high[rates_total-2]

Or is there a different meaning here?

Thank you.

 
Дмитрий:

Thank you... but this raises a question about the rationality of the string if high[rates_total-1] is already one bar more than high[rates_total-2]

Or is there something else that makes sense here?

Thank you.

What do the bars have to do with it?

You are comparing high values on two bars of the same array. The rates_total-1 and rates_total-2 indicate which values of the two bars you are comparing.

You are comparing the High values of the bars located on rates_total-1 and rates_total-2, not the values of the indices.

What you are thinking of would look like this: MathMax(rates_total-1, rates_total-2) - this is where rates_total-1 will always be returned.

 
Rustam Bikbulatov:
Can you tell me how to sum up all the values in the text? This code only creates

do you want to get the balance minus equity values?

 
Artyom Trishkin:

What do the bars have to do with it?

You are comparing the values of High, which are on...

Thank you... For the clarification)
 

Good day to all!

In MT4, on the model ALL TIKES, on minute candlesticks, I test the Expert Advisor. My task is to make the program to spend as little time on code execution as possible. But what surprised me!!!!

In this code, the program checks every tick and spends 6 seconds for code execution. 375 milliseconds.

void OnTick()
{
Tick++;
if (Tick!=x3)
{
Print("---------------------КАЖДЫЙ ТИК ----------Tick-----=",Tick);
x3=Tick;
}
}

It seemed to me that the program should check not every tick, but only the first tick of each minute candle and spend much less time on code execution.

 
void OnTick()
{
Tick++;

if (Minute()!=x3)//&&Seconds()==0

{
Print("---------------------КАЖДЫЙ ТИК ----------Tick-----=",Tick, "  Bid  ",   Bid, "  LoY  ",   LoY);
x3=Minute();
}
}



But the program spent 6 sec. 219 msec. From this I came to the conclusion that even though the code tells the program to check the expression in brackets only once per 60 seconds, it still checks this expression at every tick and spends almost as much time for execution as in the previous code.
Then I changed the model to VALUABLE VALUES and ran the second variant. But the program took the same6 seconds to execute it.219 milliseconds.


QUESTION . Is it possible to make the program in MT4 on the model ALL TICK, check not every tick, and only the first tick of a new minute candle, that would spend much less time for code execution. If it is possible, what function or language construct may be used?
Thank you.

 
datetime current, last;

void OnTick()
   {
   current=iTime(symbol,frame,0);
   if(last==current) return;
   last=current;

   } 
 
Aleksei Stepanenko:

Changed my code to match your code

datetime current, last;
void OnTick()
{
Tick++;
current=iTime( NULL,0,0);
if(last==current) return;
last=current;
{
Print("---------------------КАЖДЫЙ ТИК ----------Tick-----=",Tick);
}
}


Time taken by the program to execute the code.... 6 , 235, i.e. less than with my code (6.375), but not several times less
. It seems to me it should be several times less, because the program only has to check tick value once at the opening of each minute candle.

Which one of us is wrong..... it seems to me.


Reason: