Get input in the program and change its value during the program (extern - input - Mql5)

 
Hello good time,

I had a question, thank you dear ones for your help

In mql4 we had  external keywords that we used to get input in Expert or indicator and later during the program (exa -indicator) we could give a new value to the external variable.

But in mql5,
We can not use the word extern and then give the variable a new value in the program (maybe we can but I do not know if we can or not, if you know tell me to add to my experience).

So :

How to create a variable in MQL5, which takes a value from the user and changes during the program?
Is it possible or not?


I read the reference input variables.
However, he did not answer my questions.

Thank you very much for your time.
 
Abdolmobin Khezri:
Hello good time,

I had a question, thank you dear ones for your help

In mql4 we had  external keywords that we used to get input in Expert or indicator and later during the program (exa -indicator) we could give a new value to the external variable.

But in mql5,
We can not use the word extern and then give the variable a new value in the program (maybe we can but I do not know if we can or not, if you know tell me to add to my experience).

So :

How to create a variable in MQL5, which takes a value from the user and changes during the program?
Is it possible or not?


I read the reference input variables.
However, he did not answer my questions.

Thank you very much for your time.

you have to create another variable inside the program and map the value of the input variable to it. You cannot change the input variable.

 
Abdolmobin Khezri: I had a question, thank you dear ones for your help. In mql4 we had  external keywords that we used to get input in Expert or indicator and later during the program (exa -indicator) we could give a new value to the external variable. But in mql5, We can not use the word extern and then give the variable a new value in the program (maybe we can but I do not know if we can or not, if you know tell me to add to my experience). So : How to create a variable in MQL5, which takes a value from the user and changes during the program? Is it possible or not? I read the reference input variables. However, he did not answer my questions.

Save the input to a variable, then use that variable instead in your code and change it when needed.

Here is an example using global variables but it can also be local variables depending on the situation:

// Declare inputs
   input int i_nPeriod = 20;  // Period of moving average
   
// Declare global variables
   int g_nPeriod,             // Adjustable period of moving average
       g_hMA;                 // Handle for moving average indicator

// Initialisation event handler
   int OnInit()
   {
      // Save inputs to global variables (so that it can be changed later)
         g_nPeriod = i_nPeriod;
      
      // For some reason, input period of moving average needs to change
         g_nPeriod = g_nPeriod * 2;

      // Get moving average handle
         g_hMA = iMA( _Symbol, _Period, g_nPeriod, 0, MODE_SMA, PRICE_CLOSE );
      
      return(INIT_SUCCEEDED);
   };