我的選股目標是:
(1) 120個交易日內有金叉
(2) 金叉前後7天的高點(鎖定價格),金叉後第8天開始,收盤價有高於鎖定價格。
我檢查時,發現2308應該要被選到,但一直沒有辦法抓出來。
我改用Finlab寫發現可以,想請問是XS或是XQ資料上有什麼限制嗎
// ── (2) 近120日內有金叉 +「金叉7天後至今」盤價曾高於「金叉±7日」的最高價(修正版)──
// 說明:
// D0 = 金叉日。pre7 高= D0 前 1~7 日最高;post7 高= D0 至 D0+7 最高;
// anchor_high_fixed = Max(pre7 高, post7 高),在 D0+7「固定」;
// 從 D0+8 起(days_after_gc >= 8)開始檢查:High 是否曾 > anchor_high_fixed。
// 可選:僅台灣上市櫃
// variable: ex("");
// ex = GetSymbolInfo("Exchange");
variable: ma20(0), ma60(0);
variable: golden(false), seen_gc(false);
variable: gc_age(100000), days_after_gc(0);
variable: pre7_high_at_gc(0), post7_high_at_gc(0);
variable: anchor_high_fixed(0), anchor_fixed(false);
variable: hit_after7(false);
ma20 = Average(Close, 20);
ma60 = Average(Close, 60);
golden = (ma20 > ma60) and (ma20[1] <= ma60[1]);
// 一旦出現最新金叉:重置所有狀態
if golden then begin
seen_gc = true;
gc_age = 0; // 0 = 今天是金叉日 (D0)
days_after_gc = 0;
pre7_high_at_gc = Highest(High[1], 7); // D0 前 1~7 日最高
post7_high_at_gc = High; // 從 D0 開始收集
anchor_high_fixed = 0;
anchor_fixed = false;
hit_after7 = false;
end
else begin
if seen_gc then begin
if gc_age < 100000 then gc_age = gc_age + 1;
if days_after_gc < 1000 then days_after_gc = days_after_gc + 1;
// 在 D0~D0+7 期間更新 post7 高
if days_after_gc <= 7 then
if High > post7_high_at_gc then post7_high_at_gc = High;
// 在「剛好第 7 天」時,固定錨點高
if (days_after_gc = 7) and (not anchor_fixed) then begin
anchor_high_fixed = MaxList(pre7_high_at_gc, post7_high_at_gc);
anchor_fixed = true;
end;
// 從「第 8 天起」檢查是否曾盤中突破錨點高
if (days_after_gc >= 8) and anchor_fixed then begin
if High > anchor_high_fixed then
hit_after7 = true;
end;
end;
end;
// 輸出:(a) 近120日內有金叉;(b) D0+8 起曾盤中突破錨點高
if
// ((ex = "TSE") or (ex = "OTC")) and
(seen_gc) and (gc_age <= 119) and (hit_after7)
then
ret = 1;
2 評論