How to get the number of decimal places for every Symbol() price

How to get the number of decimal places for every Symbol() price

Manage alerts

Loading saved threads...

TenOutOfTen · External communityPost link
External question — Stack Overflow Stack Exchange Author: TenOutOfTen Original post: https://stackoverflow.com/questions/58199458 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Certain Currency pairs display values to 5 decimal places (EURUSD), others 4 and so on. I wrote the code below to return the integer value of the decimal places minus one. This function just takes into consideration a few pairs. I would like to expand it to cater for all pairs. How can I find the number of decimal places for each Symbol() price? int decimalPlacesForPairs() { if ((_Symbol == "XAUUSD") || (_Symbol == "USOIL")) { return 1; } else if (_Symbol == "CADJPY") { return 2; } else return 3; }
Quote
Report
DDV · External communityPost link
External answer — Stack Overflow Stack Exchange Author: DDV Original post: https://stackoverflow.com/a/58199798 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. In MQL4 you have access to a predefined variable int Digits . This function returns the number of digits after the decimal point. The example given is: Print(DoubleToStr(Close[0], Digits)); Another way, and perhaps a better way in your case is to use MarketInfo . Here you can return the number of decimals places per symbol by inserting the symbol as a string variable. The example given: int vdigits = (int)MarketInfo("EURUSD",MODE_DIGITS); In your case you could have a function like the below: int decimalPlacesForPairs(string sPair) { return MarketInfo(sPair),MODE_DIGITS); } And to call from your Main(){} : void Main() { decimalPlacesForPairs(Symbol()); //or //decimalPlacesForPairs("EURUSD"); }
Quote
Report
King Trinity · External communityPost link
External answer — Stack Overflow Stack Exchange Author: King Trinity Original post: https://stackoverflow.com/a/58574873 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Place your Digits or Pips in the global area. double pips; double ticksize = MarketInfo(NULL,MODE_DIGITS); if(ticksize==2||ticksize==3||ticksize==4||ticksize==5) pips=ticksize*10; else pips =ticksize;
Quote
Report
Bodhi Mantra · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Bodhi Mantra Original post: https://stackoverflow.com/a/77076092 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. The only ones that aren't 5 decimals are yen pairs right? Just do a string search to see if it contains yen. string pair="USDJPY"; if(StringFind(pair,"JPY",0)>0) { //Do stuff with 3 decimals } else { //Do stuff with 5 decimals } Or this will do it for you string pair="USDJPY"; double onePip = MarketInfo(pair,MODE_POINT)*10; double fourPips = MarketInfo(pair,MODE_POINT)*40; note: the last integer in the function is how many pips you want in points (which are 1/10th of a pip)
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: DDV Source score (net votes, not local likes): 2 Original post: https://stackoverflow.com/a/58199798 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. In MQL4 you have access to a predefined variable int Digits . This function returns the number of digits after the decimal point. The example given is: Print(DoubleToStr(Close[0], Digits)); Another way, and perhaps a better way in your case is to use MarketInfo . Here you can return the number of decimals places per symbol by inserting the symbol as a string variable. The example given: int vdigits = (int)MarketInfo("EURUSD",MODE_DIGITS); In your case you could have a function like the below: int decimalPlacesForPairs(string sPair) { return MarketInfo(sPair),MODE_DIGITS); } And to call from your Main(){} : void Main() { decimalPlacesForPairs(Symbol()); //or //decimalPlacesForPairs("EURUSD"); }

Cancel quote

Checking account access…