自動交易實單無法下單 但回側有數據

  •   403 
  • 最後發表   will0612  2024 六月 23
will0612 發文於   2024/06/12

想請問一下自動交易  回測都有數據但是實際要用模擬單 都沒有顯示下單,然後都無法執行,請問是什麼問題???

排序方式: 標準 | 最新
虎科大許教授 發文於   2024/06/13

這個要看腳本才知道。

  • 按讚來自於
  • love0612
will0612 發文於   2024/06/13

再麻煩你指教了

input: exit_period(5, "收盤前N分鐘平倉");

input: profit_percent(10, "停利(%)");

input: loss_percent(4, "停損(%)");

var:bcost(0);

var: market_close_condition(false); { 是否已經進入收盤階段 }

var:short_condition(true);

 

short_condition = currenttime >=093600 ;

 

if position = 0 and filled = 0 

 

 

 

and getField("成交金額(元)","D")[1]>10000000

 

and  getSymbolField("otc.tw", "收盤價", "5")<getSymbolField("otc.tw", "收盤價", "D")[1]

 

and C<200

then

 

if closed(1)>0 and bcost=0 

then begin

bcost=closed(1);

end;

 

if bcost <> 0 and date<>date[1] 

then

value5+=1;

 

if value5=3

and short_condition

and close<closed(1)*1.08

then begin  

value5=0;

bcost=0;

setposition(-1,Close+0);

end;

 

 

 

market_close_condition = EnterMarketCloseTime(exit_period);

 

if Position = -1 and Filled = -1 then begin

{ 依照成本價格設定停損/停利: 請注意當作空時, 判斷是否獲利的方向要改變 }

 

if profit_percent > 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin

{ 停利 }

SetPosition(0);



虎科大許教授 發文於   2024/06/13

由於你沒有提供使用的頻率是什麼,看到date<>date[1],我估計你用的是分鐘頻率。若有勾選逐筆洗價,則問題出在if bcost <> 0 and date<>date[1] 這個條件。bcost因為沒有用intrabarpersist宣告,所以在第二根K棒才會被設為前一天的收盤價,而第二根K棒的date是等於date[1],所以value5沒有機會加1,亦即一直保持0的預設值,因此不會有訊號。

宣告bcost時,加intrabarpersist就可解決問題。

will0612 發文於   2024/06/13

先謝謝教授 原來是我宣告 沒有使用intrabarpersist 

will0612 發文於   2024/06/13

教授 我還想問一個問題

 

我的時間 為什麼只有放在這裡  才會觸發時間的條件呢

 

一般來說 我都正常放在if position = 0 and filled = 0 下面 就會觸發時間 0906的時候才進場 但是 似乎 好像用了begin end這一區塊 我的時間擺在這裡就不會觸發  變成要往下擺 這個部份我一直卡住 雖然解決了  但是我並沒有理解為什麼會這樣

 

short_condition = currenttime >=090600 ;

 

if value5=3

and short_condition

and close<closed(1)*1.08

then begin  

 

謝謝你

虎科大許教授 發文於   2024/06/13

請說明short_condition原來放在哪裡不行。把不行的程式碼貼上來,才能判斷問題。

will0612 發文於   2024/06/14

好的 我結圖給您看看

附加文件

虎科大許教授 發文於   2024/06/14

放在原本的位置,只是9點6分開始,且昨天日收盤價大於0且bcost=0時,計算bcost。

最後兩個if並不受9點6分的限制。

  • 按讚來自於
  • love0612
will0612 發文於   2024/06/22

教授完蛋了  我這幾天 試過 使用自動交易 一樣無法實單ㄟ  是因為value5 或是Closed的問題嗎?  因為一直交叉測試 都沒有解決 只好再上來請教您

虎科大許教授 發文於   2024/06/22

請說明無法實單交易,是沒有訊號,還是有其他錯誤訊息?將最後的版本放上來,我幫忙看看問題在哪裡。

顯示更多回應 發表回覆
Close