0
votes

Been doing this code in "Include" file. But I am encountering the error "not all control paths return a value. What should I do?

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

1 Answers

0
votes

Your if... else is wrong and you are also not using the variables passed to the function. You are instead referencing another function or overwriting them. Mixing variable types in a calculation can also lead to undesirable results (takeProfitPips should be of type double). You can also cut a few lines of your code down as follows

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