我寫的etf策略2255成功1個失敗 但是回測沒有資料是為什麼
以下是我的策略內容
// 策略名稱:ETF策略2/8-72萬勝率60%
var: HoldDays(0); // 宣告一個專門紀錄持有天數的變數
// --- 【1. 商品過濾條件:強制限定為 ETF】 ---
// 在台灣市場,SymbolType 為 4 代表該商品是 ETF
condition1 = SymbolType = 4;
// --- 【進場條件計算】 ---
condition2 = LinearRegSlope(Volume, 5) > 0;
value1 = GetField("成交金額(元)");
condition3 = value1 > Average(value1, 5);
condition4 = High = Highest(High, 5);
condition5 = GetField("開盤委買", "D") >= 300;
// 計算布林下緣 (使用 value1 存儲數值)
value2 = Average(Close, 20) - 2 * StandardDev(Close, 20, 1);
condition6 = Close > value2 * 1.01;
condition7 = Bias(6) < 15;
condition8 = ATR(15) <= 5;
condition9 = (Highest(High, 20) - Lowest(Low, 20)) / Lowest(Low, 20) > 0.03;
condition10 = Close >= 10;
condition11 = Close <= 20;
// --- 【持有天數計數邏輯】 ---
if Position = 0 then
HoldDays = 0 // 沒部位時,計數器歸零
else if date <> date[1] then
HoldDays += 1; // 有部位且換日,計數器加 1
// --- 【進場執行】 ---
if
condition1 and condition2 and condition3 and condition4 and condition5
and condition6 and condition7 and condition8 and condition9 and condition10 and condition11
and Position = 0 // 確保目前沒持股
then begin
HoldDays = 0; // 進場當刻再次確保計數器從0開始
SetPosition(1, Market);
end;
// --- 【出場條件機制】 ---
if Position = 1 then begin
// 1. 停損 5%
if Close <= FilledAvgPrice * 0.95 then SetPosition(0, Market);
// 2. 盤中上漲 3%
if High >= FilledAvgPrice * 1.03 then SetPosition(0, Market);
// 3. 手動持有天數滿 30 天
if HoldDays >= 30 then SetPosition(0, Market);
end;

1 評論