自動交易,取消委託單

  •   459 
  • 最後發表   散散惹人愛  2021 十一月 16
散散惹人愛 發文於   2021/11/08

1.請問如何能夠做到 0930 00 以前下單之委託單,如未能成交委託單,即設定取消?

執行紀錄可見,110年11月8日

3588通嘉,於9時2分0秒     刪除1筆委託單後

3588通嘉,又於9時2分1秒 下單2筆委託單

維持委託2筆 下單 135元,待到9時42分17秒始成交

針對這種情形,想設定9時30分鐘前如未成交即取消委託單。

2. 復自執行紀錄可知 ,執行自動下單並未停損,

原先設定跌1.2%以上,則停損出場。 當盤中10時37分43秒 跌到131.5的價位(-1.87%)

並未出觸發停損機制而下單出場,也不清楚竟未啟動停損

本次執行監控畫面及自動交易程式碼如下,請XQ 協助:


 

input:percent(100); setinputname(1,"量增比例%");

input:Length(200); setinputname(2,"均量期數");

input:XLimit(True); setinputname(3,"限制最低觸發門檻");

input:atVolume(500); setinputname(4,"最低觸發張數");

input:TXT("建議使用分鐘線"); setinputname(5,"使用說明");

value5 = xfMin_EMA("15", Close,12); //計算15分鐘線12期收盤價的XQ EMA

value6 = xfMin_EMA("5", Close,5);

 variable: AvgVolume(0);

 settotalbar(Length + 3);

 AvgVolume=Average(volume,Length);

if XLimit and volume>200 then

begin

condition1 =Volume > atVolume and volume > AvgVolume *(1+ percent/100) and close>GetField("收盤價", "D")[1] and close>value5 and value5>value5[1];

condition2 =Volume > Volume[1] and volume > AvgVolume *(1+ percent/100)and close>GetField("收盤價", "D")[1] and close>value5 and value5>value5[1];

end;

var: long_condition(false);{ 進場買進作多 }

long_condition = Condition1 or Condition2;

if Position = 0 and long_condition  and time>090130 and time<090800 then begin

    SetPosition(1, AddSpread(Close, -3),label:="下2檔低買入");Print("低買一");

end else 

if Position = 1 and long_condition and time>090130 and time<090800  then begin

SetPosition(2, AddSpread(Close, -4),label:="下3檔低買入");Print("低買二");

/////以買進價為基礎

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

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

input: losss_percent(1, "停損(%)");

if Position =1 and Filled =1 then begin

if losss_percent > 0 and Close <= GetField("收盤價","D")[1]*(1-0.01*losss_percent) then begin

SetPosition(0, market);

{ 依照成本價格設定停損/停利 }

    end else if profit_percent > 0 and Close >= FilledAvgPrice*(1+0.01*profit_percent) then begin

{ 停利 }

SetPosition(0, market);

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

{ 停損 }

SetPosition(0, market);

end;

end;

end;


 

 

 

  • 按讚來自於
  • sb04870487
排序方式: 標準 | 最新
散散惹人愛 發文於   2021/11/08

執行紀錄 如附件

附加文件

XQ小幫手 發文於   2021/11/10

Hello 散散惹人愛,

 

1.

您只需要加上當現在時間大於09:30之後將部位調整成與庫存相同即可。

 

2.

您停損停利的先決條件是 if Position =1 and Filled =1 then begin。

那麼當您部位為2口的時候自然就不會停損停利了。

建議您可以調整成為 if Position > 0 and Filled > 0 then begin。

 

附上交易腳本供您參考。

另外小幫手測試時input若設為 True False 會出現錯誤,目前已請工程師確認。

附加文件

散散惹人愛 發文於   2021/11/10

 time_exceed = True; 是指55行程式碼有問題?明天在實測看看,謝謝。

 

XQ小幫手 發文於   2021/11/12

Hello 散散惹人愛,

 

小幫手指的 input若設為 True False 會出現錯誤 是在說第三行的 input:XLimit(True,"限制最低觸發門檻"); 這部分喔。

建議您測試的時候將這段以及用到此input的部分(第16行)去掉。

XQ小幫手 發文於   2021/11/16

Hello 散散惹人愛,

 

input使用True False會出錯的問題已修復。

發表回覆
Close