交易腳本回測 出場指令無效且大量失敗

  •   79 
  • 最後發表   蓬蘇王杜  2025 六月 21
蓬蘇王杜 發文於   2025/06/20

我使用以下交易腳本回測所有上市櫃類股  我寫的跌破10日低停利這個條件都會無效 , 我也看不出語法有什麼問題...

我大概貼一些出來  ,我往下再貼出完整程式碼  ,  另外問為什麼回測2千多檔上市櫃類股 會大量失敗? 大量逾時 終止運算? 

我在附上我的截圖失敗畫面 ,謝謝各位好心人的回答

 

low_out(10,"低點出場");

low_point = lowest(low,low_out);

//停利

if position > 0 and filled > 0 and close < low_point then setposition(0,label:="停利");

 

 

//參數
input: pos_1(10,"試單(萬)"),
       pos_2(20,"加碼(萬)"),
       sstop(4.8," 停損% "),
       aadd(5," 加碼% "),
       high_in(8,"日均"),
       low_out(10,"低點出場");

//變數
vars: order_pos(0),
      max_pos(0),
      stop_price(0),
      add_price(0),
      min_bar(0),
      high_point(0),
      low_point(0);

//取資料
min_bar  = GetField("收盤價", "30")[1];
high_point = average(close,high_in); //8日均
low_point = lowest(low,low_out);

//進場邏輯
condition2 = min_bar <= high_point ;      //前一根k
condition3 = close >= high_point ;        //穿越8日線
condition4 = filledavgPrice*filled*1000 > 10000*pos_1 ;  // 判斷是否已加碼

//進場
if position = 0 and filled = 0 and condition2 and condition3 then begin
   order_pos = IntPortion((pos_1 * 10000) / (close * 1000));
   if order_pos > 0 then begin
      setposition(order_pos,label:="進場");
   end;
end;

//停損邏輯:依加碼與否切換條件
if position > 0 and filled > 0 then begin
   if not condition4 then begin  // 尚未加碼
      if close < filledavgPrice * (1 - (sstop * 0.01)) then
         setposition(0, label:="初始停損");
   end
   else begin  // 已加碼
      if close < filledavgPrice * (1 - ((sstop / 2) * 0.01)) then
         setposition(0, label:="加碼後停損");
   end;
end;

//加碼
if position > 0 and filled > 0 and close >= filledavgPrice*(1+(aadd*0.01)) and not condition4 then begin
   max_pos = IntPortion((pos_2 * 10000) / (close * 1000));
   if max_pos > 0 then begin
      setposition(max_pos,label:="加碼");
   end;
end;

//停利
if position > 0 and filled > 0 and close < low_point then setposition(0,label:="停利");


print("20高",high_point,"10低",low_point);

   

 

附加文件

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

close不可能小於low_point,所以close < low_point不可能成立。請改成

low_point = lowest(low[1], low_out);

蓬蘇王杜 發文於   2025/06/21

對... 謝謝教授

發表回覆
Close