MT4 - Divide issue within indicator calculation

 

Hi all,


Starting to play around with custom indicators more and I've hit a roadblock with the divide issue. I'm calculating the spread difference between a synthetic price and its underlying (dividing the close price of 2 pairs less the underlying currency pair) which is then displayed as a moving average, in addition to this its also being used for a standard deviation calculation. When multiply 2 currency pairs everything works as expected but dividing seems to create incorrect values, any advice would be greatly appreciated :-)


double LivePrice(int k) {

double LivePrice =(iClose(ccy1, 0, k)-(iClose(ccy2, 0, k)/iClose(ccy3, 0, k)));
 
  1. Why did you post your MT4 question in the Root / MT5Indicators section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

    The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

  3. Use the debugger or print out your variables, including _LastError and find out why.

 

Hi,

Your code is incomplete,

And your parentheses are incorrect,i think you're trying such calculation like this:

double LivePrice =(iClose(ccy1, 0, k)-iClose(ccy2, 0, k))/iClose(ccy3, 0, k);

So clear more what is your main formula,