सामान्य समर्थन/प्रतिरोध पर आधारित रिवर्सल ट्रेडिंग रणनीति

लेखक:चाओझांग, दिनांक: 2023-10-30 11:23:25
टैगः

img

अवलोकन

यह रणनीति तेजी / मंदी कारकों के आधार पर रिवर्सल ट्रेडिंग को अपनाती है, जिसमें पूर्व निर्धारित लाभ लेने के स्तर होते हैं। कारकों का मूल व्यापारिक मात्रा के आधार पर विस्तारित पैटर्न सामान्यीकृत समर्थन / प्रतिरोध है, जो उच्च मात्रा और अस्थिरता वाले शेयरों के लिए उपयुक्त है। फायदे मध्यम-लघु अवधि में बड़े रिवर्सल अवसरों को कैप्चर करने और जल्दी से लाभ कमाने में निहित हैं, जबकि यह फंसने का जोखिम उठाता है।

रणनीति तर्क

  1. वॉल्यूम के साथ व्यापक समर्थन/प्रतिरोध के आधार पर तेजी/बियर कारक की पहचान करना

    • महत्वपूर्ण मात्रा द्वारा फ़िल्टर किए गए क्लासिक एस/आर स्तरों की पहचान करने के लिए कैंडलस्टिक पैटर्न का उपयोग करना

    • सामान्यीकृत एस/आर में क्लासिक पैटर्न की तुलना में बेहतर कवरेज है

    • सामान्य समर्थन संकेतों को तोड़ने का लंबा कारक, सामान्य प्रतिरोध संकेतों को तोड़ने का छोटा कारक

  2. रिवर्सल ट्रेडिंग

    • जब कारक संकेत ट्रिगर रिवर्स स्थिति ले लो

    • यदि पहले से ही स्थिति में है, तो पीछे की स्थिति को कम या जोड़ें

  3. लाभ लक्ष्य स्तरों का निर्धारण

    • एटीआर के आधार पर स्टॉप लॉस सेट करें

    • 1R, 2R, 3R जैसे कई लाभ स्तर सेट करें

    • विभिन्न लक्ष्यों को प्राप्त करते समय आंशिक लाभ

लाभ

  • मध्यम अवधि के उचित उलटफेरों को पकड़ें

    एस/आर ब्रेकआउट कुछ विश्वसनीयता के साथ मजबूत रिवर्स सिग्नल का प्रतिनिधित्व करते हैं, जो मध्यम अवधि के रिवर्स को पकड़ने में सक्षम हैं।

  • तेजी से लाभ उठाना, छोटे निकासी

    स्टॉप लॉस और कई लाभ लक्ष्य निर्धारित करके, त्वरित लाभ प्राप्त कर सकते हैं और ड्रॉडाउन को सीमित कर सकते हैं

  • महत्वपूर्ण संस्थागत धन और अस्थिरता वाले शेयरों के लिए उपयुक्त

    रणनीति मात्रा पर निर्भर करती है, जिसके लिए संस्थागत भागीदारी की आवश्यकता होती है; लाभ कमाने के लिए अस्थिरता की भी आवश्यकता होती है

जोखिम

  • रेंज-बाउंड मार्केट में फंस जाना

    विपरीत दिशा में बार-बार स्टॉप लॉस से बाहर निकलने और फिर से प्रवेश करने से विप्सॉव हो सकते हैं

  • समर्थन/प्रतिरोध की विफलता

    सामान्यीकृत एस/आर पूरी तरह से विश्वसनीय नहीं है, कुछ विफलताएं मौजूद हैं

  • एकतरफा होल्डिंग जोखिम

    शुद्ध उल्टा तर्क बड़े रुझान के अवसरों को याद कर सकता है

  • जोखिम प्रबंधन:

    • ढीला कारक स्थितियों, हर ब्रेकआउट पर उलट नहीं

    • अन्य फ़िल्टर जोड़ें जैसे कि मूल्य/मात्रा विचलन

    • जाल को कम करने के लिए स्टॉप लॉस रणनीति का अनुकूलन करें

सुधार दिशाएँ

  • एस/आर मापदंडों का अनुकूलन

    सामान्यीकृत एस/आर सेटिंग्स को ट्विक करके अधिक विश्वसनीय कारक खोजें

  • मुनाफा कमाने का अनुकूलन

    अधिक लाभ स्तर जोड़ें, या गैर-स्थिर लक्ष्यों का उपयोग करें

  • स्टॉप लॉस को अनुकूलित करें

    एटीआर मापदंडों को समायोजित करें या अनावश्यक स्टॉप को कम करने के लिए स्टॉप हानि का उपयोग करें

  • रुझान और अन्य कारकों को शामिल करें

    बड़े प्रवृत्ति संघर्षों से बचने के लिए चलती औसत जैसे प्रवृत्ति फ़िल्टर जोड़ें; अन्य सहायक कारकों को भी जोड़ें

सारांश

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


/*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"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DojiEmoji

//@version=5
strategy("Fractal Strat [KL] ", overlay=true, pyramiding=1, initial_capital=1000000000)
var string ENUM_LONG = "Long"
var string GROUP_ENTRY = "Entry"
var string GROUP_TSL = "Stop loss"
var string GROUP_TREND = "Trend prediction"
var string GROUP_ORDER = "Order size and Profit taking"

// backtest_timeframe_start = input.time(defval=timestamp("01 Apr 2000 13:30 +0000"), title="Backtest Start Time")
within_timeframe = true

// TSL: calculate the stop loss price. {
_multiple       = input(2.0, title="ATR Multiplier for trailing stop loss", group=GROUP_TSL)
ATR_TSL         = ta.atr(input(14, title="Length of ATR for trailing stop loss", group=GROUP_TSL, tooltip="Initial risk amount = atr(this length) x multiplier")) * _multiple
TSL_source      = low
TSL_line_color  = color.green
TSL_transp      = 100
var stop_loss_price = float(0)

var float initial_entry_p    = float(0)
var float risk_amt           = float(0)
var float initial_order_size = float(0)

if strategy.position_size == 0 or not within_timeframe
    TSL_line_color := color.black
    stop_loss_price := TSL_source - ATR_TSL
else if strategy.position_size > 0
    stop_loss_price := math.max(stop_loss_price, TSL_source - ATR_TSL)
    TSL_transp := 0

plot(stop_loss_price, color=color.new(TSL_line_color, TSL_transp))
// } end of "TSL" block


// Order size and profit taking {
pcnt_alloc = input.int(5, title="Allocation (%) of portfolio into this security", tooltip="Size of positions is based on this % of undrawn capital. This is fixed throughout the backtest period.", minval=0, maxval=100, group=GROUP_ORDER) / 100

// Taking profits at user defined target levels relative to risked amount (i.e 1R, 2R, 3R)
var bool  tp_mode = input(true, title="Take profit and different levels", group=GROUP_ORDER)
var float FIRST_LVL_PROFIT = input.float(1, title="First level profit", tooltip="Relative to risk. Example: entry at $10 and inital stop loss at $9. Taking first level profit at 1R means taking profits at $11", group=GROUP_ORDER)
var float SECOND_LVL_PROFIT = input.float(2, title="Second level profit", tooltip="Relative to risk. Example: entry at $10 and inital stop loss at $9. Taking second level profit at 2R means taking profits at $12", group=GROUP_ORDER)
var float THIRD_LVL_PROFIT = input.float(3, title="Third level profit", tooltip="Relative to risk. Example: entry at $10 and inital stop loss at $9. Taking third level profit at 3R means taking profits at $13", group=GROUP_ORDER)

// }

// Fractals {
// Modified from synapticEx's implementation: https://www.tradingview.com/script/cDCNneRP-Fractal-Support-Resistance-Fixed-Volume-2/

rel_vol_len = 6 // Relative volume is used; the middle candle has to have volume above the average (say sma over prior 6 bars)
rel_vol = ta.sma(volume, rel_vol_len)
_up = high[3]>high[4] and high[4]>high[5] and high[2]<high[3] and high[1]<high[2] and volume[3]>rel_vol[3]
_down = low[3]<low[4] and low[4]<low[5] and low[2]>low[3] and low[1]>low[2] and volume[3]>rel_vol[3]

fractal_resistance = high[3], fractal_support = low[3]   // initialize

fractal_resistance :=  _up ? high[3] : fractal_resistance[1]
fractal_support := _down ? low[3] : fractal_support[1]

plot(fractal_resistance, "fractal_resistance", color=color.new(color.red,50), linewidth=2, style=plot.style_cross, offset =-3, join=false)
plot(fractal_support, "fractal_support", color=color.new(color.lime,50), linewidth=2, style=plot.style_cross, offset=-3, join=false)
// }

// ATR diversion test {
// Hypothesis testing (2-tailed):
//
// Null hypothesis (H0) and Alternative hypothesis (Ha):
//     H0 : atr_fast equals atr_slow
//     Ha : atr_fast not equals to atr_slow; implies atr_fast is either too low or too high
len_fast    = input(5,title="Length of ATR (fast) for diversion test", group=GROUP_ENTRY)
atr_fast    = ta.atr(len_fast)
atr_slow    = ta.atr(input(50,title="Length of ATR (slow) for diversion test", group=GROUP_ENTRY, tooltip="This needs to be larger than Fast"))

// Calculate test statistic (test_stat)
std_error   = ta.stdev(ta.tr, len_fast) / math.pow(len_fast, 0.5)
test_stat = (atr_fast - atr_slow) / std_error

// Compare test_stat against critical value defined by user in settings
//critical_value = input.float(1.645,title="Critical value", tooltip="Strategy uses 2-tailed test to compare atr_fast vs atr_slow. Null hypothesis (H0) is that both should equal. Based on the computed test statistic value, if absolute value of it is +/- this critical value, then H0 will be rejected.", group=GROUP_ENTRY)
conf_interval = input.string(title="Confidence Interval", defval="95%", options=["90%","95%","99%"], tooltip="Critical values of 1.645, 1.96, 2.58, for CI=90%/95%/99%, respectively; Under 2-tailed test to compare atr_fast vs atr_slow. Null hypothesis (H0) is that both should equal. Based on the computed test statistic value, if absolute value of it is +/- critical value, then H0 will be rejected.")
critical_value = conf_interval == "90%" ? 1.645 : conf_interval == "95%" ? 1.96 : 2.58
reject_H0_lefttail = test_stat < -critical_value
reject_H0_righttail = test_stat > critical_value

// } end of "ATR diversion test" block

// Entry Signals
entry_signal_long = close >= fractal_support and reject_H0_lefttail

// MAIN {
// Update the stop limit if strategy holds a position.
if strategy.position_size > 0
    strategy.exit(ENUM_LONG, comment="SL", stop=stop_loss_price)

// Entry
if within_timeframe and entry_signal_long and strategy.position_size == 0
    initial_entry_p := close
    risk_amt := ATR_TSL
    initial_order_size := math.floor(pcnt_alloc * strategy.equity / close)
    strategy.entry(ENUM_LONG, strategy.long, qty=initial_order_size)

var int TP_taken_count = 0
if tp_mode and close > strategy.position_avg_price
    if close >= initial_entry_p + THIRD_LVL_PROFIT * risk_amt and TP_taken_count == 2
        strategy.close(ENUM_LONG, comment="TP Lvl3", qty=math.floor(initial_order_size / 3))
        TP_taken_count := TP_taken_count + 1
    else if close >= initial_entry_p + SECOND_LVL_PROFIT * risk_amt and TP_taken_count == 1
        strategy.close(ENUM_LONG, comment="TP Lvl2", qty=math.floor(initial_order_size / 3))
        TP_taken_count := TP_taken_count + 1
    else if close >= initial_entry_p + FIRST_LVL_PROFIT * risk_amt and TP_taken_count == 0
        strategy.close(ENUM_LONG, comment="TP Lvl1", qty=math.floor(initial_order_size / 3))
        TP_taken_count := TP_taken_count + 1
    
// Alerts
_atr = ta.atr(14)
alert_helper(msg) =>
    prefix = "[" + syminfo.root + "] "
    suffix = "(P=" + str.tostring(close, "#.##") + "; atr=" + str.tostring(_atr, "#.##") + ")"
    alert(str.tostring(prefix) + str.tostring(msg) + str.tostring(suffix), alert.freq_once_per_bar)

if strategy.position_size > 0 and ta.change(strategy.position_size)
    if strategy.position_size > strategy.position_size[1]
        alert_helper("BUY")
    else if strategy.position_size < strategy.position_size[1]
        alert_helper("SELL")

// Clean up - set the variables back to default values once no longer in use
if ta.change(strategy.position_size) and strategy.position_size == 0
    TP_taken_count := 0
    initial_entry_p := float(0)
    risk_amt := float(0)
    initial_order_size := float(0)
    stop_loss_price := float(0)
// } end of MAIN block


अधिक