Thread: Ask!
View Single Post
  #939 (permalink)  
Old 01-18-2008, 09:49 PM
hiachiever hiachiever is offline
Member
 
Join Date: Jan 2006
Posts: 59
hiachiever is on a distinguished road
Need to use Digits

Quote:
Originally Posted by Dave137 View Post
PHP Code:

#property indicator_chart_window


double spread=Ask-Bid;
   
 
   
{
  
   
ObjectCreate("Spread_Label"OBJ_LABEL000);
   
ObjectSetText("Spread_Label"DoubleToStr(spread,0), 14"Ariel"Yellow);
   
ObjectSet("Spread_Label"OBJPROP_CORNER3);
   
ObjectSet("Spread_Label"OBJPROP_XDISTANCE50);
   
ObjectSet("Spread_Label"OBJPROP_YDISTANCE55);
  } 
I tried this but get a big '0' value on the graph. How do I get the indicator to place the spread on the graph of the currency it is being overlayed on?

Your wisdom and knowledge is needed!

Dave

Dave,

The problem is with this line of code.
ObjectSetText("Spread_Label", DoubleToStr(spread,0), 14, "Ariel", Yellow);

When using DoubleToStr the second option is rounding, ie how many decimal places to round to. In your case you are rounding a two or 4 decimal place number back to "Zero" decimal places.

See Below:
string DoubleToStr( double value, int digits)
Returns text string with the specified numerical value converted into a specified precision format.
Parameters:
value - Floating point value.
digits - Precision format, number of digits after decimal point (0-8).

The correct code should read:
ObjectSetText("Spread_Label", DoubleToStr(spread,Digits), 14, "Ariel", Yellow);
NOTE: Digits is an internal function that returns the number of decimal places for the current symbol.

This should now show you the Spread.

Cheers,
Hiachiever

Last edited by hiachiever; 01-18-2008 at 09:55 PM.
Reply With Quote