Change values when changing timeframe

 
Good afternoon,
I have an indicator that shows me on the screen:
- The Initial Balance
- The Current Balance
- The Net Balance
Normally I operate in TimeFrame 1M and they allow me to know how the balance of the account evolves.
It happens to me that when changing from TimeFrame to 5M, for example, the indicator values are reset.
Could you tell me why this happens to me?
Thanks in advance,
 
febrero59: I have an indicator that shows me on the screen:
- The Initial Balance
- The Current Balance
- The Net Balance
Normally I operate in TimeFrame 1M and they allow me to know how the balance of the account evolves. It happens to me that when changing from TimeFrame to 5M, for example, the indicator values are reset.
Could you tell me why this happens to me?

Because only the current balance is maintained by the system. All the rest have to be either calculated from history, or kept as a variable in the running code.

When you change time-frame or symbol on the chart, the Indicator is reset or restarted, so all variables are reinitialised and their previous values lost.

The indicator would have to be changed to keep track of such values in a more permanent way so that they could survive the re-initialisation process.

 
Thanks, I understand.
I now assign a value to the Initial Balance when declaring the variable, before OnInit, so its value persists.

Do you know how I could do it with the current balance?

Is there a link that explains it? (I haven't been able to find it on the net).

Thank you very much,
 
febrero59 #: I now assign a value to the Initial Balance when declaring the variable, before OnInit, so its value persists. Do you know how I could do it with the current balance? Is there a link that explains it? (I haven't been able to find it on the net).

The current balance is the current balance. That is always available by the system:

printf( "Account Balance: %G", AccountInfoDouble( ACCOUNT_BALANCE ) );

Show your code if you want further guidance with the rest:

 

Oh, sorry, that's obvious. Excuse the ignorance.

Thanks Fernando.

 

The solution with terminal global variables

#include <CGlobalVar.mqh>  //Para poner Balance0 como variable de terminal

int OnInit()
  {
   
   if(GlobalVariableCheck("Balance0_value")==true) Balance0=GlobalVariableGet("Balance0_value");
   else{ CGlobalVar Balance0_value;//Para reservar el valor en el cambio de timeframe 
         Balance0_value.Create("Balance0_value",Balance0,true) ;    
       } 
.......

  }
void OnDeinit(const int reason)
{
   .......
   GlobalVariableSet("Balance0_value", Balance0);
   .......
}

Reason: