Đây là loạt bài AmiBroker AFL Library về phần mềm phân tích kỹ thuật PTKT AmiBroker

Details:

Formula name: Adaptive Cyber Cycle

Author/Uploader: Robert Dunbar - (email hidden)
Date/Time added: 2012-07-16 08:46:42
Origin: London
Keywords: Adaptive Cyber Cycle, John Ehler
Level: medium
Flags: indicator
DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

You can contact me at "info at coding4ab dot com"

Formula:

//==================================
//==================================
// From John Ehler's book ===
// Rocket Science for Traders ===
// ===
// AFL By Robert Dunbar ===
//==================================
//==================================

Arrows = ParamToggle( "Buy/Sell Arrows", "No|Yes", 1 );
PriceIn = ( ( H + L ) / 2 );
alpha = Param( "Alpha", 0.07, 0.01, 0.4, 0.01, 0.01 );
Len = Param( "Length", 8, 1, 25, 1, 1 );
BullSig = BearSig = Trigger = Cycle = InstPeriod = Period = AdaptCycle =
DeltaPhase = 0;

SmoothX = ( PriceIn + 2 * Ref( PriceIn, -1 ) + 2 * Ref( PriceIn, -2 ) + Ref(
PriceIn, -3 ) ) / 6;


for ( i = 6; i < BarCount; i++ )

Cycle[i] = ( ( 1 - 0.5 * alpha ) ^ 2 ) * ( SmoothX[ i ] - 2 * SmoothX[ i -
1 ] + SmoothX[ i - 2] ) + 2 * ( 1 - alpha ) * Cycle[ i - 1 ] - ( ( 1 - alpha ) ^
2 ) * Cycle[ i - 2 ];
Q1[i] = ( .0962 * cycle[i] + .5769 * cycle[i-2] - .5769 * cycle[i-4] -
.0962 * cycle[i-6] ) * ( .5 + .08 * InstPeriod[i-1] );
I1[i] = cycle[i-3];

if ( Q1[i] != 0 AND Q1[i-1] != 0 )
DeltaPhase[i] = ( I1[i] / Q1[i] - I1[i-1] / Q1[i-1] ) / ( 1 + I1[i] *
I1[i-1] / ( Q1[i] * Q1[i-1] ) );

if ( DeltaPhase[i] < 0.1 )
DeltaPhase[i] = 0.1;

if ( DeltaPhase[i] > 1.1 )
DeltaPhase[i] = 1.1;


//----- Speed up the median calculation by placing it inline
mlen = 5;

for ( k = mlen - 1; k >= 0; k-- )

temparray[k] = DeltaPhase[i + k - ( mlen - 1 )];
}

temp = 0;

for ( k = mlen - 1; k > 0; k-- )

for ( j = mlen - 1; j > 0; j-- )

if ( temparray[j-1] > temparray[j] )

temp = temparray[j-1];
temparray[j-1] = temparray[j];
temparray[j] = temp;
}
}
}

MedianDelta[i] = temparray[mlen - 1 - ( mlen / 2 )];

if ( MedianDelta[i] == 0 )
DC[i] = 15;
else
DC[i] = 6.28318 / MedianDelta[i] + .5;

InstPeriod[i] = .33 * DC[i] + .67 * InstPeriod[i-1];

Period[i] = .15 * InstPeriod[i] + .85 * Period[i-1];

Alpha1[i] = 2 / ( Period[i] + 1 );

AdaptCycle[i] = ( 1 - 0.5 * Alpha1[i] ) * ( 1 - 0.5 * Alpha1[i] ) * (
SmoothX[i] - 2 * SmoothX[i-1] + SmoothX[i-2] ) + 2 * ( 1 - Alpha1[i] ) *
AdaptCycle[i-1] - ( 1 - Alpha1[i] ) * ( 1 - Alpha1[i] ) * AdaptCycle[i-2];
}

Trigger = Ref( AdaptCycle, -1 );

BullSig = IIf( Cross( AdaptCycle, Trigger ), True, False );
BearSig = IIf( Cross( Trigger, AdaptCycle ), True, False );


Plot( AdaptCycle, "AdaptCycle", colorLightBlue );
Plot( Trigger , "Trigger", colorRed );
Plot( 0 , "", colorWhite, styleDashed );

if ( Arrows )

PlotShapes( shapeUpArrow*BullSig, colorBrightGreen );
PlotShapes( shapeDownArrow*BearSig, colorRed );
}