Download MetaTrader 5

New to MQL4 programing. Advice on displaying spread (5 decimals)

To add comments, please log in or register
trader24
35
trader24  

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
9641
Keith Watford  
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
14779
whroeder1  
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