股票跌破開盤價和開盤價要小於6%以下,然後進場做空

  •   357 
  • 最後發表   hello10282000  2024 十一月 24
hello10282000 發文於   2024/11/24

跟大家請教一下問題

邏輯如下

股票跌破開盤價和開盤價要小於6%以下,然後進場做空

去執行回測時,沒有進場放空的紀錄(測試股票為達方113/11/22)

程式碼如下

//設定變數
value1 = GetField("Open", "D");
value2 = getField("Close","D")[1];
value3 = value2*0.9;
value4 = value2*1.06;
value5 = value2*1.1;

//以金額計算交易數量

input: ordersize_w(100, "每筆交易金額(萬)");


input: profit_percent(2, "停利(%)");
input: profit_drawback_percent(0.5, "停利回跌(%)");
input: loss_percent(1.5, "停損(%)");


    var: order_price(0);        { 預期委託價格 }
    var: order_qty(0);          { 換算後數量 }

{ 
    以成交價為基礎, 設定固定停損以及移動停利
}
if profit_percent = 0 then raiseruntimeerror("請設定停利(點)");
if profit_drawback_percent = 0 then raiseruntimeerror("請設定停利回跌(點)");
if profit_drawback_percent > profit_percent then raiseruntimeerror("停利(點)需大於停利回跌(點)");
//進場條件


if Position = 0 and Filled = 0 
   and time >= 090100
   and time <= 133000
   and barFreq = "min"


   and close < value1
  // and Open < value4   
   then begin


    order_price = AddSpread(value5, 1); 
    order_qty = (ordersize_w * 10000) / (order_price * 1000);
                                { 計算出來的數值如果不是整數, 傳入SetPosition時會自動捨去小數位數 }
                                { 例如 SetPosition(2.5) 執行時會被轉成 SetPosition(2) }

    SetPosition(-order_qty, order_price);       { 以指定價格買入指定數量 }
end;


if Position < 0 and Filled < 0 then begin
    { 依照成本價格設定停損/停利 }

        var: intrabarpersist max_profit_percent(0); { 啟動停利後最大獲利百分比 }

    if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin
        { 停損 }
        SetPosition(0, MARKET);
        max_profit_percent = 0;
    end else begin

        { 判斷是否要啟動停利 }
        if max_profit_percent = 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin
            max_profit_percent = Close;
        end;    
    if max_profit_percent <> 0 then begin     
            if Close <= max_profit_percent + profit_drawback_percent then begin
                { 停利 }
                SetPosition(0, MARKET);
                max_profit_percent = 0;
            end else if Close > max_profit_percent then begin
                { 移動最大獲利點 }
                max_profit_percent = Close;

                                   end else if close > value1 then begin
                    SetPosition(0, MARKET);     { 分K收盤小於開盤價就全部市價賣出 } 

                                       end else if close = value3 then begin
                    SetPosition(0, MARKET);     { 分K收盤等於漲停價以市價全部賣出 } 
                                                           end else if CurrentTime = 132300 then begin
                    SetPosition(0, MARKET);     
            end;    
        end;        
    end;

end;

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

你進場放空的價格是有問題的。用昨天收盤價乘以1.1再往上加一檔當作委託價,這個價位已經超過漲停價。系統會掛漲停價放空。這種情況很可能都無法成交。

hello10282000 發文於   2024/11/24

感謝許教授

我再改一下做測試,感謝。

發表回覆
Close