// @version=5
strategy("Bitcoin Momentum Original Logic (Safe Version)", overlay=true, initial_capital=10000, currency=currency.USDT, default_qty_type=strategy.percent_of_equity, default_qty_value=100,commission_type=strategy.commission.percent,commission_value=0.2,slippage=50)
// --- 你的原始參數 ---
i_HigherTimeframe = input.timeframe("W", "Higher Timeframe") // 週線濾網
i_EmaLength = 20
i_AtrLength = 5
i_TrailStopLookback = 7
i_TrailStopMulti = 0.2
// --- 1. 正確獲取高週期數據 (週線) ---
// 使用 lookahead_on 配合 [1] 確保不偷看本週收盤價,只看「上週」收盤狀況
// 這是最嚴格且真實的寫法
emaWeekly = request.security(syminfo.tickerid, i_HigherTimeframe, ta.ema(close, i_EmaLength)[1], lookahead=barmerge.lookahead_on)
// --- 2. 本週期數據 (直接讀取掛載圖表的數據,假設掛在 4H) ---
// 這樣就不用 request.security 去抓 4H,避免 bug
rsiVal = ta.rsi(close, 14)
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
emaValue = ta.ema(close, i_EmaLength)
atrValue = ta.atr(i_AtrLength)
// --- 3. 你的原始寬鬆濾網 (保留 OR 邏輯) ---
// 只要 RSI 強勢 或 MACD 金叉,就視為動能足夠
isLowerMomentumBull = (rsiVal > 50) or (macdLine > signalLine)
// --- 4. 趨勢與 Caution 定義 ---
isBullish = close > emaWeekly // 價格在週線 EMA 之上
// Caution: 價格乖離過大 或 跌破短均
// 注意:下方已將大於小於符號轉義,確保顯示正常
isCaution = isBullish and (ta.highest(high, 7) - low > (atrValue * 1.5) or close < emaValue)
// --- 5. 進場執行 ---
// 這裡保留你原本的邏輯
if isBullish and not isCaution and isLowerMomentumBull
strategy.entry("Buy", strategy.long)
// --- 6. 停損邏輯 (原始) ---
var float trailStop = na
float temp_trailStop = ta.highest(low, i_TrailStopLookback) - (isCaution[1] ? atrValue * i_TrailStopMulti : atrValue)
if strategy.position_size > 0
if temp_trailStop > trailStop or na(trailStop)
trailStop := temp_trailStop
// 出場
if close < trailStop
strategy.close("Buy", comment="Stop Hit")
trailStop := na
// 跌破週線也出場
if close < emaWeekly
strategy.close("Buy", comment="Trend Broken")
// 繪圖
// 修改部分:如果收盤價大於週線EMA顯示綠色,否則顯示紅色
plot(emaWeekly, color = close > emaWeekly ? color.green : color.red, linewidth=2, title="Weekly EMA")
// 停損線維持紅色
plot(strategy.position_size > 0 ? trailStop : na, color=color.red, style=plot.style_linebr, title="Trailing SL")
我使用這個策略大概三四個月
雖然原本就沒多少本金,總之有陸續逃頂
還在等下次進場點
原本是看日線,但有日線有時候等太久
最後跟Gemini討論過後改看4小時線