How to update variable from with if statement MQL5

 

https://stackoverflow.com/questions/58228952/how-to-update-variable-from-with-if-statement-mql5

How to update variable from with if statement MQL5
How to update variable from with if statement MQL5
  • 2019.10.04
  • Anwar Goulouh
  • stackoverflow.com
MQL5 Question. Been awhile as have learned to learn lol although sometimes the smallest thing can stump... Have been googling for two days now and cant figure this out and it seems basic. I would like to create a variable . Lets say it starts out with no value . Then I test condition if is or equals Like So.. Which should always return true...
 
PLease check stack overflow couldn't seem to add the short code here kept saying it was exceeding char limit. :(
 

you need to set a NULL pointer to a variable int a = NULL;

   int a = NULL;
   if(PositionsTotal() < 1)
     {
      if(a == NULL || a == 1)
        {
         a = 0;
        }
      else
         if(a == 0)
           {
            a = 1;
           }
     }
   Print(a);
I will add my opinion: it is better to use the standard 0 because NULL is a compiler macro, and it can have a value other than 0
 
Pavel Shutovskiy: I will add my opinion: it is better to use the standard 0 because NULL is a compiler macro, and it can have a value other than 0

I agree.

Don't use NULL.
  • You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
  • Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
  • Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
  • MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].