Strategies
多维趋势动量价值过滤交易策略-Multi-Dimensional-Trend-Momentum-Value-Filtering-Trading-Strategy
ianzeng123 · PineScript · Trend Following · 2025-04-03 15:16:18
Filter
Sizing
—
Risk control
Exit
No English write-up in the source (no author description).
Source code (59 lines)
/*backtest
start: 2024-04-03 00:00:00
end: 2025-04-02 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BNB_USDT"}]
*/
//@version=5
strategy("BuySell Strategy OD", overlay=true)
// === INPUTS === //
rsiPeriod = input.int(14, "RSI Period")
stochPeriod = input.int(14, "Stoch RSI Period")
adxPeriod = input.int(14, "ADX Period")
// === INDICATORS === //
// RSI
rsi = ta.rsi(close, rsiPeriod)
// Stoch RSI
rsiMin = ta.lowest(rsi, stochPeriod)
rsiMax = ta.highest(rsi, stochPeriod)
stochRsi = rsiMax != rsiMin ? (rsi - rsiMin) / (rsiMax - rsiMin) * 100 : 0
// ADX (manual calculation)
upMove = high - high[1]
downMove = low[1] - low
plusDM = (upMove > downMove and upMove > 0) ? upMove : 0
minusDM = (downMove > upMove and downMove > 0) ? downMove : 0
tr = math.max(math.max(high - low, high - close[1]), low - close[1])
atr = ta.rma(tr, adxPeriod)
plusDI = 100 * ta.rma(plusDM, adxPeriod) / atr
minusDI = 100 * ta.rma(minusDM, adxPeriod) / atr
dx = 100 * ((plusDI - minusDI) >= 0 ? (plusDI - minusDI) : (minusDI - plusDI)) / (plusDI + minusDI)
adx = ta.rma(dx, adxPeriod)
// VWAP
vwap = ta.vwap(hlc3)
// === BUY CONDITION === //
buyCond = (adx > 25) and (rsi < 30) and (stochRsi < 20) and (close < vwap)
// === SELL CONDITION === //
sellCond = (adx > 25) and (rsi > 70) and (stochRsi > 80) and (close > vwap)
// === PLOTS === //
plotshape(buyCond, title="BUY", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sellCond, title="SELL", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// === STRATEGY ORDERS === //
if buyCond
strategy.entry("BUY", strategy.long)
if sellCond
strategy.entry("SELL", strategy.short)