POSITION_PRICE_OPEN and POSITION_PRICE_CURRENT always 0.0

 

Hello, 


I would like to have the open price and the current price of my open position but when I have a trade the posCurrent and posOpen are always equal to 0.0


Can you help me ? 

Thank you very much

Files:
bollingers.mq5  16 kb
 
Kl JJ:

Hello, 


I would like to have the open price and the current price of my open position but when I have a trade the posCurrent and posOpen are always equal to 0.0


Can you help me ? 

Thank you very much

You have the same variables declared twice. First time in the global scope, and you use them for Comment, and another time in your loop where you get the position's parameters. So, for MT they are different variables, even though for you they are the same :).

Start with printing / logging directly from your loop.

Remove the first declaration, from the global scope. It really makes no sense.

 
Andrey Barinov #:

You have the same variables declared twice. First time in the global scope, and you use them for Comment, and another time in your loop where you get the position's parameters. So, for MT they are different variables, even though for you they are the same :).

Start with printing / logging directly from your loop.

Remove the first declaration, from the global scope. It really makes no sense.

Thanks for the help !
 

Andrey Barinov is right.

Just a quick tip- the compiler will issue a warning for this sort of cases,

So next time just pay attention to that, and you should be fine.


In a different matter-

You also have a 'bug' in your 'count open position' loop.

You iterate thru the open positions, and get their ticket number,

But you never actually select the order,

So your loop keeps counting the same order you've selected previously in your code.


Hope I am clear enough.

I am not a native English speaker.


Cheers mate.