Digits Before Decimal Point Not Showing Spread Properly...

 

Hi,

I'm trying to make a spread indicator for Gold show appropriately but I have not been successful. The Gold price shows as for example 1545.50 (on IBFX) and the spread shows as 65. But its supposed to show as 6.5!

if(Digits==5||Digits==3) {dblPoints=Point*10;} else {dblPoints=Point;}
if(Digits==3) {SP1=Digits-2;} else {SP1=Digits-4;}
   
double SPRD=(Ask-Bid)/dblPoints;
string SPREAD=DoubleToStr(SPRD,SP1);

With the above code it shows the spread properly for all other pairs except for Gold (on IBFX), can someone please help me solve this issue?

I also tried variations of the codes below but those did not work either:

string number=DoubleToStr(Ask,2);
if(StringFind(number,".",0)==3)dblPoints=Point*100;
if(StringFind(number,".",0)==2)dblPoints=Point*1000;
if(StringFind(number,".",0)==1)dblPoints=Point*10000;

if(Digits==2||Digits==4) dblPoints=Point;
if(Digits==3||Digits==5) dblPoints=Point*10;
if(Digits==6) dblPoints=Point*100;
if(Digits==7) dblPoints=Point*1000;
if(Digits==8) dblPoints=Point*10000;
if(Digits==3) {SP1=Digits-2;} else {SP1=Digits-4;}
 

Make a special if for gold,

if (Symbol() == "Gold") do special stuff for gold;
 
Is there a way to make it work on all brokers by using numerical numbers instead of symbol names?
 
I was looking for the same thing some time ago ( https://www.mql5.com/en/forum/117053 ) but never found a good answer, my solution at the time doesn't work for all cases.
 
  1. On IBFX the Gold symbol is XAUUSD
    if (Symbol() == "Gold") do special stuff for gold;
    If you code correctly you shouldn't need any special stuff
  2. On the Navigator right click -> Online library -> All Market Data -> right click -> Download. Nav -> scripts -> all market -> execute It creates a html in experts/files about all the available pairs. Gold has Digits==2 and the spread when I ran it was 58. That is 58 points or $0.58. I have no idea where you get
    supposed to show as 6.5!

  3. if(Digits==3) {SP1=Digits-2;} else {SP1=Digits-4;}
    I'm not sure what your trying to do here, but my code would read:
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    }
    string  DeltaToPips(double d){
        if (d > 0)  string sign = "+";      else    sign = "";
        double pips = d / pips2dbl;
            string dPip     = sign + DoubleToStr(pips, 0);  if(Digits.pips==0) return(dPip);
            string dFrc     = sign + DoubleToStr(pips, Digits.pips);
            if (dPip+".0" == dFrc)          return(dPip);                   return(dFrc);              }
    string  PriceToStr(double p){
        string pFrc = DoubleToStr(p, Digits);       if(Digits.pips==0) return(pFrc);
        string pPip = DoubleToStr(p, Digits-1);
        if (pPip+"0" == pFrc)       return(pPip);           return(pFrc);          }
    int start(){ comment(Symbol(), " spread=", DeltaToPips(Ask-Bid), " pips or $", PriceToStr(Ask-Bid) ); }

 
WHRoeder:

On the Navigator right click -> Online library -> All Market Data -> right click -> Download. Nav -> scripts -> all market -> execute It creates a html in experts/files about all the available pairs.
Thank you, very useful thing to know about.
 

This may help some

//+------------------------------------------------------------------+

//| Spread.mq4 |

//| Copyright © 2009, Andriy Moraru |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2009, Andriy Moraru"

#property link "http://www.earnforex.com"


#property indicator_chart_window


extern color font_color = Magenta;

extern int font_size = 24;

extern string font_face = "Verdana";

extern int corner = 1; //0 - for top-left corner, 1 - top-right, 2 - bottom-left, 3 - bottom-right

extern int spread_distance_x = 10;

extern int spread_distance_y = 3;

extern bool normalize = false; //If true then the spread is normalized to traditional pips


double Poin;

int n_digits = 0;

double divider = 1;


//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//Checking for unconvetional Point digits number

if (Point == 0.00001) Poin = 0.0001; //5 digits

else if (Point == 0.001) Poin = 0.01; //3 digits

else Poin = Point; //Normal

ObjectCreate("Spread", OBJ_LABEL, 0,0,0 );

ObjectSet("Spread", OBJPROP_CORNER, corner);

ObjectSet("Spread", OBJPROP_XDISTANCE, spread_distance_x);

ObjectSet("Spread", OBJPROP_YDISTANCE, spread_distance_y);

double spread = MarketInfo(Symbol(), MODE_SPREAD);

if ((Poin > Point) && (normalize))

{

divider = 10.0;

n_digits = 1;

}

// ObjectSetText("Spread", "Spread: " + DoubleToStr(NormalizeDouble(spread / divider, 1), n_digits) + " ", font_size, font_face, font_color);

ObjectSetText("Spread", " " + DoubleToStr(NormalizeDouble(spread / divider, 1), n_digits) + " ", font_size, font_face, font_color);


return(0);


return(0);

}


//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

ObjectDelete("Spread");

return(0);

}


//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

RefreshRates();

double spread = (Ask - Bid) / Point;

//ObjectSetText("Spread", "Spread: " + DoubleToStr(NormalizeDouble(spread / divider, 1), n_digits) + " ", font_size, font_face, font_color);

ObjectSetText("Spread", " " + DoubleToStr(NormalizeDouble(spread / divider, 1), n_digits) + " ", font_size, font_face, font_color);

return(0);

}

//+------------------------------------------------------------------+

 
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
gets changed to
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }

Guntz use the SRC button for code:

Reason: