Chiến lược phạm vi EHMA

Tác giả:ChaoZhang, Ngày: 2022-05-09 23:31:59
Tags:EHMA

Kịch bản này là một phiên bản sửa đổi của @borsermans script cho Exponential Hull Moving Average Tất cả các tín dụng cho EHMA đi đến anh ta :)

Ngoài EHMA, kịch bản này hoạt động với một phạm vi xung quanh EHMA (có thể được sửa đổi), trong một nỗ lực để mạnh mẽ chống lại các tín hiệu giả. Nhiều lần một thanh sẽ đóng dưới mức trung bình động, chỉ để đảo ngược lại thanh tiếp theo, làm giảm lợi nhuận của bạn. Đặc biệt là trên khung thời gian ngắn hơn, nhưng cũng trên khung thời gian dài hơn có thể làm cho một chiến lược không hấp dẫn để sử dụng.

Với phạm vi xung quanh EHMA, chiến lược chỉ đi vào vị trí dài / thoát ngắn nếu một thanh vượt qua trên phạm vi trên. Ngược lại, nó chỉ đi vào vị trí ngắn / thoát dài nếu một thanh vượt qua dưới phạm vi dưới. Điều này tránh các vị trí nếu các thanh cư xử hỗn loạn trong phạm vi EHMA và chỉ đi vào vị trí nếu thị trường tự tin vào hướng của nó.

Không chịu trách nhiệm Xin lưu ý rằng hiệu suất trong quá khứ có thể không chỉ ra kết quả trong tương lai. Do nhiều yếu tố khác nhau, bao gồm cả việc thay đổi điều kiện thị trường, chiến lược có thể không còn hoạt động tốt như trong kiểm tra ngược lịch sử. Bài viết này và kịch bản không cung cấp bất kỳ lời khuyên tài chính nào.

backtest

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)
    

Có liên quan

Thêm nữa