gpt4 book ai didi

How to get the number of decimal places for every Symbol() price(如何获取每个符号()价格的小数位数)

转载 作者:bug小助手 更新时间:2023-10-25 16:53:03 25 4
gpt4 key购买 nike



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?

某些货币对的值显示为小数点后5位(欧元兑美元),其他货币对为4位,以此类推。我编写了下面的代码,以返回小数位数减1的整数值。这个函数只考虑了几对。我想把它扩大到能满足所有人的需求。我如何才能找到每个符号()价格的小数位数?



int decimalPlacesForPairs()  {
if ((_Symbol == "XAUUSD") || (_Symbol == "USOIL")) {
return 1;
}

else if (_Symbol == "CADJPY") {
return 2;
}

else return 3;
}

更多回答
优秀答案推荐

In MQL4 you have access to a predefined variable int Digits. This function returns the number of digits after the decimal point.

在MQL4中,您可以访问预定义的变量int Digits。此函数返回小数点后的位数。



The example given is:

给出的例子是:



Print(DoubleToStr(Close[0], Digits));

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.

另一种方法,在您的情况下可能是更好的方法是使用MarketInfo。在这里,您可以通过将符号作为字符串变量插入来返回每个符号的小数位数。



The example given:

给出的示例如下:



int vdigits = (int)MarketInfo("EURUSD",MODE_DIGITS);

Int vdigits=(Int)MarketInfo(“EURU.S.”,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(){}:

并从您的main()调用{}:



void Main()
{
decimalPlacesForPairs(Symbol());
//or
//decimalPlacesForPairs("EURUSD");
}


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;





The only ones that aren't 5 decimals are yen pairs right? Just do a string search to see if it contains yen.

唯一不是5位小数的是日元对吧?只需进行字符串搜索,看看其中是否包含日元。


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)

注意:函数中的最后一个整数是您想要的点数(1/10个点数)


更多回答

This does not answer the problem. If one reads the O/P, the Question is explicit to say "expand it to cater for all pairs. How can I find the number of decimal places for each Symbol() price?"

这并没有解决这个问题。如果阅读O/P,问题很明确:“扩展它以满足所有配对的需求。我如何才能找到每个符号()价格的小数位数?”

Of course it does, depending on the context. If the user is planning on using this in an EA and loads it to a chart, the above WILL return the decimals for that product it has been loaded on.

当然,这取决于具体情况。如果用户计划在EA中使用它,并将其加载到图表中,则上面的代码将返回已加载的产品的小数。

This does not answer the problem. The code is missing an iterator, that would cover the requirement to "expand it to cater for all pairs" - i.e. for each Symbol() as provided by the Broker, part of which is listed in the Market Watch --- which part of the code is still missing ...

这并没有解决这个问题。代码缺少一个迭代器,该迭代器将覆盖“扩展它以满足所有对”的要求--即,对于经纪人提供的每个符号(),市场观察中列出了其中的一部分-代码的哪一部分仍然缺失……

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com