Precision problem with OBJPROP_PRICE

 

I'm trying to adjust the precision of what I get back on OBJPROP_PRICE within ObjectGet. But, it's not working. The code below does not adjust the precision to 4 as expected.

Am I doing something wrong?

string name1;

double normprice;

for(int i=0;i<ObjectsTotal();i++)

{

name1=ObjectName(i);

normprice=ObjectGet(ObjectName(i),NormalizeDouble(OBJPROP_PRICE1,4));

Print("Object #"+i+" name is "+"\""+name1+"\" and price is "+normprice);

 

Change your codes as below:

string name1;

double normprice;

for(int i=0;i<ObjectsTotal();i++)

{

name1=ObjectName(i);

normprice=NormalizeDouble(ObjectGet(ObjectName(i),OBJPROP_PRICE1),4);

Print("Object #"+i+" name is "+"\""+name1+"\" and price is "+normprice);

you can also replace "4" in Second NormalizeDouble function parameter with Digits, because in each currency pair, your digits are different and you sometimes you only want first 2 digits not 4

Good Luck

 
intelligent_14:
Change your codes as below:

string name1;

double normprice;

for(int i=0;i<ObjectsTotal();i++)

{

name1=ObjectName(i);

normprice=NormalizeDouble(ObjectGet(ObjectName(i),OBJPROP_PRICE1),4);

Print("Object #"+i+" name is "+"\""+name1+"\" and price is "+normprice);

you can also replace "4" in Second NormalizeDouble function parameter with Digits, because in each currency pair, your digits are different and you sometimes you only want first 2 digits not 4

Good Luck

U can use MarketInfo(Symbol(),MODE_DIGITS) to check what precision do u have on your currency and use it as a param to NormalizeDouble function.

If u will get something like : 1.2345000000 then just use DoubleToStr and then StringSubstr to cut those nulls.

 

I see where you moved the right paren over. But, that still doesn't work. I'm getting the same number of digits (all of them). Likewise, changing the param to Digits yields the same result.

intelligent_14:
Change your codes as below:

string name1;

double normprice;

for(int i=0;i<ObjectsTotal();i++)

{

name1=ObjectName(i);

normprice=NormalizeDouble(ObjectGet(ObjectName(i),OBJPROP_PRICE1),4);

Print("Object #"+i+" name is "+"\""+name1+"\" and price is "+normprice);

you can also replace "4" in Second NormalizeDouble function parameter with Digits, because in each currency pair, your digits are different and you sometimes you only want first 2 digits not 4

Good Luck
 

Are you saying that one needs to do this to adjust the precision rather than realy on the far-less verbose method of using either a precision number or Digits as the precision parameter within NormalizeDouble()?

I'm not getting the precision control within NormalizeDouble() to work and was hoping to not go the route of using string routines to trim the digits.

Kalenzo:
U can use MarketInfo(Symbol(),MODE_DIGITS) to check what precision do u have on your currency and use it as a param to NormalizeDouble function. If u will get something like : 1.2345000000 then just use DoubleToStr and then StringSubstr to cut those nulls.
 
billworld2:
I'm trying to adjust the precision of what I get back on OBJPROP_PRICE within ObjectGet. But, it's not working. The code below does not adjust the precision to 4 as expected.

Am I doing something wrong?

string name1;

double normprice;

for(int i=0;i<ObjectsTotal();i++)

{

name1=ObjectName(i);

normprice=ObjectGet(ObjectName(i),NormalizeDouble(OBJPROP_PRICE1,4));

Print("Object #"+i+" name is "+"\""+name1+"\" and price is "+normprice);

It should be like that:

normprice=NormalizeDouble(ObjectGet(ObjectName(i),OBJPROP_PRICE1),4);

 
billworld2:
I see where you moved the right paren over. But, that still doesn't work. I'm getting the same number of digits (all of them). Likewise, changing the param to Digits yields the same result.

Figured it out. In addition to fixing the placement of NormalizeDouble(), the the Print() line was off. Instead of:

Print("Object #"+i+" name is "+"\""+name1+"\" and price is "+normprice);

it needs to be:

Print("Object #",i," name is ","\"",name1,"\" and price is ",normprice);