COCO研究院

 找回密碼
 註冊
搜索
查看: 6461|回復: 11

請教amibroker高手

[複製鏈接]
發表於 11-11-26 15:41 | 顯示全部樓層 |閱讀模式
本帖最後由 balance 於 11-11-26 03:48 PM 編輯

最近加入程式交易行列,主要的原因是: 人性!幾個amibroker的問題請教高手們:

1. amibroker的特性在array 處理上實在神奇,。我只有接觸ninjia一點。發覺C# based的差異很大。請問,其他常用的(tradestation和 multichart等)都要類似的array處理觀念,還是amibroker獨特的功能。

我問的原因是,在選定trading system的基本平台,很重要的是整體開發的環境。如果寫的code非常集中在amibroker array 功能,恐怕以後要搬到其他的很難受,無論要搬的原因是自願或是被迫....

2. amibroker的debug 能力非常陽春。只有 _trace 或printf. 請問大家平時真的是就是這麼debug嗎?
沒有debugger,或是 stepping, 然後inspect variable的能力? 其他的平台都是如此?我知道 ninja可以用visual studio attached process 做 source level debugging.
如果真是如此,再加上 array 的神奇功能,恐怕debug會發狂。 譬如,請問如何printf/_Trace 整個array 來做debugging?

通常我學習新的語言的方式都是看samples,然後進debugger,一步一步trace。這個對amibroker簡直是天書。。。
譬如,最近在看wolfe wave 的AFL code, 有兩個版本, 舊的是在在amibroker 網站, 新版是在這裡 (新版是從yahoo amibroker出來的)。

舊版的用到peak/trough, 因為有'look into the future'所以不能做trading system... 新版的自己寫的 peak/trough functions, 如下:

  1. //======== Fractal Peak Trough ========
  2. x = BarIndex();
  3. function pkID( nb )
  4. {
  5.     p = H == HHV( H, 2 * nb )AND Ref( HHV( H, nb ), nb ) < H;
  6.     return p AND LastValue( x ) - ValueWhen( p, x ) > nb;
  7. }
複製代碼


我在猜, pkID function是算peak的ID, return array of ‘距離你現在最起碼 nb 個bar’的peak (相對高點),然後把那個高點的index存到array 你現在位置的內容裡 (中文寫起來實在很繞口。。) nb是你在找peak的時候,peak點和現在的點的最起碼距離(bar數)。
我已經盯了這兩行code一整天了,還是clueless. 又無法把 array dump 出來看,實在難過。。。

但,也是因為amibroker的array處理功能,我覺得對開發程式交易簡化很多(一旦你懂了。。。)。 譬如,我就很難想像用C#/ninja 可以兩行就寫的出來peak function.

請問大家都是怎麼克服這個‘初期難關’的?? 如果能開釋這兩行code, 那真是大功大德!


多謝!
發表於 11-11-26 16:14 | 顯示全部樓層
會寫程式真好

評分

參與人數 1金錢 +5 收起 理由
jinace + 5 我是業餘的啦!

查看全部評分

發表於 11-11-26 16:28 | 顯示全部樓層
回復 1# balance

就我自己的經驗~

要除錯用print就夠了~

幾個主要的原因:
1.) 腳本通常行數不多
2.) 腳本通常變數不多
3.) stepping的模式會影響tick的即時性
想必balance大應該是開發大型程式的經驗比較多

但金融商品分析主要都是做統計這類單純的算數或邏輯判斷而已


---

至於AB的程式碼我就沒什麼研究了...

評分

參與人數 1金錢 +5 收起 理由
kilroy + 5 大大是專業的程式寫作高手

查看全部評分

發表於 11-11-26 16:39 | 顯示全部樓層
本帖最後由 GnuHomot 於 11-11-26 04:46 PM 編輯

譬如說想看某根K棒算出來的p值可以加入這段
if(Status("action")==actionCommentary)
{
printf("p: "+WriteVal(p));
}
點選K棒後,可以在Interpretation的視窗看到p值

或者是想把所有p值都印出來看的話
if(Status("action")==actionScan)//只在Scan的時候執行,避免一直產生Trace結果
for(i=0; i<barcount; i++)
_Trace(writeval(p[ i ]));

上面兩種是我會用到的方法,請參考
發表於 11-11-26 16:58 | 顯示全部樓層
本帖最後由 lchardie 於 11-11-26 05:00 PM 編輯

tradestation, multichart, ab 都是用 array
我很難想像有哪一套軟體不是用 array 
HTS 也是 (他是模仿 TS 的)
 樓主| 發表於 11-11-26 18:25 | 顯示全部樓層
回復 4# GnuHomot


   多謝。很有用。
再問,有人對這個用經驗的嗎? 看spec不錯。。。
發表於 11-11-26 21:12 | 顯示全部樓層
回復  GnuHomot


   多謝。很有用。
再問,有人對用經驗的嗎? 看spec不錯。。。 ...
balance 發表於 11-11-26 06:25 PM


大大真是太厲害了
會寫程式真好

像是 debug 還有這個看 spec 的

小弟都用不到(因為不會用吧 XD)
 樓主| 發表於 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數)

  1. Ref( HHV( H, nb ), nb )< H
複製代碼
是確認往右邊(look into the future!!) nb 個bar,我是最高的。
  1. H == HHV( H, 2 * nb )
複製代碼
是確認我是往左看 2xnb 裡最高的,為什麼是 2x 呢,就是要解決這個問題。 1.jpg
(這個例子,nb=3)

兩個AND起來就是 peak.
第二行中
  1. LastValue( x ) - ValueWhen( p, x )> nb
複製代碼
是確認有沒有'偷看‘nb, 解決了'look into the future'的問題!!

我是最後問到Tomasz 本人的回答,應該沒有錯。說的這裡,還是覺得這位老兄實在不是做生意的材料,還是個engineer. 在yahoo forum上,老是一副’我最聰明,你們都是笨蛋的態度‘。還好AB功能強大,收費合理,否則。。。 最後我還回馬槍的小小損了他一下。

有興趣的可以看看是否好用.
  1. // peak3, from harmin1.1.1 // bi = Cum(1)-1; // BarIndex();
  2. bi = BarIndex();

  3. strength = Param("Strength",5,1,15,1);
  4. function GetTop( bars )
  5. {
  6.     Top = H == HHV( H, 2 * bars ) AND Ref( HHV( H, bars ), bars ) < H;
  7.     Top = Top AND LastValue( bi ) - ValueWhen( Top, bi ) > bars;
  8.     return Top;
  9. }

  10. function GetValley( bars )
  11. {
  12.     Valley = L == LLV( L, 2 * bars ) AND Ref( LLV( L, bars ), bars ) > L;
  13.     Valley = Valley AND LastValue( bi ) - ValueWhen( Valley, bi ) > bars;
  14.     return Valley;
  15. }


  16. // Build fractals array

  17. P1 = GetTop( strength );
  18. V1 = GetValley( Strength );

  19. P1 = IIf( P1, IIf( ValueWhen( P1, bi, 2 ) < ValueWhen( V1, bi ), P1, IIf( ValueWhen( P1, H, 2 ) > H, False, P1 ) ), P1 );
  20. //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);
  21. 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 );


  22. V1 = IIf( V1, IIf( ValueWhen( V1, bi, 2 ) < ValueWhen( P1, bi ), V1, IIf( ValueWhen( V1, L, 2 ) < L, False, V1 ) ), V1 );
  23. //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);
  24. 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 );


  25. // P1H1 = ValueWhen( P1, H );
  26. // P1Bar1 = ValueWhen( P1, bi );
  27. // P1H2 = ValueWhen( P1, H, 2 );
  28. // P1Bar2 = ValueWhen( P1, bi, 2 );
  29. // V1L1 = ValueWhen( V1, L );
  30. // V1Bar1 = ValueWhen( V1, bi );
  31. // V1L2 = ValueWhen( V1, L, 2 );
  32. // V1Bar2 = ValueWhen( V1, bi, 2 );

  33. // -----------------------------------

  34. //SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
  35. //GraphXSpace = 5;
  36. SetChartOptions(0, chartShowDates);
  37. //Plot(C,"\nPeak3",colorWhite,styleCandle);
  38. PlotShapes(shapeSmallCircle*P1,colorRed,0,H,10);
  39. PlotShapes(shapeSmallCircle*V1,colorBlue,0,L,-10);

  40. a = LineArray( 2515, 26.694, 2569, 24.0017,  1 );
  41. Plot( a, "", 42, 1 | 2048, 19.5 );

  42. //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分析還是不夠聰明。。。

發表於 11-12-17 16:48 | 顯示全部樓層
我覺得..有沒有look into the future是AB說了算而不是自己說了算,分享一下最近遇到的經驗:
絕對不要用任何ref( xxx, 1)取到的值來運算交易訊號!!

譬如說我的程式是這樣寫
A=ref(C,1);
B=ref(A, -1);
buy=B>0;
照理說,B其實就是等於C,沒有look into future。
但是...
我這樣做Backtest出來結果是錯的,做walk forward optimizer時程式會當掉。
 樓主| 發表於 11-12-17 20:16 | 顯示全部樓層
這個應該是bug, 除了不合理之外還crash.
應該反映給AB.
發表於 11-12-26 08:35 | 顯示全部樓層
peak/trough如果能用好,可以做出很多以前实现不了的pattern识别程式,只是都不能backtesting。如果能解决'look into the future'那可太好了。
發表於 12-10-2 00:15 | 顯示全部樓層
可以dump array啊。
用AddColumn(close,"close",1.4);
Filter =1;
就可以了
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-5-16 04:25

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook