ईएचएमए रेंज रणनीति

लेखक:चाओझांग, दिनांकः 2022-05-09 23:31:59
टैगःईएचएमए

यह स्क्रिप्ट एक्सपोनेंशियल हॉल मूविंग एवरेज के लिए @बोर्सरमैन की स्क्रिप्ट का एक संशोधित संस्करण है ईएचएमए के लिए सभी श्रेय उसे जाता है :)

ईएचएमए के अलावा, यह स्क्रिप्ट ईएचएमए (जो संशोधित किया जा सकता है) के आसपास की सीमा के साथ काम करता है, नकली संकेतों के खिलाफ मजबूत होने के प्रयास में। कई बार एक बार एक चलती औसत से नीचे बंद हो जाएगा, केवल अगले बार को फिर से उलटने के लिए, जो आपके मुनाफे को खा जाता है। विशेष रूप से कम समय सीमा पर, लेकिन लंबे समय के समय सीमा पर भी यह एक रणनीति का उपयोग करने के लिए अप्रिय बना सकता है।

ईएचएमए के आसपास की सीमा के साथ, रणनीति केवल एक लंबी / निकास-लघु स्थिति में प्रवेश करती है यदि एक बार ऊपरी सीमा से ऊपर पार करता है। इसके विपरीत, यह केवल एक छोटी / निकास-लंबी स्थिति में प्रवेश करता है यदि एक बार निचली सीमा से नीचे पार करता है। यह पदों से बचता है यदि बार ईएचएमए सीमा के भीतर चंचल व्यवहार करते हैं और केवल एक स्थिति में प्रवेश करते हैं यदि बाजार इसकी दिशा में आश्वस्त है। यह कहते हुए, नकली अभी भी संभव है, लेकिन बहुत कम बार। नियमित ईएचएमए रणनीति के खिलाफ इस रणनीति का बैकटेस्ट करने के बाद (और विभिन्न सेटिंग्स के साथ प्रयोग करने के बाद), यह संस्करण बहुत अधिक मजबूत और लाभदायक लगता है!

अस्वीकरण कृपया याद रखें कि पिछले प्रदर्शन भविष्य के परिणामों का संकेत नहीं हो सकता है। विभिन्न कारकों के कारण, बाजार की बदलती परिस्थितियों सहित, रणनीति अब ऐतिहासिक बैकटेस्टिंग के रूप में अच्छा प्रदर्शन नहीं कर सकती है। यह पोस्ट और स्क्रिप्ट कोई वित्तीय सलाह नहीं देती है।

बैकटेस्ट

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)
    

संबंधित

अधिक