วันอาทิตย์ที่ 22 กันยายน พ.ศ. 2556

+++ สำหรับคำนวณหาพวกค่า New High , New Low (Amibroker)

/* get the highest high from last 52 weeks */
HighLast52week = LastValue( HHV( High, 5 * 52 ) );

/* now find the bar when this happened */
HighLast52bar = HighLast52week == High;

/* find the lowest low since then */
LowSinceLast52High = LastValue( LowestSince( HighLast52bar, Low ) );

/* dividing close by lowest low will give strength */
Strength = Close / LowSinceLast52High;

/* the detection threshold, here we filter out the stocks that closed less than 10% over the low - this might be used to get only the top 8 */
Threshold = 1.1;

/* a buy is generated when current bar is after the 52 week high, Strength is above threshold and close crossed above moving average */
Buy = Cum( 1 ) > HighLast52Bar AND Strength > Threshold AND Cross( Close , EMA( Close, 28 * 5 ) );

/* find the number of bars since last two consecutive highs */
Us = BarsSince( ( H > Ref( H,-1 ) ) AND (Ref(H,-1) > Ref(H,-2) ) );

/* find the number of bars since last two consecutive lows */
Ds = BarsSince( ( L < Ref( L,-1 ) ) AND ( Ref( L, -1) < Ref( L, - 2 ) ) );

/* outside bar is reached then it is treated in the opposite way to the next bar.*/
Sd1 =IIf( Us==0, IIf( Ref(L,-1) != LowestSince( Ds==0, L ), 1, 0),
IIf( Ds==0, IIf( Ref(H,-1) != HighestSince( Us==0, H ), -1, 0),
0));
Sd2 = IIf( Sd1 == 1, IIf( Ref( BarsSince(Sd1==1), -1) > Ref( BarsSince( Sd1 == -1), -1), 1, 0),
IIf( Sd1 == -1, IIf( Ref( BarsSince(Sd1==1),-1) < Ref( BarsSince( Sd1 == -1),-1), -1, 0), 0 ) );

Graph0 = ValueWhen( Sd2, Sd2 ); /* sample and hold non-zero values */

1 ความคิดเห็น: