The prior post discussion focused on the speed of execution of these routines. Casey introduced us to an alternative method of calculating the standard deviation that proved faster than the traditional method used in Tradestation functions. Goose developed a flexible version of this routine that allowed the Length parameter to vary from call to call, eliminating the need of having two separate versions, such as StdDev and StdDevFC versions. He also developed a “gapless” array based version of StdDev to deal with the distortion in Bollinger Bands that occurs when there is an opening gap in the trading session. These versions may be found in the original post referenced above and linked to below.
I recently needed a StdDev function that worked on arrays and also outputted the mean. Since Goose’s array-based version included filtering the opening session gap and did not output the mean, the StdDevMeanArray function presented here removes the gap filter and adds a second output parameter, the mean. This also uses Casey’s rapid calculation method for standard deviation. The additional mean output parameter avoids recalculation of the mean when both mean and standard deviation values are needed.
The original sister function working from price bars, StdDevMean, is also re-posted here for completeness.
The functions were tested to ensure they produce identical calculations by creating indicators with the same names as the functions. These are shown plotting the results of standard deviation and mean, using both price bar-based (StdDevMean) and array-based (StdDeVMeanArray) versions:
Initially posted version: 09/14/09
Latest Update: 04/06/10
*.ELD files are compiled for TS 8.7
All ELD and code text files packaged here:
Users of earlier versions fo TradeStation may compile the code
from the text files included in the above *.zip file.
The code may be visualized here: