+1 888 340 6572

MovAvg Adaptive Fltr

From MultiCharts

Article/Author: "A Guide to Smarter Trading", Perry Kaufman, S&C Magazine, Traders Tips, 03/1998

AMA Function Code:

INPUTS: PERIOD(NUMERIC);
VARS: NOISE(0), SIGNAL(0), DIFF(0), EFRATIO(0), SMOOTH(1), FASTEST(.6667), SLOWEST(.0645), ADAPTMA(0);

DIFF = ABSVALUE(CLOSE - CLOSE[1]);
IF CURRENTBAR <= PERIOD THEN ADAPTMA = CLOSE;
IF CURRENTBAR > PERIOD THEN BEGIN
	SIGNAL = ABSVALUE(CLOSE - CLOSE[PERIOD]);
	NOISE = SUMMATION(DIFF, PERIOD);
	EFRATIO = SIGNAL / NOISE;
	SMOOTH = POWER(EFRATIO * (FASTEST - SLOWEST) + SLOWEST, 2);
	ADAPTMA = ADAPTMA[1] + SMOOTH * (CLOSE - ADAPTMA[1]);
END;

AMA = ADAPTMA;

AMAF Function Code:

INPUTS: PERIOD(NUMERIC), PCNT(NUMERIC);

VARS: NOISE(0), SIGNAL(0), DIFF(0), EFRATIO(0), SMOOTH(1), FASTEST(.6667), SLOWEST(.0645), ADAPTMA(0), AMAFLTR(0);


DIFF = ABSVALUE(CLOSE - CLOSE[1]);
IF CURRENTBAR <= PERIOD THEN ADAPTMA = CLOSE;
IF CURRENTBAR > PERIOD THEN BEGIN
	SIGNAL = ABSVALUE(CLOSE - CLOSE[PERIOD]);
	NOISE = SUMMATION(DIFF, PERIOD);
	EFRATIO = SIGNAL / NOISE;
	SMOOTH = POWER(EFRATIO * (FASTEST - SLOWEST) + SLOWEST, 2);
	ADAPTMA = ADAPTMA[1] + SMOOTH * (CLOSE - ADAPTMA[1]);
	AMAFLTR = STDDEV(ADAPTMA-ADAPTMA[1], PERIOD) * PCNT;
END;

AMAF = AMAFLTR;
{COPYRIGHT 1997 TECHNICAL ANALYSIS, INC.}

MovAvg Adaptive Fltr Signal Code:

INPUTS: PERIOD(10), PCNT(.15);
VARS: AMAVAL(0), AMAFVAL(0), AMALS(0), AMAHS(0);

AMAVAL = AMA(PERIOD);
AMAFVAL = AMAF(PERIOD, PCNT);

IF CURRENTBAR = 1 THEN BEGIN
	AMALS = AMAVAL;
	AMAHS = AMAVAL;
END ELSE BEGIN

	IF AMAVAL < AMAVAL[1] THEN
		AMALS = AMAVAL;
	IF AMAVAL > AMAVAL[1] THEN
		AMAHS = AMAVAL;

	IF AMAVAL - AMALS CROSSES ABOVE AMAFVAL THEN
		BUY THIS BAR ON CLOSE;
	IF AMAHS - AMAVAL CROSSES ABOVE AMAFVAL THEN
		SELL THIS BAR ON CLOSE;
END;
{COPYRIGHT 1997 TECHNICAL ANALYSIS, INC.}