I have long been a fan of Arthur A. Merrill and from time to time like reread his work. Here is a link to an article he wrote in the Market Technicians Journal on DFE.

I would like to program DFE and Art's tests of DFE in Amibroker, but am unsure of the best way to go about it; how to split the various tasks up to their logical AB module matches. This is not a please program this for me note. What I am asking for are suggestions as to process; how to best go about coding up Art's indicator and approach to testing it on the platform.

Best regards to all,

John Bollinger -- who obviously has too much time on his hands during the lockdown.

@BBands@fxshrat posted just as I was about to put out my meager effort, but based on the appendix here are some starting calculations

// Appendix B
SP500 = Foreign( "$SPX", "C" ); //Replace with ticker of your choice
Y = Close; // the close of the currently selected ticker
d = log( C ); // or you could put the variable "Y" in place of the Close
e = log( SP500 );
f = e * e;
g = e * d;
// the letter's in AmiBroker's afl are not case specific
// so we can't just use the uppercase letters like in the article
// Assuming WEEKLY periodicity (use Weekly in AA window) he uses 20 as the parameter
dd = Sum( d, 20 );
ee = Sum( e, 20 );
ff = Sum( f, 20 );
gg = Sum( g, 20 );
// the next line in the paper is confusing (to me at least)
// B = Beta = ( G - DE/20 )/(F=(E*E/20) ??the denominator is that just F?
// i believe it is a typo as a later paragraph has a modification spelled out more clearly
Beta = ( gg - dd*ee / 20 ) / ( ff - ( ( ee*ee ) / 20 ) );
Alpha = dd / 20 - ( Beta*ee ) / 20;

Sorry, it just looked like too much fun to not make an attempt. Also I just had a quick read but the paper begins by discussing what I believe is Comparative Strength (using the term relative strength) and goes on to discuss the difference in price from a regression line.

I'm tied up the rest of the weekend but some of those lines lead me to think perhaps there is some use for

If you look at the PDF then you will see that at last page there it is listed the average of SP500.

But since (AFAICS) there is not a MA period mentioned in that paper I set to default 1 since MA of period 1 is just index. So you may set MA period yourself or may remove MA and replace by just index.
Your choice.

After a close read of a couple of related papers by Art I think that he used the word average interchangeably with index, so today we would write:
(C) CLOSING INDEX, S&P 500
Which means that your single period average is in fact correct.

Good catch! It appears that when this paper was retyped for the MTA Journal back in the day a few typos crept in. I have a copy Art's original paper. The correct lines are:

B = Beta = (G - DE/20)/(F - E^2/20))
A = Alpha = D/20 - BE/20

But AFAICS SP500 is not closing average but it is market capitalization divided by divisor (with divisor being a $ value at around 9 billion set by Standard & Poor's).
So it is $ divided by $, so unit being canceled and we get some index value.

Well, who knows what he meant...

(x/y-1)*100 is same as x/y*100-100. First one is just factorised.

As for using Ref() as numerator of DFE calculation... somewhere in that paper there was mentioned to compare current value to a previous value....

Now after second look and looking at table on last page I see that 24.25 of DFE equation refers to log(C) so yes you may change to DFE = (d/Y-1)*100;

Here is update:

/// @link https://filebin.net/0ur2wuusz1hj57xi/MTA_Journal__14_-_1982_August-pages-23-30.pdf?t=k1eyz2sa
/// possible AFL version 1.1
/// @link https://forum.amibroker.com/t/arthur-merrills-deviation-from-expected-dfe/18995/14
period = 20;
d = ln(C);// equivalent to log(C)
index = Foreign("^GSPC", "C");
average = index;// or MA(index, some_period); depending on what the paper meant
e = ln(average);// equivalent to log(...)
f = e*e;
g = e*d;
d_sum = Sum(d, period);
e_sum = Sum(e, period);
f_sum = Sum(f, period);
g_sum = Sum(g, period);
printf( "\nD:%g, E:%g, F:%g, G:%g\n", d_sum, e_sum, f_sum, g_sum);
e_ma = MA(e,period);
B = beta = (g_sum-d_sum*e_ma)/(f_sum - e_sum*e_ma);
A = alpha = MA(d,period) - B*e_ma;//(d_sum-B*e_sum)/period;//
printf( "A:%g, B:%g\n", A, B);
Y = exp(A+B*d);// -> Euler^(A+B*d);
DFE = (d/Y-1)*100;
printf("Y:%g, DFE:%g\n", Y, DFE);
Plot( DFE, "DFE", colorRed);

Note: If one just wants to calculate the DFE, one can drop the whole sums.
AFAICS this also leads to more precise results. (see e.g. Beta).
The only thing that makes me wonder is the totally different Y... in comparison with the "Sum-Y" it often seems so random.

/// @link https://filebin.net/0ur2wuusz1hj57xi/MTA_Journal__14_-_1982_August-pages-23-30.pdf?t=k1eyz2sa
/// @link https://forum.amibroker.com/t/arthur-merrills-deviation-from-expected-dfe/18995/14
period = 20;
d = ln(C); // equivalent to log(C)
index = Foreign("^GSPC", "C");
average = index; // or MA(index, some_period); depending on what the paper meant
e = ln(average); // equivalent to log(...)
d_ma = MA(d, period);
e_ma = MA(e, period);
B = beta = Correlation(d, e, period) * StDev(d, period) / (StDev(e, period) + 1e-9);
A = alpha = d_ma - B*e_ma;
printf( "A:%g, B:%g\n", A, B);
Y = exp(A+B*d); // -> Euler^(A+B*d);
DFE = (d/Y-1)*100;
printf("Y:%g, DFE:%g\n", Y, DFE);
Plot( DFE, "DFE", colorBlue);

For complicity, documented Beta calculation can be found here (for example):

Beta could be calculated by first dividing the security's standard deviation of returns by the benchmark's standard deviation of returns. The resulting value is multiplied by the correlation of the security's returns and the benchmark's returns.