这是一个基于多均线趋势跟踪系统的加密货币交易策略,结合了RSI和ATR指标进行交易过滤和风险管理。该策略主要针对主流加密货币进行交易,通过设定每日交易频率限制和动态止盈止损来控制风险。策略采用9周期、20周期和50周期三条指数移动平均线(EMA)来判断趋势方向,并使用相对强弱指标(RSI)和平均真实波幅(ATR)作为辅助指标进行交易过滤。
策略的核心交易逻辑包括以下几个关键部分: 1. 趋势判断:使用三条EMA(9/20/50)进行趋势方向判断,当短期EMA穿越中期EMA且价格位于长期EMA之上时,视为上升趋势成立;反之则视为下降趋势成立。 2. 交易过滤:使用RSI(14)进行超买超卖过滤,买入信号要求RSI在45-70之间,卖出信号要求RSI在30-55之间。 3. 趋势强度确认:要求价格与50周期EMA的距离大于1.1倍ATR,以确保趋势足够强劲。 4. 风险管理:根据不同加密货币的波动特性,设置2.5-3.2倍ATR的止损和3.5-5.0倍ATR的止盈。 5. 交易频率控制:每个交易日最多允许一笔交易,避免过度交易。
该策略通过多重技术指标的综合运用,实现了相对稳健的加密货币交易系统。通过差异化的风险参数设置和严格的交易频率控制,较好地平衡了收益和风险。策略的核心优势在于其动态的风险管理机制和完善的过滤系统,但同时也需要注意加密货币市场特有的高波动性和流动性风险。通过持续优化和完善,该策略有望在不同市场环境下都能保持稳定的表现。
/*backtest
start: 2015-02-22 00:00:00
end: 2025-02-18 17:23:25
period: 1h
basePeriod: 1h
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © buffalobillcody
//@version=6
strategy("Backtest Last 2880 Baars Filers and Exits", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=2, backtest_fill_limits_assumption=0)
// Define EMAs
shortEMA = ta.ema(close, 9)
longEMA = ta.ema(close, 20)
refEMA = ta.ema(close, 50)
// **Force Strategy to Trade on Historical Bars**
barLimit = bar_index > 10 // Allow trading on past bars
allowTrade = strategy.opentrades == 0 or barLimit // Enable first trade on history
// **Define ATR for Stop-Loss & Take-Profit**
atrLength = 14
atrValue = ta.atr(atrLength)
atr50 = ta.sma(atrValue, 50) // 50-period ATR average
// **Relaxed RSI Filters (More Trades Allowed)**
rsi = ta.rsi(close, 14)
rsiFilterBuy = rsi > 45 and rsi < 70
rsiFilterSell = rsi < 55 and rsi > 30
// **Reduce Trend Filter - Allow Smaller Price Movement**
minDistance = atrValue * 1.1
isTrending = math.abs(close - refEMA) > minDistance
// **Allow Trading in All Conditions (No ATR Filter)**
atrFilter = true
// **Allow Flat EMA Slopes - Increase Trade Frequency**
emaSlope = ta.linreg(refEMA, 5, 0) > -0.2
emaSlopeSell = ta.linreg(refEMA, 5, 0) < 0.2
// **Trade Counter: Allow 1 Trade Per Day**
var int dailyTradeCount = 0
if dayofweek != dayofweek[1]
dailyTradeCount := 0
// **ATR-Based Stop-Loss & Take-Profit Per Pair**
atrSL = switch syminfo.ticker
"EURUSD" => 3.0 * atrValue,
"USDJPY" => 2.5 * atrValue,
"GBPUSD" => 3.0 * atrValue,
"AUDUSD" => 3.2 * atrValue,
"GBPJPY" => 3.0 * atrValue,
=> 2.5 * atrValue
atrTP = switch syminfo.ticker
"EURUSD" => 3.8 * atrValue,
"USDJPY" => 3.5 * atrValue,
"GBPUSD" => 4.0 * atrValue,
"AUDUSD" => 4.0 * atrValue,
"GBPJPY" => 5.0 * atrValue,
=> 3.5 * atrValue
// **Ensure Trade Size is Not Zero**
riskPerTrade = 2
accountSize = strategy.equity
tradeSize = (accountSize * (riskPerTrade / 100)) / atrSL
tradeSize := tradeSize < 1 ? 1 : tradeSize // Minimum lot size of 1
// **Buy/Sell Conditions (Now More Trades Will Trigger)**
buyCondition = ta.crossover(shortEMA, longEMA) and rsiFilterBuy and close > refEMA and close > longEMA and isTrending and emaSlope and allowTrade and dailyTradeCount < 1
sellCondition = ta.crossunder(shortEMA, longEMA) and rsiFilterSell and close < refEMA and close < longEMA and isTrending and emaSlopeSell and allowTrade and dailyTradeCount < 1
// **Execute Trades**
if buyCondition
strategy.entry("Buy", strategy.long, qty=tradeSize)
strategy.exit("Take Profit/Stop Loss", from_entry="Buy", limit=close + atrTP, stop=close - atrSL)
label.new(x=bar_index, y=low, text="BUY", color=color.green, textcolor=color.white, size=size.small, style=label.style_label_down)
alert("BUY", alert.freq_once_per_bar_close)
dailyTradeCount := dailyTradeCount + 1
if sellCondition
strategy.entry("Sell", strategy.short, qty=tradeSize)
strategy.exit("Take Profit/Stop Loss", from_entry="Sell", limit=close - atrTP, stop=close + atrSL)
label.new(x=bar_index, y=high, text="SELL", color=color.red, textcolor=color.white, size=size.small, style=label.style_label_up)
alert("SELL", alert.freq_once_per_bar_close)
dailyTradeCount := dailyTradeCount + 1
// **Plot Indicators**
plot(shortEMA, color=color.yellow, title="9 EMA")
plot(longEMA, color=color.fuchsia, title="20 EMA")
plot(refEMA, color=color.blue, title="50 EMA")