I don't understand this line of code

 

What does this line of code do:

string Market_Price = DoubleToStr(Bid, Digits);


here is the full program:


//+------------------------------------------------------------------+
//| Magnified Market Price.mq4 ver1.4 by Habeeb |
//+------------------------------------------------------------------+
#property indicator_chart_window
//----
extern string note1="Change font colors automatically? True = Yes";
extern bool Bid_Ask_Colors=True;
extern string note2="Default Font Color";
extern color FontColor=Black;
extern string note3="Font Size";
extern int FontSize=24;
extern string note4="Font Type";
extern string FontType="Comic Sans MS";
extern string note5="Display the price in what corner?";
extern string note6="Upper left=0; Upper right=1";
extern string note7="Lower left=2; Lower right=3";
extern int WhatCorner=2;
//----
double Old_Price;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("Market_Price_Label");
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if (Bid_Ask_Colors==True)
{
if (Bid > Old_Price) FontColor=LawnGreen;
if (Bid < Old_Price) FontColor=Red;
Old_Price=Bid;
}
string Market_Price=DoubleToStr(Bid, Digits);
//----
ObjectCreate("Market_Price_Label", OBJ_LABEL, 0, 0, 0);
ObjectSetText("Market_Price_Label", Market_Price, FontSize, FontType, FontColor);
ObjectSet("Market_Price_Label", OBJPROP_CORNER, WhatCorner);
ObjectSet("Market_Price_Label", OBJPROP_XDISTANCE, 1);
ObjectSet("Market_Price_Label", OBJPROP_YDISTANCE, 1);
}
//+------------------------------------------------------------------+
 
if you move the caret above a function name and then press F1 you will immediately get a detailed description, much faster than posting a question on the forum.
 

The developer wishes Bid (which is a double variable containing the bid price of the current symbol) to be converted (with precision set to Digits which is an int variable representing the number of decimal places appropriate for the current symbol) to a string variable in order that it can be used in the ObjectSetText() function (which requires the 2nd parameter to be a string variable).


CB

 
cloudbreaker:

The developer wishes Bid (which is a double variable containing the bid price of the current symbol) to be converted (with precision set to Digits which is an int variable representing the number of decimal places appropriate for the current symbol) to a string variable in order that it can be used in the ObjectSetText() function (which requires the 2nd parameter to be a string variable).


CB


thank you CB but I'm still a little confused about "string Market_Price"..If Market_Price is a string (which to me means it represents characters), how can it represent the market price as it is so labeled (bid ask price is a number) ?

string Market_Price
 
x11115:

thank you CB but I'm still a little confused about "string Market_Price"..If Market_Price is a string (which to me means it represents characters), how can it represent the market price as it is so labeled (bid ask price is a number) ?

The name of the Market_Price variable is a bit misleading. It would have been better to name it something like Text_Market_Price, that conveys that it is a string and not the actual value. But note that it is not used for any calculations, it's only used in ObjectSetText() function to set the text of the label object "Market_Price_Label".

 

Think of it like this x11115

1. You type someone's phone number into your phone

2. You write down someone's phone number on a piece of paper


Now:

1. Is useful for actually calling the phone number

2. Can't be used for calling the number, but is useful for sticking in a shop window to advertise the number


In both cases, you call it "Joe Bloggs' phone number".


CB

 

What does this line of code do:

string Market_Price = DoubleToStr(Bid, Digits);

Bid
Print(Bid)
Print(DoubleToStr(Bid, Digits))
1.56789
1.5679 *
1.56789
1.56700
1.567
1.56700
1.50000
1.5
1.50000

* Print defaults to 4 digits of accuracy (rounded).

In your case you want the object text to read like the right column.

Reason: