MQL4 Error: " '}' - not all control paths return a value"
MQL4 Error: " '}' - not all control paths return a value"
Loading saved threads...
mervin · External communityPost link
External question — Stack Overflow Stack Exchange
Author: mervin
Original post: https://stackoverflow.com/questions/67646470
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
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;
}
}
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: PaulB
Original post: https://stackoverflow.com/a/67647280
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
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);
}
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: mervin Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/67646470 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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; } }
Checking account access…