EHMA 범위 전략

저자:차오장, 날짜: 2022-05-09 23:31:59
태그:EHMA

이 스크립트는 @borserman의 스크립트의 변형 버전입니다 EHMA의 모든 크레딧은 그에게 돌아갑니다.

이 스크립트는 EHMA 외에도 EHMA 주위의 범위 (변경될 수 있는 범위) 로 작동하며, 가짜 신호에 대한 견고함을 시도한다. 많은 경우 바는 이동 평균 이하로 닫히고, 다음 바를 다시 뒤집어 놓을 뿐, 이는 당신의 이익을 잡아먹는다. 특히 짧은 시간 프레임에서, 또한 더 긴 시간 프레임에서 이것은 전략을 사용하기에 매력적이지 않을 수 있다.

EHMA 주변 범위에서 전략은 바가 상위 범위를 넘으면 단기/출구 단위 입장에 들어갈 수 있습니다. 반대로, 바가 하위 범위를 넘으면 단기/출구 단위 입장에 들어갈 수 있습니다. 이것은 바가 EHMA 범위 내에서 흔들리는 행동을 할 경우 위치를 피하고 시장이 방향에 확신하는 경우에만 입장에 들어갈 수 있습니다. 그렇다고 해서 가짜아웃은 여전히 가능하지만 훨씬 덜 빈번합니다. 이 전략을 일반 EHMA 전략과 비교하여 백테스트 한 후 (그리고 다양한 설정을 실험 한 후),이 버전은 훨씬 더 견고하고 수익성이있는 것처럼 보입니다!

면책 과거의 성과가 미래의 결과를 나타내는 것은 아닐 수 있습니다. 다양한 요인, 변화하는 시장 조건 등으로 인해 전략은 더 이상 역사적인 백테스팅과 같은 성능을 발휘하지 않을 수 있습니다. 이 포스트와 시나리오는 어떤 재정적 조언도 제공하지 않습니다.

백테스트

img


/*backtest
start: 2021-05-08 00:00:00
end: 2022-05-07 23:59:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// Credit is due where credit is due:
// Hull Moving Average: developed by Alan Hull
// EHMA: coded by Twitter @borserman
// I've built on their work in an attempt to create a strategy more robust to fake moves
// @0xLetoII

//@version=4
//strategy(
//  title="EHMA Range Strategy",
//  process_orders_on_close=true,
//  explicit_plot_zorder=true,
//  overlay=true, 
//  initial_capital=1500, 
//  default_qty_type=strategy.percent_of_equity, 
//  commission_type=strategy.commission.percent, 
//  commission_value=0.085,
//  default_qty_value=100
//  )
  

// Position Type
pos_type = input(defval = "Both", title="Position Type", options=["Both", "Long", "Short"])

// Inputs
Period = input(defval=180, title="Length")
RangeWidth = input(defval=0.02, step=0.01, title="Range Width")
sqrtPeriod = sqrt(Period)

// Function for the Borserman EMA
borserman_ema(x, y) =>
    alpha = 2 / (y + 1)
    sum = 0.0
    sum := alpha * x + (1 - alpha) * nz(sum[1])

// Calculate the Exponential Hull Moving Average
EHMA = borserman_ema(2 * borserman_ema(close, Period / 2) - borserman_ema(close, Period), sqrtPeriod)

// Create upper & lower bounds around the EHMA for broader entries & exits
upper = EHMA + (EHMA * RangeWidth)
lower = EHMA - (EHMA * RangeWidth)

// Plots
EHMAcolor = (close > EHMA ? color.green : color.red)
plot(EHMA, color=EHMAcolor, linewidth=2)
plot(lower, color=color.orange, linewidth=2)
plot(upper, color=color.blue, linewidth=2)


// Strategy
long = close > upper
exit_long = close < lower
short = close < lower
exit_short = close > upper


// Calculate start/end date and time condition
//startDate  = input(timestamp("2017-01-01T00:00:00"))
//finishDate = input(timestamp("2029-01-01T00:00:00"))
 
time_cond  = true


// Entries & Exits
if pos_type == "Both"
    strategy.entry("Long", strategy.long, comment="Long", when=long and time_cond)
    strategy.close("Long", comment="Exit Long", when=exit_long and time_cond)
    strategy.entry("Short", strategy.short, comment="Short", when=short and time_cond)
    strategy.close("Short", comment="Exit Short", when=exit_short and time_cond)
if pos_type == "Long"
    strategy.entry("Long", strategy.long, comment="Long", when=long and time_cond)
    strategy.close("Long", comment="Exit Long", when=exit_long and time_cond)
if pos_type == "Short"
    strategy.entry("Short", strategy.short, comment="Short", when=short and time_cond)
    strategy.close("Short", comment="Exit Short", when=exit_short and time_cond)
    

관련

더 많은