[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 321

 
hoz:

https://www.mql5.com/ru/forum/144705 Here, I've started a separate thread. It has all the details of what is needed.


Yes, it is more fun with full source. Immediately visible, what from where and where passes, what the hell and how many times. Well, that's what immediately caught my eye:

hoz:
int GetStateOfMA()
{
   if (GetMA(1) > GetMA(2))
   {
       pr ("GetStateOfMA() = CROSS_UP");
       return (CROSS_UP);
   }
       
   if (GetMA(1) < GetMA(2))
   {
       pr ("GetStateOfMA() = CROSS_DN");
       return (CROSS_DN);
   }
       
    pr ("GetStateOfMA() = CROSS_NO");
    return (CROSS_NO);
}

You can simplify it down to practically one line:

int GetStateOfMA(){
   if(GetMa(2)==GetMa(1)) return(0); else return(MathAbs(GetMA(2)-GetMA(1))/(GetMA(2)-GetMA(1)));
}

Here we return zero or the sign of the difference (plus or minus). See: the modulus of a number divided by the number itself is practically the same as dividing a number by a number, i.e. one, only if the number was negative, naturally minus one is returned.

Figuring it out further.

 
gyfto:


Yes, it is more fun with full source. Immediately visible, what from where and where passes, what the hell and how many times. Well, that's what immediately caught my eye:

can be simplified to almost one line:

Here we return zero or the sign of the difference of values (plus or minus). See: the modulus of a number divided by the number itself is almost the same as dividing a number by a number, i.e. one, only if the number was negative, naturally minus one is returned.

Figuring it out further.


How easily you compare two real numbers
 
gyfto:


Yes, it is more fun with full source. You can see at a glance what is passed from where and where, what the hell and how many times. Well, that's what immediately caught my eye:

can be simplified to almost one line:

Here we return zero or the sign of the difference of values (plus or minus). See: the modulus of a number divided by the number itself is almost the same as dividing a number by a number, i.e. one, only if the number was negative, naturally minus one is returned.

I'll look into it further.

Yes, it makes sense. But why do I have to go through all this trouble? :)gyfto, I see that you, by the way, like me, tend to universalize everything. I'd say more. Here you can add a variable for the size of the deviation, and thus filter out small crossings of averages. It's sort of all understandable, but readability will not be particularly handy. After all, the function value will need to be compared to 0. Like <0 or >0.

Vinin:

How easily you compare two real numbers.

Well, if we're not interested in the variance, what's stopping us? Where is that stipulated?
 
Vinin:

How easily you compare two real numbers

You mean that double divided by double will still be double, and return can only return int? Well, you can locally define int temp; and assign to it, and return(temp);
 
gyfto:

In the sense that double divides by double will still be double, and return can only return int? Well, you can locally define int temp; and assign to it, and return(temp);
Two floating-point numbers obtained after calculation will almost never be equal. Or rather, more often they won't be equal, when you think they should be equal.
 
gyfto:

and return can only return int?

No. You can return whatever you want. Not necessarily int. After all, if the function is of type double, how will you return int from it?
It does not make any difference in principle, the main thing is to return from a function of a certain type, the same return. This is how I understand it.

Zhunko:
Two floating-point numbers obtained after calculation are almost never equal. Or rather, more often they won't be equal, when you think they should be equal.

So do you have to constantly set some variable dist to compare the difference between the mashups you're comparing? I mean like:

extern dist = 0.1 // Расстояние между сравниваемыми машками.
//---------------------------
GetMA(2) - GetMA(1) >= dist;
 
hoz:

a tendency to make everything universal.


No, according to my psychology, as I analyze myself, it's more a desire to make a program for people, not just for myself.

hoz:

Why get so twisted?


You probably won't believe me, but it's a lack of schooling. I'm sorry. The thing is, when I left school (6th grade), kids that age still have a vivid childlike curiosity, a thirst for knowledge. Then, in high school, the school system kills all that. I'm now in my thirties, but I still have that lively curiosity and I'm still not aware of those conditional restrictions, I'm not aware of what is "tinny" and what is "kinky", because for me it's all "tinny". Sorry...

hoz:
Zhunko:
Two floating point numbers, obtained after calculation, will almost never be equal. Or rather, more often they won't be equal, when you think they should be.


So is it necessary to constantly set some kind of variabledist to compare the difference between the mashups being compared? I mean like:

extern dist = 0.1 // Расстояние между сравниваемыми машками.
//---------------------------
GetMA(2) - GetMA(1) >= dist;
Yeah, that's right, that's logical.
 
gyfto:

You probably won't believe me, but it's the lack of schooling that's coming out. Sorry. The fact is that when I left school (6th grade), children of that age still have a vivid childlike curiosity, a thirst for knowledge. Then, in high school, the school system kills all that. I'm now in my thirties, but I still have that lively curiosity and I'm still not aware of those conditional restrictions, I'm not aware of what is "tinny" and what is "kinky", because for me it's all "tinny". Sorry...


In fact, I am kind of educated, but I taught only what I needed, ignored the rest purely. It turned out that I wasn't interested in a lot of things and turned away from those trivial things (history, geography, etc.). I don't think so myself, not like others. But your approach is really peculiar. I immediately thought that your education is not lacking, but on the contrary, it is something like that. Because I did not immediately understand everything from the above analyses.
 
hoz:
The approach is peculiar.


Let me explain in other words: it's self-taught, I've been self-taught all my life, so I do NOT know what approach you have adopted. I do NOT know what is accepted by you, what is not.

OK, back to the candles. Suppose we have i_AnyBarsToHistory = 30, i_ѕеqceptBarsConnt = 3. If in a window of 30 candlesticks cntUp == i_ѕеԛceptBarsCount and cntDn == i_ѕеԛceptBarsCount one time, then what should happen? Or does it always count only one counter per pass?

Yes, and why do we exit the loop prematurely before reaching Close[1].

 

Help, I can't figure out how to make an indicator compare a given number of recent bars and calculate how many of them were up, how many were down and how many were pinbars and who had what prices closed/open, high/low and volumes?

We need to do this specifically in the indicator.

Reason: