請教Ray大 教學中所使用的kd 背離策略,通常是用什麼時間刻度呢
我將這套kd 背離策略拿去做 btcusdt 交易對 ,
我的止盈止損使用ATR,
TP: 4*ATR ,SL: 2*ATR,
回測時間3年期,5min 刻度收益最好。
謝謝 Ray大
==我的Pinescript==
strategy("KD Divergence Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// 設定KD指標的計算參數
length = input(14, title="Length")
smoothK = input(3, title="SmoothK")
smoothD = input(3, title="SmoothD")
maLength = input(50, title="MA Length")
// 計算KD指標
lowestLow = ta.lowest(low, length)
highestHigh = ta.highest(high, length)
rsv = (close - lowestLow) / (highestHigh - lowestLow) * 100
k = ta.sma(rsv, smoothK)
d = ta.sma(k, smoothD)
// 繪製KD線
// 識別背離
priceNewHigh = ta.highest(close, length) == close
kNotNewHigh = ta.highest(k, length) < k[length]
topDivergence = priceNewHigh and kNotNewHigh
priceNewLow = ta.lowest(close, length) == close
kNotNewLow = ta.lowest(k, length) > k[length]
bottomDivergence = priceNewLow and kNotNewLow
// 生成交易信號並設定止損止盈
atrLength = input(14, title="ATR Length")
slMultiplier = input(2, title="Stop Loss ATR Multiplier")
tpMultiplier = input(4, title="Take Profit ATR Multiplier")
atr = ta.atr(atrLength)
// 生成交易信號並設定止損止盈
if (topDivergence)
strategy.entry("Sell", strategy.short)
strategy.exit("Exit Sell", "Sell", stop=close + slMultiplier * atr, limit=close - tpMultiplier * atr)
if (bottomDivergence)
strategy.entry("Buy", strategy.long)
strategy.exit("Exit Buy", "Buy", stop=close - slMultiplier * atr, limit=close + tpMultiplier * atr)