
이 전략은 이동 평균 지표와 동향 지표를 결합하여 양 지표의 교차 신호를 구현하여 구매 및 판매 신호를 발송합니다. 또한, 전략은 위험을 제어하기 위해 동적 추적 스톱을 추가합니다.
이 전략은 이동 평균과 동력 지표의 장점을 통합하고, 이중 확인 신호를 사용하여 지표 간의 상호 보완을 사용하여 전략 수익성을 향상시킵니다. 동시에, 동적 추적 중지 메커니즘은 전략의 위험을 효과적으로 제어 할 수 있습니다. 매개 변수 최적화 및 규칙 개선을 통해 이 전략의 수익성 및 안정성이 향상 될 것으로 기대됩니다.
/*backtest
start: 2023-02-22 00:00:00
end: 2024-02-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Combined EMA and DMI Strategy with Enhanced Table", overlay=true)
// Input parameters for EMA
shortTermEMA = input.int(9, title="Short-Term EMA Period")
longTermEMA = input.int(21, title="Long-Term EMA Period")
riskPercentageEMA = input.float(1, title="Risk Percentage EMA", minval=0.1, maxval=5, step=0.1)
// Calculate EMAs
emaShort = ta.ema(close, shortTermEMA)
emaLong = ta.ema(close, longTermEMA)
// EMA Crossover Strategy
longConditionEMA = emaShort > emaLong and emaShort[1] <= emaLong[1]
shortConditionEMA = emaShort < emaLong and emaShort[1] >= emaLong[1]
// Input parameters for DMI
adxlen = input(17, title="ADX Smoothing")
dilen = input(17, title="DI Length")
// DMI Logic
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
truerange = ta.tr
plus = fixnan(100 * ta.rma(up > down and up > 0 ? up : 0, len) / truerange)
minus = fixnan(100 * ta.rma(down > up and down > 0 ? down : 0, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adxValue = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
[adxValue, plus, minus]
[adxValue, up, down] = adx(dilen, adxlen)
// DMI Conditions
buyConditionDMI = up > down or (up and adxValue > down)
sellConditionDMI = down > up or (down and adxValue > up)
// Combined Conditions for Entry
longEntryCondition = longConditionEMA and buyConditionDMI
shortEntryCondition = shortConditionEMA and sellConditionDMI
// Combined Conditions for Exit
longExitCondition = shortConditionEMA
shortExitCondition = longConditionEMA
// Enter long trade based on combined conditions
if (longEntryCondition)
strategy.entry("Long", strategy.long)
// Enter short trade based on combined conditions
if (shortEntryCondition)
strategy.entry("Short", strategy.short)
// Exit trades
if (longExitCondition)
strategy.close("Long")
if (shortExitCondition)
strategy.close("Short")
// Plot EMAs
plot(emaShort, color=color.blue, title="Short-Term EMA")
plot(emaLong, color=color.red, title="Long-Term EMA")
// Create and fill the enhanced table
var tbl = table.new(position.top_right, 4, 1)
if (barstate.islast)
table.cell(tbl, 0, 0, "ADX: " + str.tostring(adxValue), bgcolor=color.new(color.red, 90), width=15, height=4)
table.cell(tbl, 1, 0, "+DI: " + str.tostring(up), bgcolor=color.new(color.blue, 90), width=15, height=4)
table.cell(tbl, 2, 0, "-DI: " + str.tostring(down), bgcolor=color.new(color.orange, 90), width=15, height=4)