|  | 
 
 樓主|
發表於 11-12-17 13:45
|
顯示全部樓層 
| 本帖最後由 balance 於 11-12-17 01:52 PM 編輯 
 回復 1# balance
 
 
 (回答自己的問題,順便繼續分享我的學習過程)1. 上面的那段code, 個人覺得是很好找高低點的peak/trough function。 AB 內建的peak/trough 是 zigzag based, 這裡之前有討論過使用zigzag的缺點。而且zigzag的缺點我覺得是 高低用差價百分比來算不習慣,而且look into the future bar 數不確定,很難做好的trading system 的基礎。 這裡可以參考這裡。 fractal based 的優點是, look into the future bar 數你自己可以確定,而且是唯一的參數。
 
 2. 這段code是算 peak, 參數 nb 是 peak (相對高點左右的最起碼bar數)
 
 
 是確認往右邊(look into the future!!) nb 個bar,我是最高的。複製代碼Ref( HHV( H, nb ), nb )< H
是確認我是往左看 2xnb 裡最高的,為什麼是 2x 呢,就是要解決這個問題。
   (這個例子,nb=3)
 
 兩個AND起來就是 peak.
 第二行中
 是確認有沒有'偷看‘nb, 解決了'look into the future'的問題!!複製代碼LastValue( x ) - ValueWhen( p, x )> nb
 我是最後問到Tomasz 本人的回答,應該沒有錯。說的這裡,還是覺得這位老兄實在不是做生意的材料,還是個engineer. 在yahoo forum上,老是一副’我最聰明,你們都是笨蛋的態度‘。還好AB功能強大,收費合理,否則。。。 最後我還回馬槍的小小損了他一下。
 
 有興趣的可以看看是否好用.
 
 複製代碼// peak3, from harmin1.1.1 // bi = Cum(1)-1; // BarIndex();
bi = BarIndex();
strength = Param("Strength",5,1,15,1);
function GetTop( bars )
{
    Top = H == HHV( H, 2 * bars ) AND Ref( HHV( H, bars ), bars ) < H;
    Top = Top AND LastValue( bi ) - ValueWhen( Top, bi ) > bars;
    return Top;
}
function GetValley( bars )
{
    Valley = L == LLV( L, 2 * bars ) AND Ref( LLV( L, bars ), bars ) > L;
    Valley = Valley AND LastValue( bi ) - ValueWhen( Valley, bi ) > bars;
    return Valley;
}
// Build fractals array
P1 = GetTop( strength );
V1 = GetValley( Strength );
P1 = IIf( P1, IIf( ValueWhen( P1, bi, 2 ) < ValueWhen( V1, bi ), P1, IIf( ValueWhen( P1, H, 2 ) > H, False, P1 ) ), P1 );
//P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi,IIf(ValueWhen(P1,bi,0) < ValueWhen(V1,bi,0),IIf(ValueWhen(P1,H,0) >= H,False,P1),P1),P1);
P1 = IIf( P1 AND ValueWhen( P1, bi, 0 ) > bi AND NOT( ValueWhen( V1, bi, 0 ) > 0 AND ValueWhen( V1, bi, 0 ) < ValueWhen( P1, bi, 0 ) ), IIf( ValueWhen( P1, H ) <= ValueWhen( P1, H, 0 ), False, P1 ), P1 );
V1 = IIf( V1, IIf( ValueWhen( V1, bi, 2 ) < ValueWhen( P1, bi ), V1, IIf( ValueWhen( V1, L, 2 ) < L, False, V1 ) ), V1 );
//V1 = IIf(V1 AND ValueWhen(V1,bi,0) > bi ,IIf(ValueWhen(V1,bi,0) < ValueWhen(P1,bi,0),IIf(ValueWhen(V1,L,0) <= L, False,V1),V1),V1);
V1 = IIf( V1 AND ValueWhen( V1, bi, 0 ) > bi AND NOT( ValueWhen( P1, bi, 0 ) > bi AND ValueWhen( P1, bi, 0 ) < ValueWhen( V1, bi, 0 ) )  , IIf( ValueWhen( V1, L ) >= ValueWhen( V1, L, 0 ), False, V1 ), V1 );
// P1H1 = ValueWhen( P1, H );
// P1Bar1 = ValueWhen( P1, bi );
// P1H2 = ValueWhen( P1, H, 2 );
// P1Bar2 = ValueWhen( P1, bi, 2 );
// V1L1 = ValueWhen( V1, L );
// V1Bar1 = ValueWhen( V1, bi );
// V1L2 = ValueWhen( V1, L, 2 );
// V1Bar2 = ValueWhen( V1, bi, 2 );
// -----------------------------------
//SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
//GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
//Plot(C,"\nPeak3",colorWhite,styleCandle);
PlotShapes(shapeSmallCircle*P1,colorRed,0,H,10);
PlotShapes(shapeSmallCircle*V1,colorBlue,0,L,-10);
a = LineArray( 2515, 26.694, 2569, 24.0017,  1 );
Plot( a, "", 42, 1 | 2048, 19.5 );
//Plot( a, "", colorBrightGreen ,styleThick|styleOwnScale,15,30);
 參數 Strength (就是nb) 太小太大都沒用。
 
 
 最後提一點,我覺得這個peak/trough沒有look into the futue,但是 用code profile檢查還是有'look into the future',而且因為nb是parameter,所以look into the future是無限大。。。
 結論是,靜態的code分析還是不夠聰明。。。
 
 
 | 
 |