चलती औसत ब्रेकआउट पर आधारित प्रवृत्ति-अनुसरण रणनीति

लेखक:चाओझांग, दिनांक: 2023-10-30 12:22:28
टैगः

img

अवलोकन

इस रणनीति का मुख्य विचार उच्च समय सीमाओं में चलती औसत के ब्रेकआउट का पता लगाकर प्रवृत्ति का पालन करना है। जब कीमत उच्च समय सीमा पर चलती औसत से ऊपर या नीचे टूट जाती है, तो यह एक नई प्रवृत्ति की संभावित शुरुआत का संकेत देती है, जिससे व्यापारियों को तदनुसार पद लेने की अनुमति मिलती है।

रणनीति तर्क

यह रणनीति पाइन स्क्रिप्ट में विकसित की गई है और इसमें निम्नलिखित मुख्य घटक शामिल हैंः

  1. इनपुट

    इनपुट पैरामीटर अवधि को चलती औसत अवधि के रूप में परिभाषित करता है, डिफ़ॉल्ट रूप से 200; और समय सीमा को बार समय सीमा के रूप में, डिफ़ॉल्ट रूप से D (दैनिक बार) ।

  2. चलती औसत

    ta.ema फ़ंक्शन का उपयोग करके घातीय चलती औसत (EMA) की गणना करता है.

  3. ब्रेकआउट का पता लगाना

    ta.crossover और ta.crossunder कार्यों का उपयोग करके ब्रेकआउट और ब्रेकडाउन की पहचान करता है।

  4. सिग्नल प्लॉटिंग

    पलायन होने पर सलाखों पर ऊपर और नीचे के तीरों को प्लॉट करता है।

  5. व्यापार प्रवेश और बाहर निकलना

    ब्रेकआउट सिग्नल पर ट्रेड में प्रवेश करता है और जब कीमत 2x स्टॉप लॉस दूरी तक पहुंचती है तो बाहर निकलता है।

यह रणनीति मुख्य रूप से उच्च समय सीमाओं में चलती औसत की प्रवृत्ति-अनुसरण क्षमता का लाभ उठाती है। यह प्रवृत्ति व्यापार के लिए सरल ब्रेकआउट तर्क को लागू करती है, जिससे यह एक पारंपरिक ब्रेकआउट रणनीति बन जाती है।

लाभ विश्लेषण

इस रणनीति के मुख्य लाभों में निम्नलिखित शामिल हैंः

  1. सरल तर्क, समझने और मास्टर करने में आसान।

  2. केवल एक संकेतक पर निर्भर करता है, न्यूनतम पैरामीटर ट्यूनिंग के साथ।

  3. ब्रेकआउट सिग्नल ट्रेंड के अनुरूप होते हैं, अत्यधिक ट्रेडिंग से बचते हैं।

  4. उच्च समय सीमाओं में प्रमुख रुझानों को बिना शोर के स्पष्ट रूप से दर्शाया गया है।

  5. लचीले समय-सीमा संयोजन विभिन्न उत्पादों को पूरा करते हैं।

  6. आसानी से उत्पादों के बीच स्केलेबल, एक साथ ड्रॉडाउन से बचने के लिए।

जोखिम विश्लेषण

संभावित जोखिम हैंः

  1. ब्रेकआउट सिग्नल झूठे सिग्नल साबित हो सकते हैं, जो बाजार के शोर को प्रभावी ढंग से फ़िल्टर करने में असमर्थ हैं।

  2. अल्पकालिक अवसरों का लाभ उठाने में असमर्थ।

  3. यदि प्रमुख रुझान दिशा गलत है तो भारी नुकसान होता है।

  4. चलती औसत और ट्रेडिंग टाइमफ्रेम के बीच टाइमफ्रेम असंगतता से ओवर-ट्रेडिंग या चूक लाभ हो सकता है।

  5. वास्तविक समय में स्टॉप लॉस की कमी के परिणामस्वरूप बढ़े हुए नुकसान हो सकते हैं।

संभावित समाधानों में ट्रेंड-फॉलो करने वाले संकेतकों के साथ संयोजन, फ़िल्टर जोड़ना, होल्डिंग अवधि को छोटा करना, गतिशील स्टॉप लॉस आदि लागू करना शामिल है।

बढ़ोतरी के अवसर

इस रणनीति में निम्नलिखित पहलुओं में सुधार किया जा सकता हैः

  1. ब्रेकआउट की विश्वसनीयता बढ़ाने के लिए एमएसीडी, केडी जैसे ट्रेंड-फॉलोइंग इंडिकेटर जोड़ें।

  2. झूठे ब्रेकआउट से बचने के लिए वॉल्यूम या बोलिंगर बैंड के आधार पर फ़िल्टर जोड़ें।

  3. ट्रेंड चक्र के साथ होल्डिंग अवधि को मेल खाने के लिए पैरामीटर ट्यूनिंग को अनुकूलित करें।

  4. एकल व्यापार हानि को नियंत्रित करने के लिए वास्तविक समय स्टॉप लॉस शामिल करें।

  5. गतिशील पैरामीटर अनुकूलन के लिए मशीन सीखने की तकनीक का अन्वेषण करें।

  6. समग्र स्थिरता बढ़ाने के लिए विभिन्न परिसंपत्ति आवंटन संयोजनों का परीक्षण करें।

निष्कर्ष

संक्षेप में, यह चलती औसत ब्रेकआउट के माध्यम से प्रवृत्ति-अनुसरण के लिए एक सरल और व्यावहारिक रणनीति है। यह समझने और लागू करने में आसान है, जो एल्गो ट्रेडिंग के लिए एक अच्छी परिचयात्मक रणनीति के रूप में कार्य करता है। लेकिन इसमें कुछ खामियां भी हैं जिन्हें संकेतकों के संयोजन, पैरामीटर ट्यूनिंग, गतिशील स्टॉप लॉस आदि के माध्यम से संबोधित करने की आवश्यकता है। सुधार और विस्तार के लिए बहुत जगह बनी हुई है।


/*backtest
start: 2023-09-29 00:00:00
end: 2023-10-29 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=5
// Open-Range-Breakout strategy
// No license. Free and Open Source.    

strategy('Strategy: ORB', shorttitle="ORB", overlay=true , currency=currency.NONE, initial_capital=100000)

// Inputs
period = input.int(defval=15, title="TimeRange", tooltip="The range in minutes (default: 15m)")
sessionInput = input(defval="0915-0930", title="Time Range", group="ORB settings", tooltip='What is the timeperiod (default 9:15AM to 9:30AM, exchange timezone')
hide = input.bool(defval = false, title="Hide ORB Range", group="ORB setting", tooltip = 'Hide the ORB range drawing')

// SL Related
slAtrLen = input.int(defval=14, title="ATR Period for placing SL", group="StopLoss settings")
showSLLines = input.bool(defval=false, title="Show SL lines in chart", tooltip="Show SL lines also as dotted lines in chart. Note: chart may look untidy.", group="StopLoss settings")

// Further Filtering
ignoreMementumVolume = input.bool(defval=false, title="Ignore Momentum & Volume", tooltip="Ignore Momentum & Volume to find out trades", group="Strengh Settings")
rsiLen = input.int(defval=14, title="Momentum Period", group="Strengh Settings", tooltip = 'To determine the momentum, RSI period is set default to 100')
rsiBullish = input.int(defval=50, step=1, title="Bullish Momentum", group="Strengh Settings", tooltip = 'Bullish Momentum, default set to RSI as 50')
rsiBearish = input.int(defval=50, step=1, title="Bearish Momentum", group="Strengh Settings", tooltip = 'Bearish Momentum, default set to RSI as 50')
volAvg = input.int(defval=20, step=1, title="Volume Average Period", group="Strengh Settings", tooltip = 'To calculate average volume, how many historical bars are considered. Default: 20.')
volThreshold = input.float(defval=1, step=0.1, title="Volume Strengh", group="Strengh Settings", tooltip = 'Multiplier: How big the current bar volume compared to average of last 20')

trendPeriod = input.int(defval=200, step=1, title="Trend Period", group="Trend Settings", tooltip = 'To calculate trend, what period is considered. Default: 200.')
hideTrend = input.bool(defval = false, title="Hide the trend line", group="Trend Settings", tooltip = 'Hide the trend')

hidePDHCL = input.bool(defval = false, title="Hide the PDHCL (prev day High Close Low range)", tooltip = 'Hide the Previous Day High, Close, Low lines')

hideTable = input.bool(defval = false, title="Hide the Summary Table", tooltip = 'Hide the summary table.')

// Trade related
rrRatio = input.float(title='Risk:Reward', step=0.1, defval=2.0, group="Trade settings")
endOfDay = input.int(defval=1500, title="Close all trades, default is 3:00 PM, 1500 hours (integer)", group="Trade settings")
mktAlwaysOn = input.bool(defval=true, title="Markets that never closed (Crypto, Forex, Commodity)", tooltip="Some markers never closes. For those cases, make this checked.", group="Trade settings")
lotSize = input.int(title='Lot Size', step=1, defval=1, group="Trade settings")

// Util method

is_newbar(res) => 
	timeframe.change(time(res)) != 0

// print table
printTable(txt) =>
    var table t = table.new(position.bottom_right, 1, 1)
    table.cell(t, 0, 0, txt, text_halign = text.align_left, bgcolor = color.lime)
	
// globals
t = time(timeframe.period, sessionInput + ":1234567") // everyday
in_session = not na(t)
is_first = in_session and not in_session[1]
is_end_session = in_session[1] and not in_session
green(open, close) => close > open ? true : false
red(open, close) => close < open ? true : false

var float orb_high = na
var float orb_low = na
if is_first
    orb_high := high
    orb_low := low
else
    orb_high := orb_high[1]
    orb_low := orb_low[1]
if high > orb_high and in_session
    orb_high := high
if low < orb_low and in_session
    orb_low := low

plot(hide ? na : orb_high, style=plot.style_line, color=orb_high[1] != orb_high ? na : color.green, title="ORB High", linewidth=2)
plot(hide ? na : orb_low, style=plot.style_line, color=orb_low[1] != orb_low ? na : color.red, title="ORB Low", linewidth=2)



// PDHCL (Previous Day High Close Low)
[dh,dl,dc] = request.security(syminfo.ticker, "D", [high[1],low[1], close[1]], lookahead=barmerge.lookahead_on)
plot(hidePDHCL ? na : dh, title="Prev High",  color=color.red,  linewidth=2, trackprice=true, show_last = 1)
plot(hidePDHCL ? na : dl, title="Prev Low",  color=color.green,  linewidth=2, trackprice=true, show_last = 1)
plot(hidePDHCL ? na : dc, title="Prev Close",  color=color.black,  linewidth=2, trackprice=true, show_last = 1)
plot(hidePDHCL ? na : ta.vwap(close), title="Prev VWAP",  color=color.fuchsia,  linewidth=2, trackprice=true, show_last = 1)

var l1 = label.new(bar_index, hidePDHCL ? na : dh, 'PDH', style=label.style_label_right)

// Previous Day WWAP


// For SL calculation
atr = ta.atr(slAtrLen)	
highestHigh = ta.highest(high, 7)
lowestLow = ta.lowest(low, 7)
longStop = showSLLines ? lowestLow - (atr * 1) : na
shortStop = showSLLines ? highestHigh + (atr * 1) : na
plot(longStop, title="Buy SL", color=color.green, style=plot.style_cross)
plot(shortStop, title="Sell SL", color=color.red, style=plot.style_cross)

// Momentum: rsi
rsi = ta.rsi(close, rsiLen)

// trend: EMA200
ema = ta.ema(close, trendPeriod)
plot(hideTrend ? na : ema, "EMA Trend", color=close > ema ? color.green : color.red, linewidth = 1)

// Volume-Weighed Moving Average calculation
vwmaAvg = ta.vwma(close, volAvg)
vwma_latest = volume
// plotshape((barstate.isconfirmed and (vwma_latest > (vwmaAvg * volThreshold))), title='VolumeData', text='', location=location.abovebar, style=shape.diamond, color=color.gray, textcolor=color.gray, size=size.tiny)

// Trade signals

longCond = barstate.isconfirmed and (ta.crossover(close, orb_high) or ta.crossover(close, dh)) and green(open, close) and (ignoreMementumVolume ? true : rsi > rsiBullish and (vwma_latest > (vwmaAvg * volThreshold)))
shortCond = barstate.isconfirmed and (ta.crossunder(close, orb_low) or ta.crossunder(close, dl)) and red(open, close) and (ignoreMementumVolume ? true : rsi < rsiBearish and (vwma_latest > (vwmaAvg * volThreshold)))

plotshape(longCond, title='Breakout', text='BO', location=location.belowbar, style=shape.triangleup, color=color.green, textcolor=color.green)
plotshape(shortCond, title='Breakout', text='BD', location=location.abovebar, style=shape.triangledown, color=color.red, textcolor=color.red)


// Trade execute
h = hour(time('1'), syminfo.timezone)
m = minute(time('1'), syminfo.timezone)
hourVal = h * 100 + m
totalTrades = strategy.opentrades + strategy.closedtrades
if (mktAlwaysOn or (hourVal < endOfDay))
    // Entry
    var float sl = na
    var float target = na
    if (longCond)
        strategy.entry("enter long", strategy.long, lotSize, limit=na, stop=na, comment="Enter Long")
        sl := longStop
        target := close + ((close - longStop) * rrRatio)
        alert('Buy:' + syminfo.ticker + ' ,SL:' + str.tostring(math.floor(sl)) + ', Target:' + str.tostring(target), alert.freq_once_per_bar)
    if (shortCond)
        strategy.entry("enter short", strategy.short, lotSize, limit=na, stop=na, comment="Enter Short")
        sl := shortStop
        target := close - ((shortStop - close) * rrRatio)
        alert('Sell:' + syminfo.ticker + ' ,SL:' + str.tostring(math.floor(sl)) + ', Target:' + str.tostring(target), alert.freq_once_per_bar)

    // Exit: target or SL
    if ((close >= target) or (close <= sl))
        strategy.close("enter long", comment=close < sl ? "Long SL hit" : "Long target hit")
    if ((close <= target) or (close >= sl))
        strategy.close("enter short", comment=close > sl ? "Short SL hit" : "Short target hit")
else if (not mktAlwaysOn)
    // Close all open position at the end if Day
    strategy.close_all(comment = "Close all entries at end of day.")


// Plotting table
if (not hideTable and is_end_session)
    message =  syminfo.ticker + " :\n\nORB Upper: " + str.tostring(math.round(orb_high)) + "\nORB Lower: " + str.tostring(math.round(orb_low)) + "\nPDH: " + str.tostring(math.round(dh)) + "\nPDC: " + str.tostring(math.round(dc)) + "\nPDL: " + str.tostring(math.round(dl)) + "\nVWAP: " + str.tostring(math.round(ta.vwap(close)))   
    printTable(message)
    alert(message, alert.freq_once_per_bar_close)



अधिक