Global variable resettable

 

Hi guys,

I'm very new in MQL and I only know 2 ways to save information in an running indicator :

      - global variable, defined at the same level of functions and which can be set only once

      - buffer which depends of the number of Bars

My question is : Is there another way in MQL to keep information at the "indicator level" which can be set several times ?

For example : a global array resizable that does not depend of Bars (like buffers).

I think I can use some tricks with multiple buffers to bypass this limitation but I want to be sure before using these.

I hope I've been clear, English not being my native tongue...

Thanks in advance :)

 
sehinz:

Hi guys,

I'm very new in MQL and I only know 2 ways to save information in an running indicator :

      - global variable, defined at the same level of functions and which can be set only once

      - buffer which depends of the number of Bars

My question is : Is there another way in MQL to keep information at the "indicator level" which can be set several times ?

For example : a global array resizable that does not depend of Bars (like buffers).

I think I can use some tricks with multiple buffers to bypass this limitation but I want to be sure before using these.

I hope I've been clear, English not being my native tongue...

Thanks in advance :)

You can use arrays in an Indicator if you want . . . and make them bigger or smaller as you wish.  You can also change values in an Indicator buffer for any bar you like . . .
 

You can have up to 8 buffers in an indicator, they don't all have to show. Beyond that you have to manage your own arrays.

Perhaps you should explain why you think you need another method.

 
RaptorUK:
You can use arrays in an Indicator if you want . . . and make them bigger or smaller as you wish.

If I define an array in the Indicator scope, it is considered as a global variable and the doc says : "A global variable can be initialized only by a constant that corresponds with its type. Global variables can be initialized only once after program loading into client terminal memory."

These are the two aspects I want to avoid :(


RaptorUK:
You can also change values in an Indicator buffer for any bar you like . . .

Actually, I would like a permanent array not indexed by Bars.
 
WHRoeder:

You can have up to 8 buffers in an indicator, they don't all have to show. Beyond that you have to manage your own arrays.

Perhaps you should explain why you think you need another method.


I'm exploring MQL possibilities, so it's a general thought, no ideas in particular...

Here an example anyway : let's imagine you want to keep a list of values and depending of some results in the indicator, you want to add or delete some of these.

How do you do that without buffers ?

Otherwise, how do you manage your own arrays ?

 
Fixed Array
double array[99];
Variable size
double arr[]; ArrayResize(arr, n);
Simulated indicator buffer (moving elements is unnecessary) from my code
double arr[]; ResizeArray(arr, Bars);
 
sehinz:

If I define an array in the Indicator scope, it is considered as a global variable and the doc says : "A global variable can be initialized only by a constant that corresponds with its type. Global variables can be initialized only once after program loading into client terminal memory."

These are the two aspects I want to avoid :(

Please don't call them Global Variables . . . they are globally declared or have global scope.  There is nothing stopping you setting the value of a variable to the same as it was when you declared it.
 

Ok I clearly misunderstood an aspect of MQL (I found the answer of my question here), let's say it's the language barrier :)

Anyway, thank you very much WHRoeder and RaptorUK for taking the time to explain me.

Reason: