Chiến lược hợp nhất dữ liệu đa nguồn EMA inFusion Pro

EMA ADX ATR ROC HEIKIN-ASHI VOLUME
Ngày tạo: 2025-09-03 14:23:19 sửa đổi lần cuối: 2025-09-03 14:23:19
sao chép: 0 Số nhấp chuột: 213
2
tập trung vào
319
Người theo dõi

Chiến lược hợp nhất dữ liệu đa nguồn EMA inFusion Pro Chiến lược hợp nhất dữ liệu đa nguồn EMA inFusion Pro

Chiến lược EMA không chỉ nhìn vào giá cả

Bạn có biết rằng hầu hết mọi người chỉ nhìn vào giá cả khi sử dụng EMA, nhưng chiến lược này có gì tuyệt vời? Nó có thể tính EMA từ 6 nguồn dữ liệu khác nhau! Giống như việc nấu ăn không chỉ dùng muối để thêm hương vị, mà còn dùng đường, dưa chuột và dầu hầm để cung cấp cho bạn một tín hiệu giao dịch phong phú hơn.

6 nguồn dữ liệu bao gồm: giá thông thường, khối lượng giao dịch, tỷ lệ thay đổi, giá trung bình K-line, khối lượng giao dịch trung bình K-line, tỷ lệ thay đổi trung bình K-line. Mỗi nguồn có những hiểu biết thị trường khác nhau!

Hệ thống lọc ba lần: Tạo ra tín hiệu chính xác hơn

Chiến lược này không chỉ đơn giản là để báo hiệu, mà còn có ba cách để kiểm tra:

Đường 1: Đánh giá xu hướng của EMA 📈 Giống như việc xem dự báo thời tiết, bạn sẽ biết được khu vực nào sẽ có mưa hay không.

Đường thứ hai: Bộ lọc cường độ ADX 💪
ADX giống như một thiết bị đo gió, chỉ cần có xu hướng mạnh (chỉ mặc định trên 25), nó sẽ phát ra tín hiệu.

Đường thứ ba: xác nhận số lượng giao dịch 🔊 Sự tăng vọt của doanh thu giống như chứng khoán “nói to” - chứng minh rằng tín hiệu này là nghiêm túc, không phải là trò đùa

3 cách rút lui: thích ứng với phong cách giao dịch khác nhau

Và điều thú vị nhất là chiến lược này cung cấp 3 cách để thoát ra, giống như trò chơi có 3 mức độ khó: đơn giản, bình thường và khó khăn:

Mô hình 1: tín hiệu ngược thoát 🔄 Đơn giản là thô nhất, nhiều đầu tín hiệu đến, nhiều trống rỗng, trống đầu tín hiệu đến, nhiều trống rỗng

Mô hình 2: ATR động dừng lỗ 📏 Điều chỉnh tự động theo biến động của thị trường, dừng lỗ mở rộng điểm khi biến động lớn, điểm thắt chặt khi biến động nhỏ

Phương thức 3: Stop Loss % cố định 📊 Hiểu rõ hơn, tăng 2% là chạy, mất 1.5% là thua (có thể tùy chỉnh)

Hướng dẫn ứng dụng chiến trường

Chu kỳ áp dụngGiao dịch ngắn hạn và trung hạn, đặc biệt phù hợp với thị trường có sự biến động Hướng dẫn tránh hốThị trường rung động: Cẩn thận, khuyến nghị bật bộ lọc ADX Tiến lênBạn có thể thử các nguồn dữ liệu khác nhau, và nguồn dữ liệu này đặc biệt hiệu quả khi bạn đạt được một bước đột phá!

Ưu điểm lớn nhất của chiến lược này là tính linh hoạt, bạn có thể chọn nguồn dữ liệu phù hợp nhất và phương thức rút lui phù hợp nhất với môi trường thị trường khác nhau. Hãy nhớ rằng, không có chiến lược hoàn hảo, chỉ có chiến lược phù hợp nhất với thị trường hiện tại!

Mã nguồn chiến lược
/*backtest
start: 2025-01-01 00:00:00
end: 2025-09-01 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":500000}]
*/

//@version=5
//@fenyesk
strategy("EMA inFusion Pro - Source Selection", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// =============================================
// === INPUT PARAMETERS =======================
// =============================================

// Moving Average Source Selection
maSourceSelection = input.string("Price", "Moving Average Source", 
  options=["Price", "Volume", "Rate of Change", "Heikin Ashi Price", "Heikin Ashi Volume", "Heikin Ashi Rate of Change"],
  tooltip="Select data source for EMA calculation")

// EMA Settings
emaLength = input.int(50, title="EMA Length", minval=1, maxval=200)
rocLength = input.int(1, title="Rate of Change Length", minval=1, maxval=50, tooltip="Length for ROC calculation")

// ADX Filter Settings
useAdxFilter = input.bool(true, title="Use ADX Filter", group="ADX Settings")
adxLength = input.int(14, title="ADX Length", minval=1, maxval=50, group="ADX Settings")
adxThreshold = input.float(25, title="ADX Threshold", minval=10, maxval=50, step=0.5, group="ADX Settings")

// Volume Spike Settings
useVolumeFilter = input.bool(true, title="Use Volume Spike Filter", group="Volume Settings")
volumeMultiplier = input.float(1.0, title="Volume Spike Multiplier", minval=1.0, maxval=5.0, step=0.1, group="Volume Settings")
volumeSmaLength = input.int(20, title="Volume SMA Length", minval=5, maxval=100, group="Volume Settings")

// Trading Exit Mode Selector
tradingMode = input.int(2, title="Trading Exit Mode", minval=1, maxval=3, 
  tooltip="1: Exit on reverse signal\n2: ATR based TP/SL\n3: Percent based TP/SL", 
  group="Exit Strategy")

// Mode 3: Percent-Based Settings
takeProfitPercent = input.float(2.0, title="Take Profit %", minval=0.1, maxval=10.0, step=0.1, group="Percent Exit")
stopLossPercent = input.float(1.5, title="Stop Loss %", minval=0.1, maxval=10.0, step=0.1, group="Percent Exit")

// Mode 2: ATR-Based Settings
atrLength = input.int(14, title="ATR Length", minval=1, maxval=50, group="ATR Exit")
atrMultiplierTp = input.float(4.0, title="ATR Take Profit Multiplier", minval=0.1, maxval=10.0, step=0.1, group="ATR Exit")
atrMultiplierSl = input.float(4.0, title="ATR Stop Loss Multiplier", minval=0.1, maxval=10.0, step=0.1, group="ATR Exit")

// =============================================
// === SOURCE CALCULATIONS ====================
// =============================================

// Rate of Change calculation
roc(src, length) =>
    change = src - src[length]
    src[length] != 0 ? (change / src[length] * 100) : 0

// Standard Rate of Change
rocPrice = roc(close, rocLength)
rocVolume = roc(volume, rocLength)

// Heikin Ashi calculations
haClose = (open + high + low + close) / 4
var float haOpen = na
haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
haHigh = math.max(high, math.max(haOpen, haClose))
haLow = math.min(low, math.min(haOpen, haClose))

// Heikin Ashi Rate of Change
haRocPrice = roc(haClose, rocLength)
haRocVolume = roc(volume, rocLength)  // Volume remains same for HA

// Define EMA source based on selection
emaSource = switch maSourceSelection
    "Price" => close
    "Volume" => volume
    "Rate of Change" => rocPrice
    "Heikin Ashi Price" => haClose
    "Heikin Ashi Volume" => volume  // Volume doesn't change in HA
    "Heikin Ashi Rate of Change" => haRocPrice
    => close  // Default fallback

// =============================================
// === INDICATOR CALCULATIONS =================
// =============================================

// Core Indicators
emaValue = ta.ema(emaSource, emaLength)
[diPlus, diMinus, adx] = ta.dmi(adxLength, adxLength)
volumeSma = ta.sma(volume, volumeSmaLength)
volumeSpike = volume > (volumeSma * volumeMultiplier)
atrValue = ta.atr(atrLength)

// Trend Conditions (adjusted for different source types)
bullishTrend = switch maSourceSelection
    "Price" => close > emaValue
    "Heikin Ashi Price" => haClose > emaValue
    "Volume" => volume > emaValue
    "Heikin Ashi Volume" => volume > emaValue
    "Rate of Change" => rocPrice > emaValue
    "Heikin Ashi Rate of Change" => haRocPrice > emaValue
    => close > emaValue

bearishTrend = not bullishTrend

// Cross conditions (adjusted for source type)
emaCrossUp = switch maSourceSelection
    "Price" => ta.crossover(close, emaValue)
    "Heikin Ashi Price" => ta.crossover(haClose, emaValue)
    "Volume" => ta.crossover(volume, emaValue)
    "Heikin Ashi Volume" => ta.crossover(volume, emaValue)
    "Rate of Change" => ta.crossover(rocPrice, emaValue)
    "Heikin Ashi Rate of Change" => ta.crossover(haRocPrice, emaValue)
    => ta.crossover(close, emaValue)

emaCrossDown = switch maSourceSelection
    "Price" => ta.crossunder(close, emaValue)
    "Heikin Ashi Price" => ta.crossunder(haClose, emaValue)
    "Volume" => ta.crossunder(volume, emaValue)
    "Heikin Ashi Volume" => ta.crossunder(volume, emaValue)
    "Rate of Change" => ta.crossunder(rocPrice, emaValue)
    "Heikin Ashi Rate of Change" => ta.crossunder(haRocPrice, emaValue)
    => ta.crossunder(close, emaValue)

// Filters
strongTrend = useAdxFilter ? adx >= adxThreshold : true
volumeConfirm = useVolumeFilter ? volumeSpike : true

// Entry Signals
longCondition = emaCrossUp and strongTrend and volumeConfirm
shortCondition = emaCrossDown and strongTrend and volumeConfirm

// =============================================
// === STRATEGY EXECUTION WITH EXIT MODES =====
// =============================================

// MODE 1: EXIT ON REVERSE SIGNAL
if (tradingMode == 1)
    if (longCondition)
        strategy.entry("Long", strategy.long)
        strategy.close("Short")
    if (shortCondition)
        strategy.entry("Short", strategy.short)
        strategy.close("Long")

// MODE 2: ATR-BASED TAKE PROFIT & STOP LOSS
else if (tradingMode == 2)
    if (longCondition)
        strategy.entry("Long", strategy.long)
        strategy.exit("Long TP/SL", "Long", 
          profit=atrMultiplierTp * atrValue / syminfo.mintick, 
          loss=atrMultiplierSl * atrValue / syminfo.mintick)
    
    if (shortCondition)
        strategy.entry("Short", strategy.short)
        strategy.exit("Short TP/SL", "Short", 
          profit=atrMultiplierTp * atrValue / syminfo.mintick, 
          loss=atrMultiplierSl * atrValue / syminfo.mintick)

// MODE 3: PERCENT-BASED TAKE PROFIT & STOP LOSS
else if (tradingMode == 3)
    if (longCondition)
        longTpPrice = close * (1 + takeProfitPercent / 100)
        longSlPrice = close * (1 - stopLossPercent / 100)
        strategy.entry("Long", strategy.long)
        strategy.exit("Long TP/SL", "Long", limit=longTpPrice, stop=longSlPrice)
    
    if (shortCondition)
        shortTpPrice = close * (1 - takeProfitPercent / 100)
        shortSlPrice = close * (1 + stopLossPercent / 100)
        strategy.entry("Short", strategy.short)
        strategy.exit("Short TP/SL", "Short", limit=shortTpPrice, stop=shortSlPrice)

// =============================================
// === VISUALIZATIONS =========================
// =============================================

// Plot EMA with dynamic color based on source type
emaColor = switch maSourceSelection
    "Price" => color.blue
    "Volume" => color.orange
    "Rate of Change" => color.purple
    "Heikin Ashi Price" => color.green
    "Heikin Ashi Volume" => color.red
    "Heikin Ashi Rate of Change" => color.maroon
    => color.blue

plot(emaValue, title="EMA", color=emaColor, linewidth=2)

// Plot source data for reference (in separate pane when not price-based)
sourceColor = maSourceSelection == "Price" or maSourceSelection == "Heikin Ashi Price" ? na : color.gray
plot(str.contains(maSourceSelection, "Price") ? na : emaSource, title="Source Data", color=sourceColor)

// Background color based on trend
bgcolor(bullishTrend ? color.new(color.green, 95) : color.new(color.red, 95), title="Trend Background")

// Entry signals
plotshape(longCondition, title="Long Signal", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(shortCondition, title="Short Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)

// Volume spikes
plotchar(useVolumeFilter and volumeSpike, title="Volume Spike", char="V", location=location.bottom, color=color.orange, size=size.tiny)

// ATR-based levels for Mode 2
plot(tradingMode == 2 and strategy.position_size > 0 ? strategy.position_avg_price + (atrMultiplierTp * atrValue) : na, 
  title="Long TP Level", color=color.green, style=plot.style_circles, linewidth=1)
plot(tradingMode == 2 and strategy.position_size > 0 ? strategy.position_avg_price - (atrMultiplierSl * atrValue) : na, 
  title="Long SL Level", color=color.red, style=plot.style_circles, linewidth=1)
plot(tradingMode == 2 and strategy.position_size < 0 ? strategy.position_avg_price - (atrMultiplierTp * atrValue) : na, 
  title="Short TP Level", color=color.green, style=plot.style_circles, linewidth=1)
plot(tradingMode == 2 and strategy.position_size < 0 ? strategy.position_avg_price + (atrMultiplierSl * atrValue) : na, 
  title="Short SL Level", color=color.red, style=plot.style_circles, linewidth=1)


// Alert conditions
alertcondition(longCondition, title="Long Entry", message="EMA Fusion Pro: Long entry signal")
alertcondition(shortCondition, title="Short Entry", message="EMA Fusion Pro: Short entry signal")