本策略是一个基于移动平均线交叉信号的自动化交易系统,通过设定固定的风险收益比来优化交易表现。策略采用快速移动平均线(Fast MA)和慢速移动平均线(Slow MA)的交叉来确定市场趋势方向,并结合预设的止损点和获利目标来管理持仓风险。
策略的核心逻辑基于两条不同周期的移动平均线(10周期和30周期)产生的交叉信号。当快线上穿慢线时,系统产生做多信号;当快线下穿慢线时,系统产生做空信号。每次开仓后,系统会根据预设的2%止损比例自动计算止损位置,并按照2.5倍风险收益比设定获利目标。这种方式确保了每笔交易都具有固定的风险收益特征。
该策略通过结合经典的技术分析方法和现代化的风险管理理念,构建了一个完整的交易系统。虽然存在一定的局限性,但通过持续优化和改进,策略有望在不同市场环境下保持稳定的表现。关键在于根据实际交易效果,不断调整参数设置,找到最适合当前市场环境的配置。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SOL 15m 2.5 R:R Strategy", overlay=true, margin_long=100, margin_short=100, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1)
//---------------------------------------------------
// User Inputs
//---------------------------------------------------
// sym = input.symbol("swap", "Symbol")
timeframe = input.timeframe("15", "Timeframe")
fastLength = input.int(10, "Fast MA Length")
slowLength = input.int(30, "Slow MA Length")
stopLossPerc = input.float(2.0, "Stop Loss %", step=0.1) // This is an example; adjust to achieve ~45% win rate
RR = input.float(2.5, "Risk to Reward Ratio", step=0.1)
//---------------------------------------------------
// Data Sources
//---------------------------------------------------
price = request.security("swap", timeframe, close)
// Compute moving averages
fastMA = ta.sma(price, fastLength)
slowMA = ta.sma(price, slowLength)
// Entry Conditions
longCondition = ta.crossover(fastMA, slowMA)
shortCondition = ta.crossunder(fastMA, slowMA)
//---------------------------------------------------
// Stop Loss and Take Profit Calculation
//---------------------------------------------------
var entryPrice = 0.0
if (strategy.position_size == 0) // not in a position
if longCondition
// Long entry
entryPrice := price
strategy.entry("Long", strategy.long)
if shortCondition
// Short entry
entryPrice := price
strategy.entry("Short", strategy.short)
if strategy.position_size > 0
// We are in a long position
if strategy.position_avg_price > 0 and strategy.position_size > 0
longStop = strategy.position_avg_price * (1 - stopLossPerc/100)
longTarget = strategy.position_avg_price * (1 + (stopLossPerc/100)*RR)
strategy.exit("Long Exit", "Long", stop=longStop, limit=longTarget)
if strategy.position_size < 0
// We are in a short position
if strategy.position_avg_price > 0 and strategy.position_size < 0
shortStop = strategy.position_avg_price * (1 + stopLossPerc/100)
shortTarget = strategy.position_avg_price * (1 - (stopLossPerc/100)*RR)
strategy.exit("Short Exit", "Short", stop=shortStop, limit=shortTarget)
//---------------------------------------------------
// Plotting
//---------------------------------------------------
plot(fastMA, color=color.new(color.teal, 0), title="Fast MA")
plot(slowMA, color=color.new(color.orange, 0), title="Slow MA")