Quote:
Originally Posted by Dave137
PHP Code:
#property indicator_chart_window
double spread=Ask-Bid;
{
ObjectCreate("Spread_Label", OBJ_LABEL, 0, 0, 0);
ObjectSetText("Spread_Label", DoubleToStr(spread,0), 14, "Ariel", Yellow);
ObjectSet("Spread_Label", OBJPROP_CORNER, 3);
ObjectSet("Spread_Label", OBJPROP_XDISTANCE, 50);
ObjectSet("Spread_Label", OBJPROP_YDISTANCE, 55);
}
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