Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Store a property or variable in memory?

Is there a way to store a variable or a property in memory? Or am I thinking about this all wrong?

As an example, lets say I want to buy when some indicator signals a buy - but only every other time.
I would have to track if a signal was the first or second signal observed. This would require setting and storing (past a day) a property like:

context.ready_next_time = True  

then...

...
if some_signal and context.ready_next_time: # second time signal hit  
    order(...)  
    context.ready_next_time = False # reset property

elif some_signal and not context.ready_next_time : # first time signal hit  
    context.ready_next_time = True  

The problem is when you re - initialize() everyday you clear the memory. Am I missing something is there a database or somewhere I can store data past one day?

Thanks,

2 responses

you should call context.my_var = 1, and print it every day to see if it is persistent. then you would know.

context does not get cleared, unless the algo is stopped. You can store stuff there.