简体   繁体   中英

MQL4: How to convert the value of iHigh() - iLow() to integer?

  double _high = iHigh(Symbol(), Period(), 0);
  double _low = iLow(Symbol(), Period(), 0);
  double result = _high - _low;

Excuse my limited English.

The type of result is a double number, and I want to convert the double number to an integer number, but the number of digits after the decimal point of the result corresponding to each symbol is uncertain.

I really don't know what to do other than doing it differently depending on the symbol.

Q: "How to convert the value of iHigh() - iLow() to integer?
... doing it differently depending on the symbol. "

A:
Yes, we need to do it differently, depending on each the symbol.

Something like this may be a way to handle this:

...
int iSymbolSpecificDIGITs = SymbolInfoInteger( Symbol(), /* here, or
                                          OrderSymbol(),          if looping OrderBook */
                                               SYMBOL_DIGITS
                                               );
...
int iHiLoDIFF = (int)( MathPow( 10, iSymbolSpecificDIGITs ) * _high )
              - (int)( MathPow( 10, iSymbolSpecificDIGITs ) * _low  );

Main thing is to add NomalizeDouble to the result and add Digits in the bracket to sum everything up:

 Alert(NormalizeDouble(result,Digits));

Or 

Print("result:" + NormalizeDouble(result,Digits));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM