Amibroker AFL code for Cup and Handle exploration

MarketSecrets - Learn To Trade Like a Pro

Amibroker AFL code for Cup and Handle exploration:

Script:

_SECTION_BEGIN(“Cup and Handle exploration”);


MinPrice=0.1;
MinVolume=10000;

//Left side of Handle formation can occur anywhere from 2-25days – look at the last 25 bars AND get the number of bars since condition met.

LH=HHV(Close,25); // Highest close past 25 days.
BLH=HHVBars(Close,25); // Tells us # of bars that have past since high reached. Used to determine Lowest bar.

BH=LLV(Close,BLH); // Lowest close since the highest value was reached/
BBH=LLVBars(Close,BLH); // number of bars that have past since lowest value.

NBLH=BLH-BBH; // this is the number of bars in the formation of the left side handle. NBLH must be atleast 2 to be a valid handle formation.

// Now lets get the cup formation. Cup formation can occur anywhere from 23 to 145 days. The left side of the cup can be from 20-120 days AND the right side can be anywhere from 3-25 days.

// get the right side of the cup(low).

BC=LLV(Close,BLH+25); // look at 25 bars since the left side of handle.
BBC=LLVBars(Close,BLH+25);

// get the left side of the cup.

LC=Ref(HHV(Close,120),BBC*-1);
BLC=Ref(HHVBars(Close,120),BBC*-1);

// Get highest value before left side of cup started to form.

KC=Ref(HHV(Close,30),BLC*-1);
BKC=Ref(HHVBars(Close,120),BLC*-1);

Delta= LC/KC;

//Calculate the up/down relative price value during time frame RC (Right Cup Formation)

URPV=DRPV=0;
i=EndValue(BLH);
j=EndValue(BBC);
do
{
URPV =
IIf(Ref(Close,i*-1)>Ref(Close,(i+1)*-1),Ref(Volume,(i*-1))*Ref(Close,(i*-1))-Ref(Close,(i+1)*-1),URPV);
DRPV =
IIf(Ref(Close,i*-1)<Ref(Close,(i+1)*-1),Ref(Volume,(i*-1))*Ref(Close,(i+1)*-1)-Ref(Close,(i*-1)),DRPV);
i++;
} while (i<j);
Alpha = URPV/DRPV; // Should be >1

// Calculate Beta

DRPV=0;
i=EndValue(BBH);
j=EndValue(BLH);
do
{
DRPV =
IIf(Ref(Close,i*-1)<Ref(Close,(i+1)*-1),Ref(Volume,(i*-1))*Ref(Close,(i+1)*-1)-Ref(Close,(i*-1)),DRPV);
i++;
} while (i<j);
//Beta = URPV/DRPV;
//Gamma = log(Alpha) + log(Beta) + delta;

AddColumn(LH,”Left Handle”);
AddColumn(BH,”Bottom Handle”);
AddColumn(BC,”Bottom Cup”);
AddColumn(LC,”Left Cup”);
AddColumn(ALPHA,”Alpha”);
AddColumn(DELTA,”Delta”);
//AddColumn(BETA,”BETA”);
//AddColumn(GAMMA,”Gamma”);


Filter= NBLH>2 AND Close>BH AND BC<lc AND LH<=LC AND BC<LH AND BH<LH AND BH>.8*LH+.2*BC AND KC<lc AND Close>MinPrice AND MA(Volume,30) > MinVolume;
_SECTION_END();

 

Download File

error: Content is protected !!