Indicator Values Storing in Array

 

Hello,

I am wondering what would you consider a better practice for storing values of an indicator. Keeping a seperate Array to store values for each indicator or having one array where you temporary use it to store values and clear for each indicator?

Example below for a moving average indicator:

double MAvalue(int MAhandle, int IsPrevBar)
  {
   double maArray[];
   CopyBuffer(MAhandle,0,IsPrevBar,2,maArray);
   return(maArray[1]);
   ArrayFree(maArray);//possible use for memory optimisation
  }

later I can call the function MA value in my code as follows (note: IsPrevBar is used for when I want to calculate by BAR with other code, you can ignore this part):

double maValueSlow = MAvalue(maSlowHandle, isPrevBar);

double maValueFast = MAvalue(maFastHandle, isPrevBar);

where the slow and fast handles are for differing lookback periods. The benefit I see from not having seperate functions would make allow me to use less code which always makes life easier (could even in theory have a generic one that includes other indicators that follow similar structure). On the other hand am worried it may create some issue in the code itself. 

Would this approach cause any issues? Is is it better to create a seperate function for the MAslow and MAfast to store in its own seperate arrays or it would not matter?

very curious to know opinions on this!

Thank you

 
  1. Does not matter.
  2. The array is released on return; the ArrayFree is unnecessary.
  3. Don't worry about performance, until you have a problem. Then, and only then, use the profiler, find the problem, fix the problem, and remeasure.

 
William Roeder #:
  1. Does not matter.
  2. The array is released on return; the ArrayFree is unnecessary.
  3. Don't worry about performance, until you have a problem. Then, and only then, use the profiler, find the problem, fix the problem, and remeasure.

Thank you William for your reply, very clear!

1. Thats great, i will then use the generic one as it will be less effort than having a new function for every indicator.

2. Always had some doubt on that, thanks for the feedback,will remove it.

Is it the same for IndicatorRelease function in OnDeinit? or is that still usefull? (please see below example)

void OnDeinit(const int reason)
  {
//---

//release handles after removing EA

   if(maSlowHandle!=INVALID_HANDLE)
      IndicatorRelease(maSlowHandle);
  }
Reason: