[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 82

 
wolf05632:

Thank you, but it won't work for me. I don't need an offset. Above I wrote. Suppose for the first candle buffer[1]=Hight[1], for the third buffer[3]=Hight[3] and for the second one we need to calculate: buffer[2]=MathAbs(Higth[1]-Hight[3])/2 and get what I want in the picture.
And what don't you like my variant? :)) It's much simpler and less complicated. Or you need, that in a buffer remained values on each bar?
 

wolf05632:

SZY: How can I make an indicator work, i.e. make calculations (it WORKS, not visible) only on a certain timeframe (H1)?

You must bind the calculation not to the current timeframe, but to H1! :)) I.e. do not use arrays Open[], Close[], High[], Low[], Time[], but functions iOpen(), iClose(), iHigh(), iLow(), iTime() with relevant parameters...
 
MaxZ:
Why didn't you like my version? :)) Much simpler and less calculations. Or do you want to keep values in buffer at each bar?

I tried it, thank you, but it didn't work. I couldn't get it to show on the chart. I might have misunderstood something. The only thing I understood the main thing: elements in the buffer must go sequentially (1,2,3...), i.e. without any gaps (1,3,5...) and EVERY! element in the buffer must have a value assigned! :-)
 

Roman, thanks for the reply..... Unfortunately, I still don't understand one thing. In the textbook, https://book.mql4.com/ru/basics/expressions, under "Type Approach. Option 4.1. Calculating the result of an integer type

and Variant 4.2. A similar situation occurs if we look for a result as a value of a real type", the same formula is given, but in one case, the type of variable F is designated as int

   double A = 2.0;                      // Количество карандашей у Васи
   int    Y = 3;                        // Количество ответов Пети
   int    F = A + Y;                    // Общее количество

and in the second example, the variable is double

   double A = 2.0;                   // Количество карандашей у Васи
   int    Y = 3;                     // Количество ответов Пети
   double F = A + Y;                 // Общее количество

Unfortunately, I still don't understand the logic of the conversion. If in the first variant it is clear why int is assigned to variable F (i.e., according to rule of implicit type conversion), then why double.... is assigned in the second variant totally confuses me.

Please clarify what I may have missed in my explanations here?

Thank you in advance.

 
wolf05632:

I tried it, thank you, but it didn't work. It didn't show anything on the chart. Maybe I misunderstood something?

Did you copy the whole code or just what was in the start() function? It's important!

wolf05632:

The only thing I understood the most important: elements in the buffer must go one after another (1,2,3...), i.e. without gaps (1,3,5...) and EVERY! element in the buffer must have a value assigned to it! :-)
You got it wrong! :)) For example, the zig-zag does not have all elements of the buffer filled. Also, you don't have to fill all buffer elements for icons.
 
Geowind64:

Roman, thanks for the reply..... Unfortunately, I still don't understand one thing. In the textbook, https://book.mql4.com/ru/basics/expressions, under "Type Adduction. Option 4.1. Calculating the result of an integer type

and Variant 4.2. A similar situation occurs when looking for a result as a value of a real type", the same formula is given, but in one case, the type of the variable F is denoted as int

and in the second example, the variable is already a double

Unfortunately, I still don't understand the logic of the conversion. If in the first variant it is clear why int is assigned to variable F (i.e., according to rule of implicit type conversion), then why in the second variant they assigned double.... is completely confused me.

Please explain what I might have missed in my explanation.

Thanks in advance.



n


The interanger type is a duble type, the duble variable type has a wider range, so it is not possible that variables in an expression "have the possibility" of being of different types, and the result is a variable that has a narrower range of accepted values, in this case, the interanger type. I.e., if at least one variable in an expression is of type duble, the result must and can also be in the range of duble, otherwise there will be a compile-time error - type mismatch.

Please see here for details.

 
Roman.:


Integer is a duble type, and duble variables have a wider scope, so it is not possible for variables in an expression to "have the possibility" to be of different types, and the result is a variable which has a narrower range of accepted values, in this case, the integer type. I.e., if at least one variable in an expression is of type duble, the result must and can also be in the range of duble, otherwise there will be a compile-time error - type mismatch.

For more details, see here.


I often use implicit type conversion. But I have to use unnecessary parentheses.
 

Guys, what does #INF mean - is it out of allowed range of double? see second line from the top (it counts the product of double TWR, namely its previous value is multiplied by the next one). What is the correct way to count THOSE values taken by TWR variable?

 
Geowind64:

If you read this section of the textbook carefully, you will see that you must first look at the expression to the left of the assignment "=":

   A + Y

According to the rule:

  • if the type of the expression to the right of the assignment sign is not the same as the type of the variable to the left of the assignment sign, then the value of the expression is cast to the type of the variable to the left of the assignment sign; this is called a target type conversion;

A is a variable of type double to the left, and so the value of A+Y is a number of type double.

Next, pay attention to the type of variable to which the expression is assigned.

In the first case: "first the type of expression A+Y will be converted to int type (according to the rule of calculating integers), and then this result will become the value of the integer variable F".

In the second case: "the target type of variable F (to the left of the assignment operation sign), in this case the type double, is the same as the type double of expression A+Y, so no target type conversion occurs".

Verstehen? :)))

 
Roman.:

Guys, what does #INF mean - is it out of allowed range of double? see second line from the top (it counts the product of double TWR, namely its previous value is multiplied by the next one). How to correctly count THOSE values taken by TWR variable?

Generally INFINITY (INF for short ) is infinity! :)) Yes, it turns out that double lacks power (memory) to store such a huge number.

And how to calculate correctly, I can only guess... Create Own type, conditionally: store in an additional variable digit, and double multiply by 10^n, where n is digit capacity. But in this case, accuracy is lost, and I see that your accuracy is getting worse and worse...

But it may be simpler to change the logic of calculations? :))) Or maybe there's a mistake somewhere.