intrabarpersist variables not reset to their initial values

Questions about MultiCharts and user contributed studies.
janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 103 times

intrabarpersist variables not reset to their initial values

Postby janus » 13 Mar 2012

I've noticed that intrabarpersist variables are not reset to their initial values when a study is re-executed when the "maximum number of bars study will reference" is not large enough, while other variables are reset. Is this normal? It may present a problem where the study expects the initial values on the first official run, which may be say the second, third, etc. re-run. In some cases I now have to include logic to avoid this issue. This is yet another reason I wish there was a way to turn off the "maximum number of bars study will reference" feature.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: intrabarpersist variables not reset to their initial val

Postby Henry MultiСharts » 13 Mar 2012

Hello Janus,

The problem has not been reproduced in our environment on MultiCharts 7.4 and 8.0.
Please let me know the exact version and build number of MultiCharts you are running (Help -> About MultiCharts).
Provide more information on the subject:
what are the exact steps for reproducing this problem?
Please attach sreenshots demonstrating the problem.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 103 times

Re: intrabarpersist variables not reset to their initial val

Postby janus » 13 Mar 2012

I've performed some basic tests and discovered the issue arises only for signals not indicators. Here's my code to demonstrate the issue. The output for a signal study is as follows:

Normal variable set to 1
Intrabarpersist variable set to 1
Normal variable set to 1
Normal variable set to 1
Normal variable set to 1

As you can see the intrabarpersist variable retains it's value across re-runs but the normal one doesn't. The other interesting point to note is the once keyword works across the re-runs. In other words, it is only ever executed once regardless of how many times the study is re-run. This is good or bad depending on the intent by the programmer. I don't mind its current behaviour as it is very handy most of the time. I already use another method to execute code each and every time a study is re-run. The simplest way is to use a normal variable as shown in my test code to check whether a study is re-run.

Code: Select all

[IntrabarOrderGeneration = True]

variables:
normal.var(0), intrabarpersist intrab.var(0);

once cleardebug;

if normal.var = 0 then begin
normal.var = 1;
print ("Normal variable set to 1");
end;
if intrab.var = 0 then begin
intrab.var = 1;
print ("Intrabarpersist variable set to 1");
end;
iF LastBarOnChart_s then value1 = close[30];

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: intrabarpersist variables not reset to their initial val

Postby Henry MultiСharts » 14 Mar 2012

This is not the script re-run. This is the script calculation with IOG turned on (4 calculations on historical data, tick-by-tick calculation on realtime data).

If IntraBarPersist is not specified, the value of variable will be updated at the close of each bar. If IntraBarPersist is specified, the value will be updated on every tick.

The value of the regular variable is rolled back to the previous one until the bar close.
The value of the regular variable is fixed on the bar close.
The value of the IntraBarPersist variable is fixed on each calculation.

That is why you have the following output:
Normal variable set to 1
Intrabarpersist variable set to 1
Normal variable set to 1
Normal variable set to 1
Normal variable set to 1

The indicator is calculated once for the bar on historical data. That is why you have not noticed this before. It can be noticed in realtime using the other script code.
That means that there is no issue in this behaviour.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 103 times

Re: intrabarpersist variables not reset to their initial val

Postby janus » 14 Mar 2012

I see now. I forgot the script executes each historical bar 4 times (barstatus = 1,1,1,2). Perhaps more appropriately once would be enough but I know this will not change so I won't be concerned about it.


Return to “MultiCharts”