Brief comments on variable scope:
Scope determines the lifetime of a variable. Variables that are class level will persist (stay alive/not get garbage collected) as long as the class does. What defines the variable scope is where in the object hierarchy they are declared.
Code: Select all
[System.Security.SuppressUnmanagedCodeSecurity]
public class NeoTickerClass
//this is the global/main class. This object with live until the chart is closed or disabled
{
string GlobalClassString = "anything";
//class level variable. Can be used as a substitute for pheap
double IIDLIndicator.IDLCallEx(NTIndicatorObjects NTIndicatorObjects)
{
string MethodLevelString = "anything";
//this variable will die after every bar excecution, it will not retain it's value
// and is not a pheap alternative
if (Itself.FirstCall)
{
GlobalClassString = Params.get_Items("paramname"). Str;
//Make sure you reset this in the first call
//this will retain it's scope throughout the lifetime of the ndicator/
//between bars. It acts as a pheap as oposed to heap as it does not reset itself if changed
}
}
There is an important issue to be aware of when using this alternative to pheap. You must remember to reset the value in the FirstCall and even remove previous items from Arrays. I had an issue when I stored an array collection. When I modified the parameters and pressed "Apply" my new items were added to the array but the previous items not removed. I now make sure to clear the array in the FirstCall section.