Strategi Julat EHMA

Penulis:ChaoZhang, Tarikh: 2022-05-09 23:31:59
Tag:EHMA

Skrip ini adalah versi diubah suai skrip @borserman untuk Exponential Hull Moving Average Semua kredit untuk EHMA pergi kepadanya :)

Selain EHMA, skrip ini berfungsi dengan julat di sekitar EHMA (yang boleh diubah suai), dalam usaha untuk menjadi kuat terhadap isyarat palsu. Sering kali bar akan ditutup di bawah purata bergerak, hanya untuk membalikkan lagi bar seterusnya, yang memakan keuntungan anda.

Dengan julat di sekitar EHMA, strategi hanya memasuki kedudukan panjang / keluar pendek jika bar melintasi di atas julat atas. Sebaliknya, ia hanya memasuki kedudukan pendek / keluar panjang jika bar melintasi di bawah julat bawah. Ini mengelakkan kedudukan jika bar berkelakuan bergelombang dalam julat EHMA & hanya memasuki kedudukan jika pasaran yakin ke arahnya. Setelah mengatakan itu, penipuan masih mungkin, tetapi jauh lebih jarang berlaku. Setelah menguji semula strategi ini berbanding strategi EHMA biasa (dan telah bereksperimen dengan pelbagai tetapan), versi ini nampaknya lebih mantap & menguntungkan!

Pengecualian Sila ingat bahawa prestasi masa lalu mungkin tidak menunjukkan hasil masa depan. Oleh kerana pelbagai faktor, termasuk keadaan pasaran yang berubah, strategi mungkin tidak lagi berfungsi dengan baik seperti dalam ujian semula sejarah. Pos ini dan skrip tidak memberikan sebarang nasihat kewangan.

Ujian belakang

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)
    

Berkaitan

Lebih lanjut