【问题标题】:MQL4: How to convert the value of iHigh() - iLow() to integer?MQL4:如何将 iHigh() - iLow() 的值转换为整数?
【发布时间】:2022-03-13 22:36:27
【问题描述】:
  double _high = iHigh(Symbol(), Period(), 0);
  double _low = iLow(Symbol(), Period(), 0);
  double result = _high - _low;

对不起,我的英语有限。

结果的类型是double数字,我想把双精度数转换成整数,但是每个符号对应的结果小数点后的位数不确定。

我真的不知道该怎么做,除了根据符号做不同的事情。

【问题讨论】:

    标签: algorithmic-trading mql4 mql mt4


    【解决方案1】:

    问: “如何将iHigh() - iLow() 的值转换为整数?
    ...根据符号不同做不同的事情。"

    A :
    是的,我们需要以不同的方式进行操作,具体取决于每个符号。

    这样的事情可能是一种处理方式:

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

    【讨论】:

      【解决方案2】:

      主要是将 NomalizeDouble 添加到结果中并在括号中添加 Digits 以总结所有内容:

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

      【讨论】:

      • 恕我直言,尝试"add Digits" 不会将双精度转换为整数。如果有疑问,给定一个工具有 _Digits == 5 和 aPriceDomainVALUE == 1827.604 ...添加这些是 (a) 仍然是双倍 1833.604 和 (b) 这样的总和并不代表任何意义
      猜你喜欢
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 2016-04-01
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多