गतिशील औसत लागत डॉलर लागत औसत यौगिक रणनीति

लेखक:चाओझांग, दिनांकः 2024-01-04 16:34:10
टैगः

img

अवलोकन

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

रणनीति तर्क

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

जैसे-जैसे डीसीए की गिनती बढ़ती है, औसत होल्डिंग लागत में गिरावट जारी रहती है। प्रत्येक स्थिति का लाभ लेने के लिए केवल एक छोटा रिबाउंड पर्याप्त है। निरंतर प्रविष्टियों को प्रस्तुत करने के बाद, औसत होल्डिंग मूल्य के ऊपर एक स्टॉप लॉस लाइन प्लॉट की जाती है। एक बार कीमत औसत मूल्य और स्टॉप लॉस लाइन से ऊपर टूट जाती है, तो सभी पद बंद हो जाते हैं।

सबसे बड़ा लाभ यह है कि जब होल्डिंग लागत में गिरावट जारी रहती है, तो समेकन के दौरान भी लागत को धीरे-धीरे कम किया जा सकता है। जब प्रवृत्ति उलट जाती है, तो बाजार मूल्य की तुलना में बहुत कम होल्डिंग लागत के कारण, बहुत अधिक लाभ प्राप्त किया जा सकता है।

जोखिम और दोष

सबसे बड़ा जोखिम शुरू में सीमित स्थिति आकार है। निरंतर गिरावट के दौरान, स्टॉप लॉस जोखिम हो सकता है। इसलिए स्टॉप लॉस प्रतिशत को व्यक्तिगत जोखिम भूख के आधार पर उचित रूप से निर्धारित करने की आवश्यकता है।

इसके अलावा, स्टॉप लॉस स्तर सेट करने के दो चरम सीमाएं हैं। यदि बहुत ढीला है, तो पर्याप्त प्रतिगमन नहीं किया जा सकता है। लेकिन यदि बहुत तंग है, तो मध्य-अवधि सुधारों के दौरान बंद होने की संभावना बढ़ जाती है। इसलिए विभिन्न बाजार स्थितियों और जोखिम वरीयता के अनुसार उचित स्टॉप लॉस स्तर चुनना महत्वपूर्ण है।

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

अनुकूलन के सुझाव

  1. उच्च जीत दर संकेतों के लिए मापदंडों और अन्य संकेतकों के संयोजनों का परीक्षण करके प्रवेश समय संकेतों का अनुकूलन करें।

  2. बेहतर परिणाम प्राप्त करने के लिए एल ट्रेलिंग स्टॉप लॉस या वक्र फिट ट्रेलिंग स्टॉप लॉस का परीक्षण करके स्टॉप लॉस तंत्र को अनुकूलित करें। इसके अलावा स्तरों को स्थिति आवंटन प्रतिशत के आधार पर गतिशील रूप से समायोजित किया जा सकता है।

  3. लाभ लेने के तरीकों को अनुकूलित करें। बेहतर निकास अवसरों और उच्च कुल रिटर्न के लिए विभिन्न प्रकार के ट्रेलिंग लाभ लेने की जांच की जा सकती है।

  4. एंटी-विपसा तंत्र जोड़ें। कभी-कभी डीसीए सिग्नल को स्टॉप लॉस के तुरंत बाद फिर से ट्रिगर किया जा सकता है। स्टॉप के तुरंत बाद आक्रामक पुनः प्रविष्टियों से बचने के लिए एक विपसा रेंज जोड़ा जा सकता है।

निष्कर्ष

इस रणनीति का उपयोग करता है आरएसआई निर्धारित करने के लिए प्रविष्टियों, घातीय गतिशील स्टॉप लॉस डीसीए तंत्र को समायोजित करने के लिए स्थिति आकार और औसत लागत गतिशील रूप से, क्रम में प्राप्त करने के लिए मूल्य लाभ के दौरान समेकन. मुख्य अनुकूलन क्षेत्रों पर ध्यान केंद्रित कर रहे हैं प्रवेश / निकास संकेतों, स्टॉप हानि और लाभ लेने. घातीय डीसीए के मूल अवधारणा को लागू किया जाता है स्थानांतरित करने के लिए होल्डिंग लागत लगातार कम, इस प्रकार प्रदान करने के लिए अधिक जगह के दौरान समेकन, और प्राप्त करने के लिए गुणा रिटर्न जब प्रवृत्ति उभरती है. लेकिन मापदंडों अभी भी ध्यान से सेट करने की जरूरत है के आधार पर पूंजी आवंटन योजनाओं को नियंत्रित करने के लिए समग्र स्थिति जोखिम.


/*backtest
start: 2023-12-04 00:00:00
end: 2024-01-03 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///
// © A3Sh
//@version=5

// Study of a Simple RSI based, PA (priceaveraging) and DCA strategy that opens a new position everytime it hits a specified price level below the first entry.
// The first entry is opened when the specified rsi and moving average conditions are met. 
// The following DCA levels are calculated exponentially and set, starting with a specified % of price drop. 
// The disctance between the dca levels can be changed with the exponential scale.
// Each position closes individually when it reaches a specified take profit.
// The position can re-open again when it hits the price level again.
// Each time a position is closed and reopened, the average price drops a little.
// The position stays open until the first entry closes or when the price reaches the Stop level.
// When the price reaches the Stop level, all positions will close at once.

// The RSI and MA code for opening the entry is adapted from the Optimized RSI Buy the Dips strategy, by Coinrule.
// This code is used for study purposes, but any other low/ dip finding indicator can be used.
// https://www.tradingview.com/script/Pm1WAtyI-Optimized-RSI-Strategy-Buy-The-Dips-by-Coinrule/

// Dynamic DCA layers are inspired by the Backtesting 3commas DCA Bot v2, by rouxam
// This logic gives more flexibility because you can dyanically change the amount of dca entries.
// https://www.tradingview.com/script/8d6Auyst-Backtesting-3commas-DCA-Bot-v2/

// The use of for loops to (re)open and close different entries separately is based on the Simple_Pyramiding strategy.
// https://www.tradingview.com/script/t6cNLqDN-Simple-Pyramiding/


strategy('Simple_RSI+PA+DCA', overlay=true, pyramiding=20, initial_capital=500, calc_on_order_fills=true, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.075, close_entries_rule='FIFO')

// Backtest Window //
start_time   = input(defval=timestamp("01 April 2021 20:00"), group = "Backtest Window", title="Start Time")
end_time     = input(defval=timestamp("01 Aug 2030 20:00"),   group = "Backtest Window", title="End Time")
window() => true

// Inputs //
takeProfit      = input.float  (3,           group = 'Risk',           title = 'Take Profit %', step=0.1)
takeProfitAll   = input.float  (6,           group = "Risk",           title = 'Close All %',   step=0.1)
posCount        = input.int    (8,           group = 'DCA Settings',   title = 'Max Amount of Entries')
increment       = input.float  (2,           group = 'DCA Settings',   title = 'Price Drop % to open First DCA Order', step=0.5)/100 
exponent_scale  = input.float  (1.4,         group = 'DCA Settings',   title = 'Exponential Scale DCA levels', step=0.1, minval=1.1) 
bar_lookback    = input.int    (4999,        group = 'DCA Settings',   title = 'Lines Bar Lookback', maxval = 4999)
plotMA          = input.bool   (false,       group = 'Moving Average', title = 'Plot Moving Average')
moving_average  = input.int    (100,         group = 'Moving Average', title = 'MA Length' )
rsiLengthInput  = input.int    (14,          group = 'RSI Settings',   title = "RSI Length", minval=1)
rsiSourceInput  = input.source (close,       group = 'RSI Settings',   title = 'Source')
overSold        = input.int    (29,          group = 'RSI Settings',   title = 'Oversold, Trigger to Enter First Position')

// variables //
var open_position    = true   // true when there are open positions
var entry_price      = 0.0    // the entry price of the first entry
var dca_price        = 0.0    // the price of the different dca layers
var int count        = 0      // bar counter since first open position
var int max_bar      = 0      // max bar buffer variable for DCA lines, stop lines, average price
var line dca_line    = na     // lines variable for creating dca lines

// arrays //
linesArray = array.new_float(posCount,na)  // array to store different dca price levels for creating the dca lines

// Create max bar buffer for DCA lines, Stop and average price lines //
max_bar := count >= bar_lookback ? bar_lookback : count

// Order size based on first entry and amount of DCA layers
q = (strategy.equity  / posCount + 1) / open


// Calculate Moving Averages
movingaverage_signal = ta.sma(close ,moving_average)
plot (plotMA ? movingaverage_signal : na, color = color.new(#f5ff35, 0))


// RSI calculations //
up   = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi  = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))


// Buy Signal (co)
co = ta.crossover(rsi, overSold) and close < movingaverage_signal


// Create a white line for average price, since the last opened position //
// average_price = line.new(x1 = bar_index - max_bar, y1 = strategy.position_avg_price, x2 = bar_index, y2 = strategy.position_avg_price, color = color.white)
    

// Stop //
// Create a red Stop level line based on a specified % above the average price //
stop_level = strategy.position_avg_price + (strategy.position_avg_price / 100 * takeProfitAll)
// stop_line  = line.new(x1 = bar_index - max_bar, y1 = stop_level, x2 = bar_index, y2 = stop_level, color = color.red)
    

// Take profit definition per open position //
take_profit_price = close * takeProfit / 100 / syminfo.mintick


// Make sure the Stop level and average price level don't excied the bar buffer to avoid errors //
// if count <= bar_lookback
//     line.set_x1(stop_line,     strategy.opentrades.entry_bar_index(strategy.opentrades - 1))
//     line.set_x1(average_price, strategy.opentrades.entry_bar_index(strategy.opentrades - 1))


// Exponential DCA Layer Calculation fucntion --> First try, needs more experimentation //
dca_price_level(index,entry_price) =>   
    entry_price * (1 - (increment * math.pow(exponent_scale, index)))


// Set  Entries //
// Open the first entry and set the entry price //
if co and strategy.position_size == 0 and window() 
    open_position := true
    entry_price   := close
    strategy.entry(id = 'FE1', direction = strategy.long, qty = q)  
    
// first_entry_line = line.new(x1 = bar_index - max_bar, y1 = entry_price, x2 = bar_index, y2 = entry_price, color = color.blue)


// Start bar counting since the position is open //
if open_position == true
    count := count + 1


// Set the DCA entries //
// Prices below 1 are not set to avoid negative prices //
if strategy.position_size > 0 and window()
    for i = 0 to strategy.opentrades
        if strategy.opentrades == i and i < posCount
            dca_price := dca_price_level(i,entry_price) > 1 ? dca_price_level(i,entry_price) : na
            entry_id = 'DCA' + str.tostring(i + 1) 
            strategy.entry(id = entry_id, direction = strategy.long, limit = dca_price, qty = q)  


// Store the values of the different dca price levels in an array and create the dca lines // 
// Prices below 1 are not stored//
if open_position==true and window() 
    for i = 1 to posCount -1
        array.push(linesArray, dca_price_level(i,entry_price) > 1 ? dca_price_level(i,entry_price) : na) 
    
    // for i = 1 to array.size(linesArray) - 1
    //     dca_line := line.new(x1 = bar_index - max_bar, y1 = array.get(linesArray, i), x2 = bar_index, y2 = array.get(linesArray, i),color = color.blue)


// Create thick line to show the last Entry price //
// last_entry_price = line.new(x1 = bar_index[5], y1 = strategy.opentrades.entry_price(strategy.opentrades - 1), x2 = bar_index, y2 = strategy.opentrades.entry_price(strategy.opentrades - 1),color = color.rgb(255, 0, 204), width = 5)


// Exit the first entry when the take profit triggered //   
if strategy.opentrades > 0 and window() 
    strategy.exit(id = 'Exit FE', from_entry = 'FE1', profit = take_profit_price)


// Exit DCA entries when take profit is triggered //
if strategy.opentrades > 0 and window() 
    for i = 0 to strategy.opentrades 
        exit_from = 'DCA' + str.tostring(i + 1)
        exit_id = 'Exit_' + str.tostring(i + 1)
        strategy.exit(id = exit_id, from_entry = exit_from, profit = take_profit_price)


// Close all positions at once when Stop is crossed //
if strategy.opentrades > 0 and ta.crossover(close,stop_level) and window() 
    strategy.close_all()


// Make sure nothing is open after alle positions are closed and set the condiftion back to be open for new entries //
if strategy.position_size[1] > 0 and strategy.position_size == 0
    strategy.cancel_all()
    strategy.close_all()
    // line.delete(average_price)
    // line.delete(stop_line)
    // line.delete(dca_line)
    open_position := false   // All position are closed, so back to false
    count := 0               // Reset bar counter




अधिक