How to store a price into a variable?

 

Hi everyone,

I tried to store a price value into a variable:

double price = Ask;

and then

Print("price", price);

to check if it be stored properly, but it seems not be stored,

the result shows 0.

Who can help me find a way to store a price value into a variable?

Thanks a lot.


 
are you sure this is exactly how you have it in your EA? maybe you can post more of the code to help clarify what is wrong.
 
yy169168 wrote >>

Hi everyone,

I tried to store a price value into a variable:

double price = Ask;

and then

Print("price", price);

to check if it be stored properly, but it seems not be stored,

the result shows 0.

Who can help me find a way to store a price value into a variable?

Thanks a lot.

price is double variable and to print u need to convert it to a string so

Print("price",DoubletoStr(price,2));

 
ronaldosim:

price is double variable and to print u need to convert it to a string so

Print("price",DoubletoStr(price,2));

I don't believe that's correct information, shouldn't be necessary to convert to string just to print unless you specifically only wanted to see the value to 2 decimals.


Any chance you're variable is being reset before it gets printed?

Have you tried just printing Ask?

Reason: