Pip calculation for Forex, Stocks, and Exotic Forex Not Working

 

Hey guys I am trying to build an Expert Advisor that simply sets a StopLoss and a TakeProfit based on a set number of pips. Not that complicated.

But why in the world is it nearly impossible to do it perfectly for every currency pair and stock?

My code is below: 

double ticksize = MarketInfo(Symbol(), MODE_TICKSIZE);
if (ticksize==0.00001 || ticksize==0.001 || ticksize == 0.1) {
   pips = ticksize * 10;
} else if (ticksize == 0.01 || ticksize == 0.0001) {
   pips = ticksize * 100;
} else {
   pips = ticksize;
}

Then whenever I am calculating my StopLoss price I use the following (based on a StopLoss of 30 pips): 

double StopLoss_Price = Ask - StopLoss*pips;

My problem is that this works fine for things like GBPUSD, USDJPY, etc.

This also works now for FTSE100 and other indexes.

But for the super exotic pairs like USDZAR it is off. Especially for things like the spread. 

Does anyone have code that they use in their EA's that gives you the correct pip value no matter what you are using?

 
footfairy11: But for the super exotic pairs like USDZAR it is off. Especially for things like the spread.

          How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum
          Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum