[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 212

 
Good afternoon to all.Two MAs are crossed many times on the chart.Is it possible to count the number of bars after EVERY MA crossing.After the last one it works, but after EVERY one it does not.Does anyone know how to do it?
 
MK07:
If we want to check the number of bars after EVERY MA crossing, we can calculate the number of bars after the last one, but after EVERY one it is not.

It depends on what you need it for. For an EA one algorithm, for an indicator - another.

Generally, approximately as follows: Let's create a variable in which we will store the number of crossings. You can create two variables - for up and for down, for example Intersection_UP andIntersection_DN.

Before the loop, we initialize them with zeros.

Create loop from the first bar to Bars: for (int i=1; i<Bars; i++) { // loop body where we count intersections ... }.

At each intersection on bar i ma1 from the bottom up ma2 increases Intersection_UP, at each intersection on bar i ma1 from the top down ma2 increases Intersection_DN.

At the end of the cycle we have in two variables the number of crossings up and down. Add them up to get the total number of intersections

 
MK07:
Good afternoon to all.Two MAs are crossed many times on the chart.Is it possible to count the number of bars after EVERY MA crossing.After the last one it works, but after EVERY one it does not.Does anyone know how to do it?

It is simple. You fix the crossover, and create a counter. When there's a crossover, the counter adds 1 bar per crossover. When there's a crossover, another counter starts counting.
 
alsu:

We do not understand each other, apparently

In general, the location of the problem is defined - the variable static.

But why does a function with this variable compiled in the same file with the indicator work without problems (reinitialization is successful and everything works fine), but when I address the same function placed in the library, I have problems?

Maybe there are some restrictions on the use of certain types in the library functions?

 
Hello?
 
polycomp:

In general, the location of the problem is defined - the variable static.

But why the function with this variable, compiled in the same file with the indicator works without problems (reinitialization is successful and everything works fine), but when I address the same function, placed in the library, there are problems?

Maybe there are some restrictions on the use of certain types in the library functions?



I'm not a developer and can only make guesses. So, I assume that when reinitializing after changing the parameters ex4 is not unloaded from the memory, and therefore on a new start we get the same copy of the library as before, with all the statics and their old values.

In idea all statics of the program should be initialized before calling init(). But the ex4 library is loaded only immediately at the moment of the first call of the library function, so no library statics get to the common heap.

Looking at the whole thing this way, the explanation is quite logical.

 

Here is theStringGetChar function https://docs.mql4.com/ru/objects/ObjectFind

Why is it needed at all?

According to the textbook, it returns the value of a character as a number. There,"c" corresponds to the value 99. How can I understand it? What use does this function have?

So it returns a number... ...and what does it do?

I want to learn to work with strings, so I came across this function. That's why I'm asking.

 
alsu:

I am not a developer and can only speculate. So, I assume that during reinitialization after parameter changes, ex4 is not unloaded from memory, so on new start we get the same copy of the library as before, with all the statics and their old values.

In idea all statics of the program should be initialized before calling init(). But the ex4 library is loaded only immediately at the moment of the first call of the library function, so no library statics get to the common heap.

Looking at the whole thing this way, the explanation is quite logical.


Thanks for the clarification! It looks like it's better not to use statics in libraries.
 

I have in my head an array of 3000 values of the same type.

But I don't quite understand how to initialize a one-dimensional array with these values.

I don't understand - should I specify all 3000 values separated by comma in assignment operator when initializing an array

int Mas_i[3000]= { (Bid>1.2153)&&(Bid<1.2160) , (Bid>1.2156)&&(Bid<1.2163) ...do I really need to list all 3000 expressions?}

Please give me a hint, or tell me where to read. I can't seem to find an answer to this question in the tutorial by S.Kovalev..... or I don't understand it.

Thank you.

 
hoz:

Here is theStringGetChar function https://docs.mql4.com/ru/objects/ObjectFind

Why is it needed at all?

According to the textbook, it returns the value of a character as a number. There,"c" corresponds to the value 99. How can I understand it? What use does this function have?

So it returns a number... ...and what does it do?

I want to learn to work with strings, so I came across this function. That's why I'm asking.


To write in the chart (not to be confused with the comment) must encode a numeric code. You write 99, the letter "s" will appear on the chart. I haven't done it yet, but you can find how to do it all in the Dock, and with what font, size, X and Y axis orientation in pixels, etc. If that's all you're missing already, go for it, but it will take a lot of time! Good luck!