他寫說原因執行時發生錯誤 資料異常,欄位=成交金額(元),頻率(日線),code=7,AT=TRUE
這個錯誤是代表什麼意思?
你圖片中的ETF商品是可以使用成交金額(元)的欄位資料。我測試是沒問題的。不清楚你的程式怎麼寫才造成這個問題。
{
腳本用途:ETF 策略整合版(固定買進 1 張 + 修正 BarsSinceEntry)
執行頻率:日
}
// ==========================================
// 1. 參數宣告區
// ==========================================
// --- 進場參數 ---
input: _p1_1(5, "成交量趨勢天數");
input: _p1_2(5, "成交值均量天數");
input: _p1_3(5, "創高天數");
input: _p1_4(300, "開盤委買張數門檻");
input: _p1_5_len(20, "布林天數"), _p1_5_std(2, "布林標準差"), _p2_5_offset(1, "布林下緣偏離%");
input: _p1_6_len(6, "乖離天數"), _p2_6_limit(15, "乖離門檻%");
input: _p1_7_len(15, "ATR天數"), _p2_7_limit(5, "ATR門檻");
input: _p1_8_len(20, "振幅天數"), _p2_8_limit(3, "振幅門檻%");
input: _p1_9_min(10, "最低股價門檻");
input: _p1_10_max(20, "最高股價門檻");
// --- 交易規模設定 ---
input: _BuyQty(1, "買進張數"); // 設定固定為 1 張
// --- 出場參數 ---
input: _StopLossPct(5, "停損百分比(%)");
input: _TakeProfitPct(3, "上漲出場門檻(%)");
input: _HoldDaysLimit(30, "持有期間(日)");
// ==========================================
// 2. 變數與環境設定區
// ==========================================
variable:
Cond1(false), Cond2(false),Cond3(false), Cond4(false), Cond5(false),
Cond6(false), Cond7(false), Cond8(false), Cond9(false), Cond10(false),
AllEntryCond(false), days_hh(0),
HoldCount(0); // 手動持有天數計數器
SetTotalBar(5000);
// ==========================================
// 3. 進場邏輯運算 (符合全部 10 個條件)
// ==========================================
// 1. 成交量 5 日趨勢朝上
Cond1 = UpTrend(Volume, _p1_1);
// 2. 成交值 > 5 日平均
Cond2 = GetField("成交金額") > Average(GetField("成交金額"), _p1_2);
value1=GetField("成交金額");
if value1 <> 0 then begin
// 執行您的交易邏輯
end;
// 3. 最高價創 5 日新高
if _p1_3 > 0 then days_hh = _p1_3 else days_hh = GetBarOffsetForYears(-1*_p1_3);
if CurrentBar >= days_hh and days_hh > 0 then
Cond3 = High > SimpleHighest(High[1], days_hh - 1);
// 4. 開盤委買 >= 300 張
Cond4 = GetField("開盤委買") >= _p1_4;
// 5. 收盤價大於 20 日布林通道下緣 1% 以上
Cond5 = Close > bollingerband(Close, _p1_5_len, -1 * _p1_5_std) * (1 + (0.01 * _p2_5_offset));
// 6. 6 日的乖離率 < 15%
Cond6 = Bias(_p1_6_len) < _p2_6_limit;
// 7. 15 日 ATR <= 5
Cond7 = ATR(_p1_7_len) <= _p2_7_limit;
// 8. 近 20 日區間振幅 > 3%
Cond8 = Lowest(Close[1], _p1_8_len) * (1 + _p2_8_limit/100) < Highest(Close[1], _p1_8_len);
// 9. 收盤價 >= 10 元
Cond9 = Close >= _p1_9_min;
// 10. 收盤價 <= 20 元
Cond10 = Close <= _p1_10_max;
// 彙總進場條件
AllEntryCond = Cond1 and Cond2 and Cond3 and Cond4 and Cond5 and Cond6 and Cond7 and Cond8 and Cond9 and Cond10 ;
// ==========================================
// 4. 持有計數邏輯
// ==========================================
if Position > 0 then
HoldCount += 1
else
HoldCount = 0;
// ==========================================
// 5. 交易執行與出場邏輯
// ==========================================
// --- 進場執行 ---
// 加入 Position = 0 判斷,確保手上沒部位時才根據 AllEntryCond 買進固定張數
if Position = 0 and AllEntryCond then begin
SetPosition(_BuyQty, Market);
end;
// --- 出場執行 ---
if Position > 0 then begin
// A. 停損 5%
if Close <= FilledAvgPrice * (1 - _StopLossPct / 100) then begin
SetPosition(0, Market);
end
// B. 達標獲利 3%
else if Close >= FilledAvgPrice * (1 + _TakeProfitPct / 100) then begin
SetPosition(0, Market);
end
// C. 持有期間滿 30 天
else if HoldCount >= _HoldDaysLimit then begin
SetPosition(0, Market);
end;
end;
這個程式無法使用成交金額(元)的欄位資料 再麻煩許教授一下
這個程式只要用腳本計算股票就會卡在準備中
5 評論