簡體   English   中英

MQL4 錯誤:“'}' - 並非所有控制路徑都返回值”

[英]MQL4 Error: " '}' - 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是錯誤的,你也沒有使用傳遞給 function 的變量。 相反,您正在引用另一個 function 或覆蓋它們。 在計算中混合變量類型也會導致不良結果(takeProfitPips 應該是double類型)。 您還可以按如下方式減少幾行代碼

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM