Variable does not get saved

 

Hi, 

int Test gets set to 2 but bool buycondition2 not to true.  
the variable  buycondition2  does not get value true outside of if, but variable test does.

second if condition does not get met. 

 Any ideas?

      int test =1;
      if (Ask<structurelong2_high && structurelong2_high !=0)    // ??????????????????????????????????????????
      {
      buycondition2 = true;   
      Print("buycondition2",buycondition2);
      Print("condition 1");
      test =2;
      } 
	else{} 
      
         if (buycondition2 = true && structurelong2_low>Low[2] && structurelong2_low>Low[2] && Ask < structurelong2_low)
         { buycondition2 = false;
         Print("condition 2");
         sndbuy2invalid = true; }
         
       Print("buycondition2 after if",buycondition2);     
       Print("test :",test); 
 
Mario0407: Hi, int Test gets set to 2 but bool buycondition2 not to true.  the variable  buycondition2  does not get value true outside of if, but variable test does. second if condition does not get met.  Any ideas?

You are assigning a value instead of doing a comparison:

if (buycondition2 = true && structurelong2_low>Low[2] && structurelong2_low>Low[2] && Ask < structurelong2_low)

You probably meant the following:

if (buycondition2 == true && structurelong2_low>Low[2] && structurelong2_low>Low[2] && Ask < structurelong2_low)

Also, please use the code Styler on your code to make it easier to read and to detect problems in your code logic.

 

You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.

 
Thank you both for helping me further, now makes much more sense, should have seen it!