I'm using the fantastic code provided by Tomasz in John Ehler's Technical Analysis of Stocks and Commodities (TASC) article regarding the Deviation Squared Moving Average (DSMA), which can be found here.
The code works fine on daily data. But on my 1-minute database from IBKR, there are a number of symbols where the DSMA suddenly returns geometrically increasing numbers, eventually reaching inf or -inf, and never recovers to "normal" values. See screenshot, below, where DSMA10 is the 10-day moving average. This also happens on DSMA30 later down the exploration (not pictured).
Here's the code, which I adapted from the article by putting it in a function and renamed "Close" to "Array", but it's otherwise the same:
// Deviation Scaled Moving Average (DSMA)
// TASC Traders Tips July 2018
// http://traders.com/Documentation/FEEDbk_docs/2018/07/TradersTips.html#item7
function DSMA( Array, Period )
{
PI = 3.1415926;
a1 = exp( -1.414 * PI / ( 0.5 * Period ) );
b1 = 2 * a1 * cos( 1.414 * PI / ( 0.5 * Period ) );
c2 = b1;
c3 = -a1 * a1;
c1 = 1 - c2 - c3;
Zeros = Array - Ref( Array, -2 );
// SuperSmoother Filter
Filt = IIR( Zeros, c1 * 0.5, c2, c1 * 0.5, c3 );
// Compute Standard Deviation
RMS = Sum( Filt * Filt, Period );
RMS = sqrt( RMS / Period );
// Rescale Filt in terms of Standard Deviations
ScaledFilt = Filt / RMS;
alpha1 = abs( ScaledFilt ) * 5 / Period;
return AMA( Array, alpha1 );
}
// Exploration
SetOption( "NoDefaultColumns", True );
Filter = 1;
AddTextColumn( Name(), "Symbol" );
AddColumn( DateTime(), "Date", formatDateTime );
AddColumn( O, "Open", 1.2 );
AddColumn( H, "High", 1.2 );
AddColumn( L, "Low", 1.2 );
AddColumn( C, "Close", 1.2 );
AddColumn( V, "Volume", 1.0 );
AddColumn( DSMA(C,10), "DSMA10" );
AddColumn( DSMA(C,30), "DSMA30" );
AddColumn( DSMA(C,90), "DSMA90" );
AddColumn( DSMA(C,270), "DSMA270" );
Before I debug each step of the calculation, does anyone have any advice on what could be causing this?
Any help is appreciated!