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

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

Manage alerts

Loading saved threads...

Abbotton · External communityPost link
External question — Stack Overflow Stack Exchange Author: Abbotton Original post: https://stackoverflow.com/questions/71186638 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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.
Quote
Report
user3666197 · External communityPost link
External answer — Stack Overflow Stack Exchange Author: user3666197 Original post: https://stackoverflow.com/a/71189227 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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 );
Quote
Report
Tman · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Tman Original post: https://stackoverflow.com/a/71457591 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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));
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: user3666197 Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/71189227 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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 );

Cancel quote

Checking account access…