A newcomer asks! - page 26

 
Alexander Bereznyak:

these are your words, there are no warnings, but there really are

What world do you live in, what do you smoke, share

So you are so bold to claim for me about my code that you can't see it? Have you got the mushrooms wrong?
 
Dmitry Fedoseev:
So you so boldly assert for me about my code which you do not see? Are not you mistaken mushrooms?

I got it, not a fool, you have a special compiler without warnings, specially personally from MQ

PS: I want one too, let me use it.

 
Михаил:

The code you gave is not correct at all!

It should be like this:

ENUM_POSITION_TYPE pos_type = ENUM_POSITION_TYPE(PositionGetInteger(POSITION_TYPE));

Wrong, because then there's a comparison:

if(type==(long)POSITION_TYPE_BUY


No, it's not.

This has nothing to do with it.

The codewriter just overreacted or copied the type conversion from somewhere.


as a matter of fact

code

    long type=PositionGetInteger(POSITION_TYPE);
    if (type==POSITION_TYPE_BUY) return;

does not generate any error or warning.

MQL does not require an explicit conversion


PS. Test your assumptions before you start arguing.

 

a very bad example, you slip up on a comparison and then you run into error:

 
o_O:

PS. Test your assumptions before you start arguing.

Think of the consequences when making proposals
 
o_O:


No, you're not.

It has nothing to do with it.

The codewriter just overreacted or copied from somewhere else .


as a matter of fact

code

does not generate any error or warning.

MQL does not require explicit conversion


PS. Test your assumptions before you start arguing.

o_o!

Right - wrong....

I get the impression that you do not read what others write!

According to programming rules:

THE ACCEPTING FUNCTION VARIABLE MUST BE OF THE SAME TYPE AS THE RETURN VALUE OF THIS FUNCTION!

THAT'S IT!

This is the end of this speculation.

Why didn't you write it this way?

int type=PositionGetInteger(POSITION_TYPE);

Because you know that the function always returns LONG.

And the reference clearly says thatthe value returned for the argument POSITION_TYPE of thePositionGetInteger() function is

is ENUM_POSITION_TYPE, not LONG

And if you want to practice type casting, write it this way:

int type = int(PositionGetInteger(POSITION_TYPE));

if (type==POSITION_TYPE_BUY) return;

The fact that the compiler doesn't give you an error does not mean that you wrote it correctly!

It indicates the compiler's "free will" and that's all! (It allows you to compare LONG and INTEGER).

This is the RIGHT way to handle this situation:

 ENUM_POSITION_TYPE pos_type = ENUM_POSITION_TYPE(PositionGetInteger(POSITION_TYPE));
 
Alexander Bereznyak:

A very bad example, you missed the comparison, and then you will get an error:

Did you see somewhere about further with type conversion? Don't justify your theses by referring to a different subject of the discussion.

This is only about comparison and only in this case long is enum.


You already entered the thicket of thoughts, although the question was direct, which was answered by integer

Nextor257:

Please advise, I cannot understand what kind of comparison this is?

if(type==(long)POSITION_TYPE_BUY)

Why is (long) preceded by POSITION_TYPE_BUY ?


Dmitry Fedoseev:

This is a change of the variable type on the fly.

 
Dmitry Fedoseev:

long and lon instead ofENUM_POSITION_TYPE andENUM_POSITION_TYPE

8 characters (which you can type with your eyes closed) instead of 36 characters (and in uppercase)! On top of that there's all sorts of information that doesn't make sense. This is not a good programming style - unnecessary writing and redundant information.

In this case, Mikhail is absolutely right (With all my disgust at Mikhail's programming style).

And it's not about potential warnings and moreover about the number of characters, but about strict typing. The ENUM_POSITION_TYPE enumeration is a unique data type. It is ENUM_POSITION_TYPE, not long or int. You must use it as ENUM_POSITION_TYPE and in no other way. And if you type long, the auto-complete function will start at the third character, and there is no problem at all. And the problem is in using long, because it can be almost anything, while ENUM_POSITION_TYPE is not.

o_O:

MQL does not require an explicit conversion

At first I wrote that it does, but then I saw the word "comparison". Actually, no explicit conversion is needed in comparison because MQL does it implicitly. And it'd better not do it at all, because the result is often undefined. But in other normal strictly typified languages an explicit type conversion is always required.

P.S. For once Michael gave a competent answer, but people got accustomed to blaspheming him here too. And in vain, because he is right in this case.

 
How do I withdraw, please?
 
Mohamad Syahwal Tojiri #:
How do I withdraw, please?

You can withdraw earned funds from your MQL5 account here: https://www.mql5.com/en/users/syahwal/accounting/chooseout