/*
* John F. Ehlers
* Cybernetic Analysis for Stocks & Futures
* Chp. 4 ~ Fig. 4.2 ~ "Cyber Cycle"
*/
function main() {
// Backtest Settings
StartDate = 20180415;
EndDate = 20180515;
LookBack = 200;
}
function run() {
vars Price = series((priceHigh() + priceLow()) / 2);
vars Smooth = series((Price[0] + 2*Price[1] + 2*Price[2] + Price[3]) / 6);
var alpha = 0.07;
vars Cycle = series(0);
Cycle[0] =
(1 - 0.5*alpha)*(1 - 0.5*alpha)*(Smooth[0] - 2*Smooth[1] + Smooth[2])
+ 2*(1 - alpha)*Cycle[1]
- (1 - alpha)*(1 - alpha)*Cycle[2];
// Plot Results
set(PLOTNOW);
plot("Cycle", Cycle[0], NEW, 0xcc0000);
plot("Trigger", Cycle[1], 0, 0x0000cc);
}