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

 
Sergey Voytsekhovsky:

Yes, indeed. I hadn't noticed that. It looks better, there are fewer letters.

Is there no way to put three versions (I don't know how to say it correctly) under one operator?

Only curly braces - they limit the condition.

 
int a,b,c,d,e,f,g,j;
a=10;
b=5;
d=3;
f=4;
j=1;
a>b?{c=d;e=f;g=j}:{c=0;e=0;g=0};
Print("c=",c," e=",e," g=",g);

I tried to draw a construction like this, and the compiler spat something bad smelling at me. Where's the mistake?

 
Sergey Voytsekhovsky:

UURRAA, and the soul has sung. Alexey, thank you so much !!!!!

It all worked, I don't quite understand how it's possible to do without the array

because its description has been deleted. So you can do without the extra array here at all?


#property indicator_color3  clrGreen,clrRed

This is the array.

 
Sergey Voytsekhovsky:

Yes, indeed. I hadn't noticed that. It looks better, there are fewer letters.

Is there no way to put three versions (I don't know how to say it right) under one operator?

Yes, we can. Create two user-defined functions and call them.

int m = 5;//0;//
m = m == 0 ? f1 : f2;

int f1()
 {
  return(1);
 }
int f2()
 {
  return(2);
 }
 
Konstantin Nikitin:

That's what I'm saying. All right, we're through. As long as he knows what's going on...

I got it, thanks.
I'm just confused. This is all new to me.

 
Alexey Viktorov:

You can. Create two custom functions and call them.

Did I understand you correctly?

ColorHistogram_2Colors[i]=ExtMainBuffer[i]>=50?ColorUp(i):ColorDown(i);
//+------------------------------------------------------------------+ 
int ColorUp(int i)
 {
   ColorHistogram_2Buffer1[i]=50;
   ColorHistogram_2Buffer2[i]=ExtMainBuffer[i];
  return(0);
 }
int ColorDown(int i)
 {
   ColorHistogram_2Buffer1[i]=ExtMainBuffer[i];
   ColorHistogram_2Buffer2[i]=50;
  return(1);
 }

I did so in the indicator - it works.

 
Sergey Voytsekhovsky:

Did I understand you correctly?

I prescribed it so in the indicator - it works.

If it works, it's right. But I would not do it that way.

First of all, I wouldn't make changes of buffers. It is enough to always write 50 in one of them without any conditions.

And in the second buffer to put the value greater or less than 50. Then at condition <=> only colour should be appointed. And no separate functions.

 
Alexey Viktorov:

If it works, it's right. But this is not how I would do it.

First of all, I would not make a fancy change of buffers in which =50. It is enough to always write 50 in one of them without any conditions.

And in the second buffer to set the value greater or less than 50. Then at condition <=> you will have only to assign colour. And no separate functions.

I would agree with you if the condition <>50 defines only colour, but it is the beginning/end of histogram candle as well. Therefore I won't argue, I will try to check, though probably you are right.

 
Alexey Viktorov:

If it works, it's right. But that's not how I would do it.

Yes, indeed, either of the two DRAW_COLOR_HISTOGRAM2 buffers defining the start/end of the candle can be either the start or the end. Everything is much simpler now:

   ColorHistogram_2Buffer1[i]=50;
   ColorHistogram_2Buffer2[i]=ExtMainBuffer[i];
   ColorHistogram_2Colors [i]=ExtMainBuffer[i]>=50?0:1;

Thanks for the science.

 

How to reset INDICATOR_MAXIMUM and INDICATOR_MINIMUM values when switching modes?

The point is that these values are used in one mode and not in the other. When switching the mode to the one where these maxima and minima are not needed, they are saved for some reason. This problem exists both in MQL4 and MQL5.

For instance, when running the indicator in the first mode the boundaries are not necessary and everything works correctly

The second mode sets the boundaries of maximum and minimum of the indicator window. Everything works correctly when switching from the first to the second mode


But when switching from the second mode to the first (the boundaries are not used in the first mode) these maxima and minima are saved and the user cannot see the real indicator values


The code in MQL4 is in the attached files

Has anyone encountered this problem? Does anyone have any idea how to solve it?

Files:
test.mq4  4 kb