Help with High Spread Values = 186.0 on USDZAR USDSEK

 

On the common currency pairs this spread code gives a correct value,

Yet on some pairs USDZAR, USDSEK I get a high spread value = 186.0

How to correct this? all help appreciated.

if (Digits == 3 || Digits == 5) nn = 10;

double spreadActual=(Ask-Bid)/Point/nn;
string spreadValue=DoubleToStr(spreadActual,1);

ObjectSetText("spreadValue",""+spreadValue+"",20,"Arial Bold",spreadColor);
 
  1. double spreadActual=(Ask-Bid)/Point/nn;
    Equivalent to pip=point*nn; (Ask-Bid)/pip.
  2. Unless you manually adjust your SL/TP for each separate symbol, using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points), and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 programming forum (2017)
              Slippage defined in index points - Expert Advisors and Automated Trading - MQL5 programming forum (2018)

 

Hello William, thank you for your reply and code,

From your code I have the code below, yet how to get the spread value to display?

ObjectSetText("spreadValue",""+spreadValue+"",20,"Arial Bold",spreadColor);
//=======================
bool     compute_pip(void){ // Requires MarketInfo, don't call in OnInit.
double   dvpl  = DeltaValuePerLot();                        // +Metals/exotics
         if(dvpl == 0)  return false;
double   gTS   = MarketInfo(_Symbol, MODE_TICKSIZE);
double   gPip  = gTS;   while(dvpl * gPip < 5)  gPip *= 10; //  USDMXN/USDZAR
double   gPipToPoint = (gPip / _Point);
double   gPipDigits  = (MathLog10(gPipToPoint) );
return true;
  }
double  DeltaValuePerLot(string pair=""){
    if (pair == "") pair = Symbol();
    return(  MarketInfo(pair, MODE_TICKVALUE)
           / MarketInfo(pair, MODE_TICKSIZE));
}
 //=======================
 
Ray Eagle #: yet how to get the spread value to display?

What part of (Ask-Bid)/pip was unclear?

 

Hi William, thank you, yes I think I have it,

double spreadActual=(Ask-Bid)/compute_pip();

But! No the resulting spread display is not correct, so I must have bungled it somewhere 😊

AUDUSD = Yes correct

EURUSD = Not = 0.0

EURJPY = Not

USDSEK & USDZAR = Not = 0.0

USDJPY = Not = 0.0