Stratégie de la gamme EHMA

Auteur:ChaoZhang est là., Date: 2022-05-09 23h31 et 59 min
Les étiquettes:EHMA

Ce script est une version modifiée du script de @borserman pour la moyenne mobile exponentielle de Hull Tout le mérite de l' EHMA lui revient.

En plus de l'EHMA, ce script fonctionne avec une plage autour de l'EHMA (qui peut être modifiée), dans une tentative d'être robuste contre les faux signaux.

Avec la plage autour de l'EHMA, la stratégie n'entre dans une position longue/sortie-courte que si une barre traverse au-dessus de la plage supérieure. Inversement, elle n'entre dans une position courte/sortie-longue que si une barre traverse au-dessous de la plage inférieure. Cela évite les positions si les barres se comportent de manière agitée dans la plage EHMA et n'entre dans une position que si le marché est confiant dans sa direction. Cela dit, les faux-sacs sont toujours possibles, mais beaucoup moins fréquents. Ayant testé cette stratégie par rapport à la stratégie EHMA régulière (et ayant expérimenté divers paramètres), cette version semble être beaucoup plus robuste et rentable!

Disclaimer N'oubliez pas que les résultats passés peuvent ne pas indiquer les résultats futurs. En raison de divers facteurs, y compris l'évolution des conditions du marché, la stratégie peut ne plus être aussi efficace que lors des tests antérieurs. Ce billet et le scénario ne fournissent aucun conseil financier.

test de retour

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)
    

Relationnée

Plus de