How to store the value of a global variable until redeclaring it?

 

Hello, everybody, i am quite new to MQL4 programming, and i have a problem :)

  if(OrdersTotal()==0)
  {
  double account_ballance=AccountBalance();
  GlobalVariableSet("account ballance(start)", account_ballance);
  }

As a result to the coding above, i would like to have a global variable declared when there are no orders opened. But i want my global variable to have the same until it is recalculated (until orderstotal=0) so i can use it when i have to open orders (when orderstotal>0). Instead, when there are no orders, the variable value gets the account ballance value but when there are some orders, it equals to 0, and so the global variable..(so it's useless for me since i want to use the variable value calculated when OrdersTotal()==0.). Can i make the program somehow to memorize the value when the condition is accomplished and then use it later on? Have any idea about any sollution than can solve this problem for me? Thanks and sorry for my bad english, i am not a native speaker :)

 
Perhaps you are getting confused between Global Variables and globally declared variables ? they are not the same . . .
 
Set a bool to true when you set the variable . . . only set the account_balance variable when this bool is false . . . set the bool to false when orders total is greater than 0 . . .
 
8323:

Hello, everybody, i am quite new to MQL4 programming, and i have a problem :)

As a result to the coding above, i would like to have a global variable declared when there are no orders opened. But i want my global variable to have the same until it is recalculated (until orderstotal=0) so i can use it when i have to open orders (when orderstotal>0). Instead, when there are no orders, the variable value gets the account ballance value but when there are some orders, it equals to 0, and so the global variable..(so it's useless for me since i want to use the variable value calculated when OrdersTotal()==0.). Can i make the program somehow to memorize the value when the condition is accomplished and then use it later on? Have any idea about any sollution than can solve this problem for me? Thanks and sorry for my bad english, i am not a native speaker :)

Hi 8323, Until reassign new value to it. Actually I'm not sure what you want, so I may be wrong. Write the code like this or just change the type account_ballance variable from local to global.

  if(OrdersTotal()==0)
    {
    double account_ballance=AccountBalance();
    GlobalVariableSet("account ballance(start)", account_ballance);
    }
    else
    {
    account_ballance=GlobalVariableGet("account ballance(start)");
    
    }
 
onewithzachy:

Hi 8323, Until reassign new value to it. Actually I'm not sure what you want, so I may be wrong. Write the code like this or just change the type account_ballance variable from local to global.


Thanks a lot!! This solved my problem :) Have a nice day, guys! :P
Reason: