Functions , using if,else

 

I have tried to create this function with the if,else but am having difficulty. I would like for the function to return the number of the "if" criteria that is meet back to the program using checkordertype () .

Is this type of function allowed using " if ,else ", as I am a newbie to functions would you please let me know if it is  acceptable to use it this way ?

I have Checked using Alert that the Signalisbuy  1 /signalissell 2 does go to the function using Alerts.   If I remove the parenthesis then it will return a number , which isn't useful for the criteria meet .

Thanks for any assistance.

 int checkordertype()
   { 
   int result;
         
    static int lastordertype=0;

 
    
if( signalisbuy==1 && signalisbuy !=lastordertype ) 
     {    
      
      lastordertype=signalisbuy;          
                                                     
         result =5;                                              
     }                          
                 
         else
      {
if(signalisbuy==1 && signalisbuy==lastordertype)
       {                                        
                                                         
         result=6;
        }
        else
        {  
if(signalissell==2 && signalissell != lastordertype) 
     {
       lastordertype=signalissell;           
       result=7; 
        }   
  else
     {

if(signalissell==2 && signalissell==lastordertype) 
   {    
     result=8;
             }
         }                                    
      }                                                     
   }
       return(result);
      }
 
barnacle7:

I have tried to create this function with the if,else but am having difficulty. I would like for the function to return the number of the "if" criteria that is meet back to the program using checkordertype () .

Is this type of function allowed using " if ,else ", as I am a newbie to functions would you please let me know if it is  acceptable to use it this way ?

I have Checked using Alert that the Signalisbuy  1 /signalissell 2 does go to the function using Alerts.   If I remove the parenthesis then it will return a number , which isn't useful for the criteria meet .

Thanks for any assistance.


Write down your code in a easy way to read  how you do it it is awful

if you did it this way then it was more easy to see what happens

 int checkordertype()
   {          
   static int lastordertype=0;
   int result;
   if( signalisbuy==1 && signalisbuy !=lastordertype ) 
     {     
     lastordertype=signalisbuy;  // here you make signalisbuy equal to lastordertype
                                                      
     result =5;                                              
     }                          
    else
      {
      if(signalisbuy==1 && signalisbuy==lastordertype)
           {                                                                                                 
           result=6;     //and result 5 you won't get
           }
         else
            {  
            if(signalissell==2 && signalissell != lastordertype) 
               {
               lastordertype=signalissell//here you make signalsell equal to lastordertype          
               result=7; 
               }   
             else
                {
                if(signalissell==2 && signalissell==lastordertype) 
                      {    
                      result=8;    //and result 7 you won't get
                      }
                }                                    
            }                                                     
      }
   return(result);
   }
 
deVries:
Write down your code in a easy way to read  how you do it it is awful
if you did it this way then it was more easy to see what happens
And if you use else if as a single statement it becomes even easier to see.
 int checkordertype()
   {
   static int lastordertype=0;
   int result;
   if( signalisbuy==1 && signalisbuy !=lastordertype )
      {
      lastordertype=signalisbuy;
      result =5;
      }
   else if(signalisbuy==1 && signalisbuy==lastordertype)
      {
      result=6;
      }
   else if(signalissell==2 && signalissell != lastordertype)
      {
      lastordertype=signalissell;
      result=7;
      }
   else if(signalissell==2 && signalissell==lastordertype)
      {
      result=8;
      }
   return(result);
   }
 
WHRoeder:
And if you use else if as a single statement it becomes even easier to see.
And if you add some whitespace it's even easier to see. I have been reading your posts for years but find it almost impossible to follow your code. I do not question your coding skills, just your formatting.