Values of variables in function will be kept

Questions about MultiCharts and user contributed studies.
ragdoll
Posts: 49
Joined: 04 Apr 2019
Has thanked: 4 times

Values of variables in function will be kept

Postby ragdoll » 23 Jun 2020

Per my test, values of variables in a function will be kept no matter the function is type of simple or series.

I define a simple function as follows which name is "test".

Code: Select all

variables: index(0); index = index + 1; fn_test = index;
And in an indicator I plot this function through all bars.

Code: Select all

Plot1(test(), "test")
I found the plot keeps increasing. Does that mean a local variable of a function will keep its value even after the function returns?

User avatar
Vlada MultiCharts
Posts: 293
Joined: 22 Apr 2020
Has thanked: 8 times
Been thanked: 76 times

Re: Values of variables in function will be kept

Postby Vlada MultiCharts » 20 Jul 2020

Hello ragdoll,

The Function Storage determines which data will be stored and returned.
Function Storage_MultiCharts.png
(10.81 KiB) Not downloaded yet
If one uses the Simple type, it will be impossible to know the value of the previous bar. The Series type stores the series so one can call the previous bar value.
In the example provided, the indicator has displayed the current values of each bar.

You may find the following articles useful:
Function Storage
Functions in MultiCharts and TS


Return to “MultiCharts”