mql4 } 不是所有控制路径 return 一个值

mql4 } not all control paths return a value

我从另一个 mql4 脚本中获取了这个函数。其他脚本编译完全没有错误。奇怪的是,既然我已经将这个函数复制到我的脚本中,我得到了错误 } not all control paths return a value

我理解 return 值的概念,但不确定脚本之间何时存在编译差异

int ModifyOrder(int ord_ticket,double op, double price,double tp, color mColor)
{
    int CloseCnt, err;

    CloseCnt=0;
    while (CloseCnt < 3)
    {
       if (OrderModify(ord_ticket,op,price,tp,0,mColor))
       {
         CloseCnt = 3;
       }
       else
       {
          err=GetLastError();
          Print(CloseCnt," Error modifying order : (", err , ") " + ErrorDescription(err));
         if (err>0) CloseCnt++;
       }
    }
}

最有可能的区别在于 #property strict。如果使用严格模式,您必须重新声明局部变量、每个函数的 return 值(当然 void 除外)和其他一些差异。 在您的示例中,函数必须以 return CloseCnt; 或其他内容结束。

无法声明非严格模式 - 只是不声明严格模式。 声明后,它会应用于该文件,并在导入时包含在其他文件中。