In the latest February 2020 Stocks & Commodities Magazine John Ehlers

presents two new interesting indicators the Reflex and TrendReflex.

http://technical.traders.com/content/TTlink.asp?mo=02&yr=2020

I would like to translate his Tradestation EasyLanguage code to AFL and I'm

having some difficulties with the looping. The Ehlers' Super Smoother filter

that he uses to smooth price data for the indicator has been previously

coded by Tomasz Janeczko and published in the January 2014

edition of Stocks & Commodities Magazine

http://technical.traders.com/content/TTlink.asp?mo=01&yr=2014

Here is Ehlers' Tradestation EasyLanguage code for the new

indicators and Tomasz' code for the SuperSmoother function:

```
{
Reflex Indicator
(C) 2019 John F. Ehlers
}
Inputs:
Length(20);
Vars:
Slope(0),
sum(0),
count(0),
a1(0), b1(0), c1(0), c2(0), c3(0), Filt(0),
MS(0),
Reflex(0);
//Gently smooth the data in a SuperSmoother
a1 = expvalue(-1.414*3.14159 / (.5*Length));
b1 = 2*a1*Cosine(1.414*180 / (.5*Length));
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(Close + Close[1]) / 2 + c2*Filt[1] + c3*Filt[2];
//Length is assumed cycle period
Slope = (Filt[Length] - Filt) / Length;
//Sum the differences
Sum = 0;
For count = 1 to Length Begin
Sum = Sum + (Filt + count*Slope) - Filt[count];
End;
Sum = Sum / Length;
//Normalize in terms of Standard Deviations
MS = .04*Sum*Sum + .96*MS[1];
If MS <> 0 Then Reflex = Sum / SquareRoot(MS);
Plot1(Reflex);
Plot2(0);
```

```
{
Trendflex Indicator
(C) 2019 John F. Ehlers
}
Inputs:
Length(20);
Vars:
sum(0),
count(0),
a1(0), b1(0), c1(0), c2(0), c3(0), Filt(0),
MS(0),
Trendflex(0);
//Gently smooth the data in a SuperSmoother
a1 = expvalue(-1.414*3.14159 / (.5*Length));
b1 = 2*a1*Cosine(1.414*180 / (.5*Length));
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(Close + Close[1]) / 2 + c2*Filt[1] + c3*Filt[2];
//Sum the differences
Sum = 0;
For count = 1 to Length Begin
Sum = Sum + Filt - Filt[count];
End;
Sum = Sum / Length;
//Normalize in terms of Standard Deviations
MS = .04*Sum*Sum + .96*MS[1];
If MS <> 0 Then Trendflex = Sum / SquareRoot(MS);
Plot1(Trendflex);
Plot2(0);
```

```
PI = 3.1415926;
SQ2 = sqrt( 2 );
function SuperSmoother( array, periods )
{
a1 = exp( -SQ2 * PI / periods );
b1 = 2 * a1 * cos( SQ2 * PI / periods );
c2 = b1;
c3 = -a1 * a1;
c1 = 1 - c2 - c3;
Filt = Nz( array );
for ( i = 2; i < BarCount; i++ )
{
Filt[ i ] = c1 * ( array[ i ] + array[ i - 1 ] ) / 2 +
c2 * Filt[ i - 1 ] +
c3 * Filt[ i - 2];
}
return Filt;
}
```