【问题标题】:MQL4 Error: " '}' - not all control paths return a value"MQL4 错误:“'}' - 并非所有控制路径都返回值”
【发布时间】:2021-05-22 05:42:00
【问题描述】:

一直在“包含”文件中执行此代码。但是我遇到了错误“不是所有的控制路径都返回一个值。我该怎么办?

double CalculateTakeProfit (double entryPrice, int takeProfitPips, double GetPipValue)
   {
   if (bIsBuyPosition == True)
      {
      double result = 0;
      entryPrice = Ask;
      result = (entryPrice + takeProfitPips * GetPipValue());
      return result;
      }
   else if (bIsBuyPosition == False)
      {
      double result = 0;
      entryPrice = Bid;
      result = (entryPrice - takeProfitPips * GetPipValue());
      return result;
      }
   }

【问题讨论】:

    标签: mql4


    【解决方案1】:

    您的if... else 错误,您也没有使用传递给函数的变量。相反,您正在引用另一个函数或覆盖它们。在计算中混合变量类型也可能导致不良结果(takeProfitPips 应该是double 类型)。你也可以把你的代码删减几行,如下所示

    double CalculateTakeProfit(double entryPrice, double takeProfitPips, double GetPipValue)
    {
       if(bIsBuyPosition) return(entryPrice+takeProfitPips*GetPipValue);
       else return(entryPrice-takeProfitPips*GetPipValue);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-01
      相关资源
      最近更新 更多