I am migrating from Easylanguage to AFL. I wrote an exploration to identify the
change in direction of High or low standard error bands. My settings are: n
days: 1, since I wished to get a list of tocks that have turned on the last
day.
The last date is March 4. But I am getting stocks that made the turn one day
earlier on march 3. Which means the pivot low was made on March 3 - March 3 is
higher than March 2, March 2 is lower than previous day, thus March 2 pivot is
confirmed on March 3. The database is end of day. The code is given below. Help
will be appreciated.
Periods = Param("Standard Error", 8, 3, 100, 1);
function SteBand( array, periods, upper )
{
Lr = LinearReg( array, periods );
se = StdErr( array, periods );
return LR + IIf( upper, 1, -1 ) * 2 * se;
}
upperstderrband = MA(SteBand( C, Periods, True ),3);
lowerstderrband = MA(SteBand( C, Periods, False ),3);
midstderrband = (upperstderrband + lowerstderrband )/2;
ThisIsLastBar = BarIndex() == LastValue( BarIndex() );
IsVolume = Volume * Close > 10000000;
HighMovesDown = Ref(upperstderrband,-1) > upperstderrband AND
Ref(upperstderrband,-1) > Ref(upperstderrband,-2);
LowMovesUp = Ref(lowerstderrband,-1) < lowerstderrband AND
Ref(lowerstderrband,-1) < Ref(lowerstderrband,-2);
Filter = ThisIsLastBar AND IsVolume AND (HighMovesDown OR LowMovesUp);
AddColumn( Close, "Close" );