Persistent Variables

I am saving a static Variable as a persistent variable, but having problems with it.

When I search computer for PersistVars I get the results shows below.

2 shortcuts that are timestamped correctly for last run
1 actual file that has not updated
image

Actual code is

DT		= LastValue(DateNum());
Staticvarset("SPY-lastdate",DT,True);	

Persistent variables JUST WORK. There no problems.

The only problem is that you are making incorrect assumptions. Checking modification date is NOT method to check if persistent variables are working
because they are NOT saved at exact moment when you call StaticVarSet.
Doing so would be highly ineffective.
AmiBroker is multithreaded program and various things occur at the same time asynchronously and persistent variables are always in RAM, and they are saved to disk asynchronously, periodically, later during "idle" time in other thread and/or on program EXIT .

Instead of making wrong assumptions, you should read the manual:

that says:

Persistency

Starting from version 5.80 there is a new parameter persist. If it is set to True then static variable will be stored in PersistVars.bin file when AmiBroker is closing and reloaded automatically on next startup, preserving the values of static variables between application runs). In addition to saving them automatically on exit, persistent static variables can be auto-saved at user-specified intervals using SetOption("StaticVarAutoSave", interval );

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.