Download MetaTrader 5
To add comments, please log in or register
Sell products via the Market and track your sales statistics
trader24
35
trader24 2014.06.12 05:55 

Hi Guys, having issues with displaying the current spread (Bid - ask). It works fine for up to 4 decimals, but I need the spread to be displayed as 0.00005 for example.

My code is quite simple (please see below)

int start(){
        double ask_price = MarketInfo(Symbol(), MODE_ASK);
        double bid_price = MarketInfo(Symbol(), MODE_BID);
        double avg_price = (ask_price - bid_price);
if (MarketInfo(Symbol(), MODE_DIGITS) == 5) {
   Comment(StringFormat("Spread: %G",avg_price));  
        }
else
.........

What i've done so far:

Tried changing 'double avg_price = (ask_price - bid_price)' to float, long, etc but doesn't work.

I read on the forums about using DoubletoStr. Would it work and how would I be able to implement that?

Thanks and apologies if my question has been asked already.

Keith Watford
Moderator
7894
Keith Watford 2014.06.12 06:09  
jb1981:

I read on the forums about using DoubletoStr. Would it work and how would I be able to implement that?


DoubleToStr(avg_price,Digits)
//or
int d=MarketInfo(Symbol(), MODE_DIGITS)
DoubleToStr(avg_price,d)
whroeder1
13602
whroeder1 2014.06.12 13:11  
jb1981: displaying the current spread (Bid - ask). It works fine for up to 4 decimals, but I need the spread to be displayed as 0.00005 for example.
double spread = Ask - Bid;  // 5 digit   4 digit broker
                    // EURUSD    USDJPY  EURUSD    USDJPY
PriceToStr(spread)  // "0.00015" "0.025" "0.0001"  "0.02"
DeltaToPips(spread) // "1.5"     "2.5"   "1"       "2"
/
To add comments, please log in or register