自動交易程式碼如下
input: ordersize_w(30, "每筆交易金額(萬)");
input: exit_period(1, "收盤前N分鐘平倉");
var: market_close_condition(false); { 是否已經進入收盤階段 }
market_close_condition = EnterMarketCloseTime(exit_period);
if Position = 0
and q_Last > high[1]
and AbsValue((q_DailyHigh-q_Last)/q_Last) < 0.025
and q_Last > open
and GetSymbolInfo("IsDayTrading")
and GetQuote("PriceChangeRatio") < 4
then begin
var: order_price(0);{ 預期委託價格 }
var: order_qty(0);{ 換算後數量 }
order_price = AddSpread(Close, 1);
order_qty = (ordersize_w * 10000) / (order_price * 1000);
SetPosition(order_qty, close);{ 以指定價格買入指定數量 }
end;
if Position >= 1 and Filled >= 1 then begin
{ 計算損益% }
var: plratio(0);
plratio = 100 * (Close - FilledAvgPrice) / FilledAvgPrice;
if plratio >= 2.5 then SetPosition(0,close);{ 停利 }
if plratio <= -2 then SetPosition(0,close);{ 停損 }
end;
if Position > 0 and market_close_condition then begin
SetPosition(0,market);{ 進入收盤階段: 出場 }
end;

證券自動停利停損部分,為什會一下送出委託一下又取消委託,最後還是成交
附上完整執行紀錄,請小編指導是否要改寫程式,感謝。
2 評論