COCO研究院

 找回密碼
 註冊
搜索
樓主: kilroy

[教學] [分享] 用AB踏入外期程式交易

  [複製鏈接]
發表於 14-3-25 00:41 來自手機 | 顯示全部樓層
謝謝教導!之前是看到大大已經說了,但我那時不太明白,現在自己測試了,聽大大再解說,明白了。
發表於 14-3-25 21:46 | 顯示全部樓層
大大, 又有問題請教, 如果我想設定每天收市前, 平了我所有的倉, 應如何寫? 我測試如下:
ExitAllPositionsTime = 160000;

Buy=xxxxx;
Sell=xxxxx OR  (TimeNum() >= ExitAllPositionsTime);
Short=xxxx;
Cover=xxxxx OR  (TimeNum() >= ExitAllPositionsTime);

是否正確? 我測試了似乎沒問題, 但沒信心......

別外, 如果上面正確, 那多空對反時, 我就想不到如何寫, 如:

Buy=xxxxxx;
Short=xxxxxx;

Sell = Cover = (TimeNum() >= ExitAllPositionsTime);

Buy = Cover = ExRem(Buy, Short);
Short = Sell = ExRem(Short, Buy);


但結果是會坐盤過夜.........謝謝指導.
發表於 14-3-25 23:06 | 顯示全部樓層
kilroy 發表於 14-3-24 08:45
Hi,

小弟覺得是計算還有欄位的問題

Hi,
因我是新手, 請問可否用短消息發聯絡給我? 謝!
發表於 14-3-26 21:13 | 顯示全部樓層
經過我兩天測試, 我發現了, 似乎ibcontroller可以自動buy和short, 但sell和cover郤不會, 再研究, 我想問題出在這裡:

捕获.PNG

捕获2.PNG

我按紅色按鍵也好, 他自動平倉也好, 都會出現問題, 我看來是 currency問題, 大大有沒有什麼好提議? 我google了但看來沒有其他人有這問題........

謝謝!!
發表於 14-3-26 23:26 | 顯示全部樓層
本帖最後由 joshsmi 於 14-3-26 23:30 編輯
andrewchan 發表於 14-3-24 07:54
Hi,

以下是Backtest mode

Your code is wrong

You can imitate individual backtest in exploration also.

See here example made by someone of the AmiBroker forum

Exploration


Default backtest without custom backtest usage


As you can see same output of same column names






發表於 14-3-27 06:45 | 顯示全部樓層
joshsmi 發表於 14-3-26 23:26
Your code is wrong

You can imitate individual backtest in exploration also.

Hi Joshsmi,

It's amazing, could you pls tell me what are the AFL codes I need to insert to my orig AFL in order to make the result of backtest & explore mode the same? Thx a lot!
發表於 14-3-27 13:25 | 顯示全部樓層
andrewchan 發表於 14-3-27 06:45
Hi Joshsmi,

It's amazing, could you pls tell me what are the AFL codes I need to insert to my ori ...

hi andrew,
just wonder why you so insist to have the same result? i suppose you want to get the signal from explorer and then trade it manually? will you try to make it auto? i am studying it but i am stuck now.....


發表於 14-3-27 20:31 來自手機 | 顯示全部樓層
Hi Joshsmi,
Yes, I want to do the auto trade, thx!
發表於 14-3-27 22:59 | 顯示全部樓層
andrewchan 發表於 14-3-27 20:31
Hi Joshsmi,
Yes, I want to do the auto trade, thx!

我不是osdak ;)

As for autotrading, there are examples in Read me file of IBcontroller. Also look at examples by user Barry Scarborough in AB's users library. There are others too there.
發表於 14-3-27 23:39 | 顯示全部樓層
joshsmi 發表於 14-3-27 22:59
我不是osdak ;)

As for autotrading, there are examples in Read me file of IBcontroller. Also look a ...

Pls accept my apologies for the typo on my last message.
 樓主| 發表於 14-3-28 00:32 | 顯示全部樓層
osdak 發表於 14-3-25 21:46
大大, 又有問題請教, 如果我想設定每天收市前, 平了我所有的倉, 應如何寫? 我測試如下:
ExitAllPositionsTi ...

Hi,

搞定了嗎?

小弟最近沒來回覆~ 不知道大大目前狀況如何了?
發表於 14-3-28 00:37 | 顯示全部樓層
joshsmi 發表於 14-3-27 22:59
我不是osdak ;)

As for autotrading, there are examples in Read me file of IBcontroller. Also look a ...

haha, but i am!

i am desperately looking for more info. on autotrading. thanks for the info, i think i need to take a look on barry's material.
發表於 14-3-28 00:51 | 顯示全部樓層
kilroy 發表於 14-3-28 00:32
Hi,

搞定了嗎?

hi, 經過多日測試, 還有兩個問題, 第一個是在於ibcontroller, 我於上面的帖提出了, 我發現我的平倉單是下不了, 而且currency會是usd, 明天會繼續研究.

第二個問題, 是關於 barcomplete,

barcomplete = BarIndex() < LastValue(BarIndex());
我不加barcomplete, 於ib中是可以自動下單(但平不了倉, 就是因為上面的原因), 但一加barcomplete, 就沒有下單, 我發
現有人問過相同問題:

www mail-archive com/amibroker@yahoogroups.com/msg36321.html
但可惜沒人回答.但我不加barcomplete, 因為是用cross, 所以AB於K中不停下單(因為不停穿來穿去.....)



我的想法是, barcomplete是比較現在的barindex,如果一有新的barindex----lastvalue(barindex()), 那就會回傳true
給barcomplete, 但這一刻, 其實已經在跑新的K, 那就是說, 於buy= cross(xxx) and barcomplete中, cross(xxx)於當
根K是TRUE時, barcomplete是false, 一直到barcomplete是TRUE時, 那cross(xxx)已經不再是TRUE了, 所以就無法下
單....但想歸想,google的結果是大家都說可以用, 那就應該是有些東西我還沒弄明白........會再研究......
 樓主| 發表於 14-3-28 01:58 | 顯示全部樓層
osdak 發表於 14-3-28 00:51
hi, 經過多日測試, 還有兩個問題, 第一個是在於ibcontroller, 我於上面的帖提出了, 我發現我的平倉單是下 ...

Hi,

沒辦法下出去是因為

barcomplete 和 newbar 相互抵觸

所以 new那邊要改寫一下

參考看看了
發表於 14-3-28 02:49 | 顯示全部樓層
osdak 發表於 14-3-28 00:51
hi, 經過多日測試, 還有兩個問題, 第一個是在於ibcontroller, 我於上面的帖提出了, 我發現我的平倉單是下 ...

AB's Status() function has these options for bar completion

From the AB manual www.amibroker.com/guide/afl/status.html
"lastbartimeleft" - returns number of seconds to the completion of current last bar. Works for time-based bars only. Note that for proper operation this requires database timeshift to be set properly (so dates displayed on chart match your local computer time zone). (v5.60)

"lastbartimeleftrt" - it works like "lastbartimeleft" but uses the most recent RT stream update time instead of Now(). Also added Status("lastrtupdate") - time of last RT stream update depends on RT plugin to deliver correct DateUpdate / TimeUpdate data. If plugin or date source sends incorrect datetimestamps or does not send DateUpdate/TimeUpdate correctly this function will not operate properly. Note that most data sources send weird (not current) datetime stamps on weekends. Also IQFeed plugin sends DateUpdate/TimeUpdate only inside regular trading hours. (v5.60)


So try this

diff =
Interval() - Status( "lastbartimeleft" ); // or Status( "lastbartimeleftrt" );
Secondsafter =
5; // 5 seconds after bar completion

Title = StrFormat( "%g", diff );

if ( diff == Secondsafter || diff == ( Interval() + Secondsafter ) ) // if x seconds after bar completion
{
   
Say( "Hello" );
}

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

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

GMT+8, 24-11-22 11:23

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |