这是一个结合了移动平均线交叉、供需区域识别以及动态止损止盈的综合交易策略。该策略通过短期和长期移动平均线的交叉来确定交易方向,同时利用供需区域作为重要的价格支撑位和阻力位,并配合百分比止损止盈来管理风险。策略的核心在于只在特定的供需区域附近开仓,从而提高交易的胜率。
策略使用9周期和21周期的简单移动平均线(SMA)来判断趋势方向。当价格处于需求区域(支撑位)1%范围内,且短期均线向上穿越长期均线时,系统发出做多信号;当价格处于供给区域(阻力位)1%范围内,且短期均线向下穿越长期均线时,系统发出做空信号。供需区域的识别基于50个周期内的显著高低点,并要求该点位具有至少2根确认蜡烛图。系统会根据入场价格自动设置动态的止损位(默认1%)和止盈位(默认2%)。
这是一个将经典技术分析方法与现代风险管理理念相结合的策略系统。通过在重要价格区域附近进行交易,并结合移动平均线交叉信号,策略提供了一个相对可靠的交易框架。动态止损止盈的设计有助于适应不同市场环境,但策略的实际应用还需要根据具体市场特征进行优化。建议在实盘交易前进行充分的参数优化和回测验证。
/*backtest
start: 2024-12-01 00:00:00
end: 2025-02-01 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("MA Crossover with Demand/Supply Zones + Stop Loss/Take Profit", overlay=true)
// Input parameters for Moving Averages
shortLength = input.int(9, title="Short MA Length", minval=1)
longLength = input.int(21, title="Long MA Length", minval=1)
// Input parameters for Demand/Supply Zones
zoneLookback = input.int(50, title="Zone Lookback Period", minval=10)
zoneStrength = input.int(2, title="Zone Strength (Candles)", minval=1)
// Input parameters for Stop Loss and Take Profit
stopLossPerc = input.float(1.0, title="Stop Loss (%)", minval=0.1) / 100
takeProfitPerc = input.float(2.0, title="Take Profit (%)", minval=0.1) / 100
// Calculate moving averages
shortMA = ta.sma(close, shortLength)
longMA = ta.sma(close, longLength)
// Plot moving averages
plot(shortMA, color=color.blue, title="Short MA")
plot(longMA, color=color.red, title="Long MA")
// Identify Demand and Supply Zones
var float demandZone = na
var float supplyZone = na
// Detect Demand Zones (Price makes a significant low and bounces up)
if (ta.lowest(low, zoneLookback) == low[zoneStrength] and close[zoneStrength] > open[zoneStrength])
demandZone := low[zoneStrength]
// Detect Supply Zones (Price makes a significant high and drops down)
if (ta.highest(high, zoneLookback) == high[zoneStrength] and close[zoneStrength] < open[zoneStrength])
supplyZone := high[zoneStrength]
// Draw Demand and Supply Zones using lines
var line demandLine = na
var line supplyLine = na
// Trade Logic: Only open trades near Demand/Supply Zones
isNearDemand = demandZone > 0 and close <= demandZone * 1.01 // Within 1% of demand zone
isNearSupply = supplyZone > 0 and close >= supplyZone * 0.99 // Within 1% of supply zone
// Calculate Stop Loss and Take Profit levels
stopLossLevel = strategy.position_avg_price * (1 - stopLossPerc) // Stop loss for long positions
takeProfitLevel = strategy.position_avg_price * (1 + takeProfitPerc) // Take profit for long positions
stopLossLevelShort = strategy.position_avg_price * (1 + stopLossPerc) // Stop loss for short positions
takeProfitLevelShort = strategy.position_avg_price * (1 - takeProfitPerc) // Take profit for short positions
// Generate buy/sell signals based on MA crossover and zones
if (ta.crossover(shortMA, longMA) and isNearDemand)
strategy.entry("Buy", strategy.long)
strategy.exit("Take Profit/Stop Loss", from_entry="Buy", stop=stopLossLevel, limit=takeProfitLevel)
if (ta.crossunder(shortMA, longMA) and isNearSupply)
strategy.entry("Sell", strategy.short)
strategy.exit("Take Profit/Stop Loss", from_entry="Sell", stop=stopLossLevelShort, limit=takeProfitLevelShort)
// Optional: Plot buy/sell signals on the chart
plotshape(series=ta.crossover(shortMA, longMA) and isNearDemand, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=ta.crossunder(shortMA, longMA) and isNearSupply, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")