
Đây là một chiến lược giao dịch tổng hợp kết hợp các đường trung bình di chuyển, nhận diện vùng cung ứng và nhu cầu, và các điểm dừng động. Chiến lược này xác định hướng giao dịch bằng cách giao nhau giữa các đường trung bình di chuyển ngắn hạn và dài hạn, đồng thời sử dụng vùng cung ứng và nhu cầu làm điểm hỗ trợ và kháng cự giá trị quan trọng, và phối hợp với điểm dừng phần trăm để quản lý rủi ro.
Chiến lược sử dụng đường trung bình di chuyển đơn giản (SMA) 9 chu kỳ và 21 chu kỳ để xác định hướng xu hướng. Hệ thống phát ra nhiều tín hiệu khi giá nằm trong phạm vi 1% của vùng nhu cầu (SMA) và đường trung bình ngắn hạn đi lên vượt qua đường trung bình dài hạn. Hệ thống phát ra tín hiệu trống khi giá nằm trong phạm vi 1% của vùng cung cấp (SMA) và đường trung bình ngắn hạn đi xuống vượt qua đường trung bình dài hạn.
Đây là một hệ thống chiến lược kết hợp các phương pháp phân tích kỹ thuật cổ điển với các tư tưởng quản lý rủi ro hiện đại. Bằng cách giao dịch gần khu vực giá quan trọng và kết hợp với tín hiệu giao dịch chéo đường trung bình di động, chiến lược cung cấp một khung giao dịch tương đối đáng tin cậy. Thiết kế dừng lỗ động giúp thích ứng với các môi trường thị trường khác nhau, nhưng ứng dụng thực tế của chiến lược cũng cần được tối ưu hóa theo đặc điểm thị trường cụ thể.
/*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")