MQL4 错误: " '}' - not all control paths return a value"



在"包括";文件但我遇到了错误";并非所有控制路径都返回一个值。我该怎么办?

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;
}
}

您的if... else是错误的,您也没有使用传递给函数的变量。而是引用另一个函数或覆盖它们。在计算中混合变量类型也可能导致不希望的结果(takeProfitPips的类型应为double(。你也可以把代码的几行剪下来,如下

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

最新更新