Is it OK to store the indicator object returned by a call to the indicator as a local class variable?
i.e.
In my code I have the following:
Initialize(){ SMA mySMA = SMA(10); } OnBarUpdate(){ if(mySMA[0] > mySMA[1]){ ..... } }
if(SMA(10)[0] > SMA(10)[1]){ ..... }
- If your indicator takes multiple parameters, writing all of them out becomes laborious and error prone, especially in more complex operations. Writing CustomIndicator(param1, param2, param3, param4)[0] is more error prone than myCI[0];
- You reduce computation overhead since you by-pass the cache look up phase every time you make a call to access the indicator. i.e. every time you encounter SMA(...), the code traverses the cache linearly and then returns the correct object for you to access.
Since indicator do not recalculate values until you do F5, it seems the indicator objects too should not be transient and hence their values persistent and suitable for storage in local class variables.
Is there anything more to it?
Comment