Download MetaTrader 5
To add comments, please log in or register
Deposit to your account in any convenient way. There are 4 of them here!
Subgenius
572
Subgenius 2014.03.14 01:24 

What is the problem causing this error message? or if this is in the wrong forum please disregard. https://www.mql5.com/en/forum/22035


MetaEditor 5.00 Build 883 / MetaTrader 4 Build 604

//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
input color    FontColor=clrLime;
input string   FontName="Arial";
input string   Corner="UpperLeft=0, UpperRight=1, LowerLeft=2, LowerRight=3";
input int      CornerNumber=1;
//+------------------------------------------------------------------+
int OnInit()
  {
  return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   TextLabel("multi1", Symbol() + "," + Per(Period()), 18, FontName, FontColor, 138, 37, CornerNumber);
   TextLabel("multi2", "Q u o t e / B a s e , P e r i o d", 8, FontName, FontColor, 31, 37, CornerNumber);
   TextLabel("multi3", "Bid(Sell): ", 10, FontName, FontColor, 4, 49, CornerNumber);
   TextLabel("multi4", "Ask(Buy): ", 10, FontName, FontColor, 4, 63, CornerNumber);
   TextLabel("multi5", "Spread: ", 10, FontName, FontColor, 5, 80, CornerNumber);
   
   return(rates_total);
  }
//+------------------------------------------------------------------+
void TextLabel(string Name, string Text, int Size, string Font, color Color, int x, int y, int iCorner)
   {
   //Upper left=0, Upper right=1, Lower left=2, Lower right=3
   ObjectCreate(Name,OBJ_LABEL,0,0,0);
   ObjectSetText(Name,Text,Size,Font,Color);
   ObjectSet(Name,OBJPROP_XDISTANCE,x);
   ObjectSet(Name,OBJPROP_YDISTANCE,y);
   ObjectSet(Name,OBJPROP_CORNER,iCorner); 
   }  
//+------------------------------------------------------------------+  
string Per(int thisperiod)
   {
   if(thisperiod==1){return("M1");}
   if(thisperiod==5){return("M5");}
   if(thisperiod==15){return("M15");}
   if(thisperiod==30){return("M30");}
   if(thisperiod==60){return("H1");}
   if(thisperiod==240){return("H4");}
   if(thisperiod==1440){return("D1");}
   if(thisperiod==10080){return("W1");}
   if(thisperiod==43200){return("MN1");}
   }
//+------------------------------------------------------------------+
qjol
3243
qjol 2014.03.14 02:38  

here is an mql4 forum Link to the MQL5 forum

i can't find the problem either but in the mean time you can use EnumToString

the weird thing is if i add this line

else {return("it's not a standart MetaQuotes time frame");}
there is no error message
Keith Watford
Moderator
7904
Keith Watford 2014.03.14 03:01  
   if(thisperiod==43200){return("MN1");}
   return("ERROR");
GreenMoney
379
GreenMoney 2014.03.14 03:22  
Subgenius:

What is the problem causing this error message?

. . .


The logic error is in your Per() function, as GumRai and qjol have stated. What happens when the variable "thisperiod" doesn't cause any of the IF statements to be true (for example, if thisperiod=20 or if thisperiod=0)? The answer is that no return operator is executed, hence the compiler is issuing the error message "not all control paths return a value." All functions must return a value, unless they are void type.

Just a suggestion, instead of a set of IF statements, you might consider using the switch operator. Below is some sample code (compiled without error but not tested):

string Per(int thisperiod) {   
   switch (thisperiod) {
      case PERIOD_M1:  return("M1");
      case PERIOD_M5:  return("M5");
      case PERIOD_M15: return("M15");
      case PERIOD_M30: return("M30");
      case PERIOD_H1:  return("H1");
      case PERIOD_H4:  return("H4");
      case PERIOD_D1:  return("D1");
      case PERIOD_W1:  return("W1");
      case PERIOD_MN1: return("MN1");
      default:         return("Unknown Timeframe");
   }
}

.

qjol
3243
qjol 2014.03.14 03:39  
Thirteen:


The logic error is in your Per() function, What happens when the variable "thisperiod" doesn't cause any of the IF statements to be true ...

even if i would agree with you that that's the problem, I do not get it

in this logic if i would use

OrderSend("Symbol Doesn't exist"...)

the compiler sould say the same error ?!

GreenMoney
379
GreenMoney 2014.03.14 13:08  
qjol:

even if i would agree with you that that's the problem, I do not get it

in this logic if i would use

OrderSend("Symbol Doesn't exist"...)

the compiler sould say the same error ?!


I don't understand what you are stating/asking. What does use of the return operator have to do with use of the OrderSend() function and why should the compiler say the same error?
whroeder1
13610
whroeder1 2014.03.14 13:42  

There is no error because it's a valid call. The compiler can't possibly know all symbol names from all brokers (current and future), nor which broker you intend to put the compiled code on.

   // Broker's use a variety of nameing patterns: EURUSD, EURUSDm, EURUSDi
   // "EURUSD.", "EURUSD..", "EUR.USD", "EUR/USD", "EURUSD.stp", EURUSDct,
   // "EURUSD.G", "EURUSD+", EURUSDpro at least.

That's why you check your return codes at run time. What are Function return values ? How do I use them ? - MQL4 forum



qjol
3243
qjol 2014.03.14 13:56  
WHRoeder:

There is no error because it's a valid call. The compiler can't possibly know all symbol names from all brokers and which broker you intend to put the compiled code on.

That's why you check your return codes at run time. What are Function return values ? How do I use them ? - MQL4 forum

that's what i'm trying to say

the compiler shouldn't return an error if i use a Symbol() that doesn't exist

same as he shouldn't return an error using this function

string Per(int thisperiod)
   {
   if(thisperiod==1){return("M1");}
   if(thisperiod==5){return("M5");}
   if(thisperiod==15){return("M15");}
   if(thisperiod==30){return("M30");}
   if(thisperiod==60){return("H1");}
   if(thisperiod==240){return("H4");}
   if(thisperiod==1440){return("D1");}
   if(thisperiod==10080){return("W1");}
   if(thisperiod==43200){return("MN1");}
   }

what's the difference

GreenMoney
379
GreenMoney 2014.03.14 14:22  
qjol:

. . .

same as he shouldn't return an error using this function

what's the difference

The difference is that the user-defined Per() function is required to return some value. If the value assigned to "thisperiod" doesn't make any of the IF statements true, what value, in your opinion, should the Per() function return? For example, lets say that thisperiod=0; how should the Per() function respond, what value should it return?

By raising the compile-time error, the compiler is telling the user that since there exists a path through the function Per() that doesn't execute the return operator (i.e., assume thisperiod=0), there is a compile-time error because Per(), as it has been defined, is required to return some value.

BTW, the OrderSend() function returns the "number of the ticket assigned to the order by the trade server or -1 if it fails." That is why the compiler doesn't raise the same error with OrderSend(). OrderSend() is designed to always return some value, the ticket number assigned to the order or -1. The compiler knows that (due to the design of OrderSend()), so the compiler knows not to raise that error when using OrderSend().

whroeder1
13610
whroeder1 2014.03.14 16:16  
qjol: what's the difference
string Per(int thisperiod)
   {
   :
   if(thisperiod==43200){return("MN1");}
//What are you returning here when all the above are false?
    } // Last return is here.
James Hodges
2780
James Hodges 2014.03.15 02:06  
string Per(int thisperiod)
   {
   if(thisperiod==1)     return("M1");
   if(thisperiod==5)     return("M5");
   if(thisperiod==15)    return("M15");
   if(thisperiod==30)    return("M30");
   if(thisperiod==60)    return("H1");
   if(thisperiod==240)   return("H4");
   if(thisperiod==1440)  return("D1");
   if(thisperiod==10080) return("W1");
   if(thisperiod==43200) return("MN1");
   return("");
   }

Need a return value so that the function can finish even if none of the conditional if statements are true.
Of course we know that it HAS to be one of those periods... but still... that's the way it is..

/ /12
To add comments, please log in or register