Download MetaTrader 5
To add comments, please log in or register
MQL5 library has more than 1500 apps already. Contribute your own one!
Hans Krijgsman
184
Hans Krijgsman 2014.04.01 08:48 

Two error messages when compiling old mq4:

1) The new MetaEditor gives me a function compiling error despite promise that old mq4 indicators etc. should/could work:

"not all control paths return a value"

//+------------------------------------------------------------------+
//| Checks for a 4_Level_ZZ_Semafor signal on last bar,              |
//| if absent, returns last known signal                             |
//+------------------------------------------------------------------+
int GetSemafor(){

   int _tmpSemafor = _Semafor;   //--- Store last known Semafor signal

   //--- Get buffer data
   FP_BuferUp=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 0,1);
   FP_BuferDn=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 1,1); 
   NP_BuferUp=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 2,1);   
   NP_BuferDn=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 3,1);    
   HP_BuferUp=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 4,1);    
   HP_BuferDn=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 5,1);   
   XP_BuferUp=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 6,1);   
   XP_BuferDn=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 7,1);
      
   //---  WARNING: KEEP THE ORDER OF STATEMENTS, ELSE WRONG OUTPUT/EXECUTION!
//--- Level 4 Lower
	if(Period4>0 && XP_BuferUp!=0){_Semafor=-4;
	     if(_tmpSemafor!=_Semafor){_SemaforCounter=1;_SemaforOld=_SemaforPrev;_SemaforPrev=_tmpSemafor;}else{_SemaforCounter++;}return(-4);}
//--- Level 3 Lower
	if(Period3>0 && HP_BuferUp!=0){_Semafor=-3;
	     if(_tmpSemafor!=_Semafor){_SemaforCounter=1;_SemaforOld=_SemaforPrev;_SemaforPrev=_tmpSemafor;}else{_SemaforCounter++;}return(-3);}
//--- Level 2 Lower	
	if(Period2>0 && NP_BuferUp!=0){_Semafor=-2;
	     if(_tmpSemafor!=_Semafor){_SemaforCounter=1;_SemaforOld=_SemaforPrev;_SemaforPrev=_tmpSemafor;}else{_SemaforCounter++;}return(-2);}
//--- Level 1 Lower
	if(Period1>0 && FP_BuferUp!=0){_Semafor=-1;
	     if(_tmpSemafor!=_Semafor){_SemaforCounter=1;_SemaforOld=_SemaforPrev;_SemaforPrev=_tmpSemafor;}else{_SemaforCounter++;}return(-1);}
//--- Level 4 Upper
	if(Period4>0 && XP_BuferDn!=0){_Semafor=4;
	     if(_tmpSemafor!=_Semafor){_SemaforCounter=1;_SemaforOld=_SemaforPrev;_SemaforPrev=_tmpSemafor;}else{_SemaforCounter++;}return(4);}
//--- Level 3 Upper
	if(Period3>0 && HP_BuferDn!=0){_Semafor=3;
	     if(_tmpSemafor!=_Semafor){_SemaforCounter=1;_SemaforOld=_SemaforPrev;_SemaforPrev=_tmpSemafor;}else{_SemaforCounter++;}return(3);}
//--- Level 2 Upper
	if(Period2>0 && NP_BuferDn!=0){_Semafor=2;
	     if(_tmpSemafor!=_Semafor){_SemaforCounter=1;_SemaforOld=_SemaforPrev;_SemaforPrev=_tmpSemafor;}else{_SemaforCounter++;}return(2);}
//--- Level 1 Upper
	if(Period1>0 && FP_BuferDn!=0){_Semafor=1;
	     if(_tmpSemafor!=_Semafor){_SemaforCounter=1;_SemaforOld=_SemaforPrev;_SemaforPrev=_tmpSemafor;}else{_SemaforCounter++;}return(1);}
//--- SPECIAL: No signal on previous bar, keep on using existing/known Entry- and Exit parameters!
   if(FP_BuferUp==0&&FP_BuferDn==0&&NP_BuferUp==0&&NP_BuferDn==0&&HP_BuferUp==0&&HP_BuferDn==0&&XP_BuferUp==0&&XP_BuferDn==0){
        _SemaforCounter++;
        return(_tmpSemafor);}
}

//+------------------------------------------------------------------+
//| Checks for a 4_Level_ZZ_Semafor signal on a given bar (shift)    |
//+------------------------------------------------------------------+
int LookUpSemafor(int shift){

   //--- Get buffer data
   FP_BuferUp=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 0,shift);
   FP_BuferDn=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 1,shift); 
   NP_BuferUp=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 2,shift);   
   NP_BuferDn=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 3,shift);    
   HP_BuferUp=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 4,shift);    
   HP_BuferDn=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 5,shift);   
   XP_BuferUp=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 6,shift);   
   XP_BuferDn=iCustom(_symbol,_period,"4_Level_ZZ_Semafor",Period1,Period2,Period3,Period4, 7,shift);
   //---  WARNING: KEEP THE ORDER OF STATEMENTS, ELSE WRONG OUTPUT/EXECUTION!
	if(Period4>0 && XP_BuferUp!=0){return(-4);} // Level 4 Lower
	if(Period3>0 && HP_BuferUp!=0){return(-3);} // Level 3 Lower
	if(Period2>0 && NP_BuferUp!=0){return(-2);} // Level 2 Lower	
	if(Period1>0 && FP_BuferUp!=0){return(-1);} // Level 1 Lower
	if(Period4>0 && XP_BuferDn!=0){return(4);}  // Level 4 Upper
	if(Period3>0 && HP_BuferDn!=0){return(3);}  // Level 3 Upper
	if(Period2>0 && NP_BuferDn!=0){return(2);}  // Level 2 Upper
	if(Period1>0 && FP_BuferDn!=0){return(1);}  // Level 1 Upper
   //--- SPECIAL: No signal on previous bar, keep on using existing/known Entry- and Exit parameters!
   if(FP_BuferUp==0&&FP_BuferDn==0&&NP_BuferUp==0&&NP_BuferDn==0&&HP_BuferUp==0&&HP_BuferDn==0&&XP_BuferUp==0&&XP_BuferDn==0){return(0);}
}

2) Also, I had to change old mq4 extern bool vars Alert.Message into AlertMessage and Comment.Message to CommentMessage (removing the dots).

It seems to me that my old bool var notations -now- contain a "Reserved Word", though it's not in the Reserved Word list....

May be add these to the Reserved Word List on: https://docs.mql4.com/en/basis/syntax/reserved

Thank you at forhand for your reply.

Alain Verleyen
Moderator
28595
Alain Verleyen 2014.04.01 09:58  
HansSpain:

Two error messages when compiling old mq4:

1) The new MetaEditor gives me a function compiling error despite promise that old mq4 indicators etc. should/could work:

"not all control paths return a value"

2) Also, I had to change old mq4 extern bool vars Alert.Message into AlertMessage and Comment.Message to CommentMessage (removing the dots).

It seems to me that my old bool var notations -now- contain a "Reserved Word", though it's not in the Reserved Word list....

May be add these to the Reserved Word List on: https://docs.mql4.com/en/basis/syntax/reserved

Thank you at forhand for your reply.

Hello,

Next time, please use the SRC button when you post code. Thank you.


See this article about possible errors with new mql4 : Common Errors in MQL4 Programs and How to Avoid Them

Ian Venner
2583
Ian Venner 2014.04.01 14:27  

That not all control paths return a value error means there is a possible result to something in your code that you do not have covered.

It could be because you have this condition at the end of the function

if(FP_BuferUp==0&&FP_BuferDn==0&&NP_BuferUp==0&&NP_BuferDn==0&&HP_BuferUp==0&&HP_BuferDn==0&&XP_BuferUp==0&&XP_BuferDn==0){return(0);}

What happens if it gets that far and then that condition is not true ? The function has no other way to return. You could probably fix it by giving it another way out:

else
return(-10); //error
/
To add comments, please log in or register