लाभ लेने के लिए ट्रेलिंग स्टॉप लॉस रणनीति

लेखक:चाओझांग, दिनांक: 2023-12-11 09:58:35
टैगः

img

अवलोकन

ट्रेलिंग टेक प्रॉफिट ट्रेलिंग स्टॉप लॉस रणनीति एक मात्रात्मक ट्रेडिंग रणनीति है जो ट्रेंड ट्रैकिंग, आंशिक टेक प्रॉफिट, फुल-साइकिल ट्रेलिंग स्टॉप लॉस और अन्य कार्यों को जोड़ती है। इसका उद्देश्य ट्रेलिंग स्टॉप का उपयोग करके डाउनसाइड जोखिमों को नियंत्रित करते हुए बुल मार्केट में ऊपर की ओर मूल्य रुझानों को पकड़ना और लाभ लेना है।

रणनीति तर्क

रणनीति तेजी से और धीमी गति से चलती औसत के स्वर्ण क्रॉस का उपयोग खरीद संकेत के रूप में करती है। जब तेजी से एमए धीमी एमए से ऊपर जाता है, तो यह एक अपट्रेंड का संकेत देता है और रणनीति लंबी होगी।

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

इसके बाद, यदि सक्षम किया गया है, तो एक ट्रैलिंग टेक प्रॉफिट तंत्र सक्रिय हो जाएगा। जैसे-जैसे कीमत बढ़ती रहती है, टेक प्रॉफिट की कीमत एक पूर्वनिर्धारित ट्रैलिंग चरण पर कीमत को ट्रेल करती है। यह टेक प्रॉफिट की कीमत को अपट्रेंड का बारीकी से पालन करने में सक्षम बनाता है, ट्रैलिंग टेक प्रॉफिट फ़ंक्शन का एहसास करता है।

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

अंत में, यदि एक पलकबैक के कारण कीमत ट्रेलिंग स्टॉप मूल्य से नीचे प्रवेश करती है, तो रणनीति बाजार मूल्य पर पूरी स्थिति को समतल कर देगी।

लाभ विश्लेषण

ट्रेंड ट्रैकिंग, आंशिक लाभ लेने, पूर्ण चक्र ट्रैलिंग स्टॉप और अधिक को एकीकृत करने से, रणनीति के निम्नलिखित किनारे हैंः

  1. सटीक खरीद संकेतों के साथ प्रभावी रूप से ऊपर की ओर रुझानों को पकड़ता है;
  2. कुछ लाभों में आंशिक लाभ लेने के लिए लॉक, सभी लाभ वापस देने से बचने के लिए;
  3. लाभ लेने के बाद कीमतें तेजी से बढ़ रही हैं।
  4. ट्रैलिंग को सक्रिय करने से अधिक मुनाफे में बाधा आती है और जोखिमों पर नियंत्रण होता है।
  5. व्यक्तिगत जोखिम सहिष्णुता स्तरों के अनुरूप अनुकूलन योग्य मापदंड।

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

इस रणनीति में मुख्य रूप से निम्नलिखित क्षेत्रों में कुछ जोखिम भी हैं:

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

इसके अनुसार अनुकूलन और सुधार के कुछ तरीकों में शामिल हैंः

  1. गलत संकेतों से बचने के लिए चलती औसत मापदंडों को ठीक से सेट करें;
  2. जोखिम कम करने के लिए आंशिक लाभ लेने के अनुपात को कम करना;
  3. घाटे को सीमित करने के लिए स्टॉप लॉस प्रतिशत को सख्त करें;
  4. लाभ प्राप्त करने की प्रभावशीलता को अनुकूलित करने के लिए फाइन ट्यून ट्रेलिंग चरण।

अनुकूलन दिशाएँ

आगे अनुकूलन के लिए जगह हैः

  1. झूठे ब्रेकआउट को रोकने के लिए रुझानों को निर्धारित करने के लिए अधिक संकेतक जोड़ें;
  2. स्थिति राशि को अधिक उचित बनाने के लिए स्थिति आकार को शामिल करें;
  3. मापदंडों को अधिक अनुकूल बनाने के लिए लाभ लेने और हानि रोकने के स्तरों के लिए गतिशील तंत्रों में निर्मित;
  4. अत्यधिक अस्थिर परिसंपत्तियों के लिए गलत लेनदेन से बचने के लिए फ़िल्टर जोड़ें।

ये अनुकूलन रणनीति को अधिक मजबूत बना सकते हैं और प्रदर्शन में सुधार कर सकते हैं।

निष्कर्ष

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


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

//@version=4
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 
//  -----------------------------------------------------------------------------
//  Copyright 2021 Iason Nikolas | jason5480
//  Trainiling Take Profit Trailing Stop Loss script may be freely distributed under the MIT license.
//
//  Permission is hereby granted, free of charge, 
//  to any person obtaining a copy of this software and associated documentation files (the "Software"), 
//  to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, 
//  publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
//  subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
//  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
//  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//  -----------------------------------------------------------------------------
//
//  Authors:  @jason5480
//  Revision: v1.0.1
//  Date:     18-Apr-2021
//
//  Description
//  =============================================================================
//  This strategy will go long if fast MA crosses over slow MA.
//  The strategy will exit from long position when the price increases by a fixed percentage.
//  If the trailing take profit is checked then the strategy instead of setting a limit order in a predefined price (based on the percentage)
//  it will follow the price with small steps (percentagewise)
//  If the price drops by this percentage then the exit order will be executed
//
//  The strategy has the following parameters:
//
//  Fast SMA Length - How many candles back to calculte the fast SMA.
//  Slow SMA Length - How many candles back to calculte the slow SMA.
//  Take Profit % - The percentage of the price increase to set the take profit price target.
//  Enable Trailing - Enable or disable the trailing for take profit.
//  Training Take Profit Deviation % - The step to follow the price when the take profit limit is reached.
//  Trailing Stop Loss % - The stop loss percentage drop that will close your position. After the take profit price is reached the trailing stop loss price target will follow the price upwards (for long positions).
//  
//  -----------------------------------------------------------------------------
//  Disclaimer:
//    1. I am not licensed financial advisors or broker dealer. I do not tell you 
//       when or what to buy or sell. I developed this software which enables you 
//       execute manual or automated trades using TradingView. The 
//       software allows you to set the criteria you want for entering and exiting 
//       trades.
//    2. Do not trade with money you cannot afford to lose.
//    3. I do not guarantee consistent profits or that anyone can make money with no 
//       effort. And I am not selling the holy grail.
//    4. Every system can have winning and losing streaks.
//    5. Money management plays a large role in the results of your trading. For 
//       example: lot size, account size, broker leverage, and broker margin call 
//       rules all have an effect on results. Also, your Take Profit and Stop Loss 
//       settings for individual pair trades and for overall account equity have a 
//       major impact on results. If you are new to trading and do not understand 
//       these items, then I recommend you seek education materials to further your
//       knowledge.
//
//    YOU NEED TO FIND AND USE THE TRADING SYSTEM THAT WORKS BEST FOR YOU AND YOUR 
//    TRADING TOLERANCE.
//
//    I HAVE PROVIDED NOTHING MORE THAN A TOOL WITH OPTIONS FOR YOU TO TRADE WITH THIS PROGRAM ON TRADINGVIEW.
//    
//    I accept suggestions to improve the script.
//    If you encounter any problems I will be happy to share with me.
//  -----------------------------------------------------------------------------
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// SETUP ============================================================================================================
strategy(title = "Trailing Take Profit Trailing Stop Loss",
         shorttitle = "TTPTSL",
         overlay = true,
         pyramiding = 0,
         default_qty_type = strategy.cash,
         default_qty_value = 100000,
         initial_capital = 100000)

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// INPUTS ===========================================================================================================

// STRATEGY INPUT ===================================================================================================
fastMALen = input(defval = 21, title = "Fast SMA Length", type = input.integer, group = "Strategy", tooltip = "How many candles back to calculte the fast SMA.")
slowMALen = input(defval = 49, title = "Slow SMA Length", type = input.integer, group = "Strategy", tooltip = "How many candles back to calculte the slow SMA.")

longTakeProfitPerc = input(defval = 12.0, title = 'Take Profit %', type = input.float, step = 0.1, group = "Strategy", tooltip = "The percentage of the price increase to set the take profit price target.") / 100
profitQuantityPerc = input(defval = 50, title = 'Take Profit Quantity %', type = input.float, step = 1.0, group = "Strategy", tooltip = "The percentage of the position that will be withdrawn when the take profit price target is hit.") / 100

enableTrailing = input(defval = true, title = "Enable Trailing", type = input.bool, group = "Strategy", tooltip = "Enable or disable the trailing for take profit.")
trailingTakeProfitDeviationPerc = input(defval = 1.0, title = 'Trailing Take Profit Deviation %', type = input.float, step = 0.05, group = "Strategy", tooltip = "The step to follow the price when the take profit limit is reached.") / 100

longTrailingStopLossPerc  = input(defval = 7.5, title = 'Trailing Stop Loss %',  type = input.float, step = 0.1, group = "Strategy", tooltip = "The stop loss percentage drop that will close your position. After the take profit price is reached the trailing stop loss price target will follow the price upwards (for long positions).") / 100

// BACKTEST PERIOD INPUT ============================================================================================
fromDate = input(defval = timestamp("01 Jan 2021 00:00 UTC"), title = "From Date", type = input.time, minval = timestamp("01 Jan 1970 00:00 UTC"), group = "Backtest Period") // backtest start date
toDate   = input(defval = timestamp("31 Dec 2121 23:59 UTC"), title = "To Date",   type = input.time, minval = timestamp("01 Jan 1970 00:00 UTC"), group = "Backtest Period") // backtest finish date

isWithinBacktestPeriod() => true // create function "within window of time"

// SHOW PLOT INPUT ==================================================================================================
showDate = input(defval = true, title = "Show Backtest Range", type = input.bool, group = "Plot", tooltip = "Gray out the backround of the backtest period.")

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// STRATEGY =========================================================================================================

fastMA = sma(close, fastMALen)
slowMA = sma(close, slowMALen)

startLongDeal = crossover(fastMA, slowMA)

longTakeProfitPrice = strategy.position_avg_price * (1 + longTakeProfitPerc)

longTrailingTakeProfitStepTicks = longTakeProfitPrice * trailingTakeProfitDeviationPerc / syminfo.mintick

// determine trailing stop loss price. Trailing starts when the take profit price is reached
longTrailingStarted = false
longTrailingStarted := if (strategy.position_size > 0)
    crossover(high, longTakeProfitPrice) or (high[1] >= longTakeProfitPrice) or longTrailingStarted[1]
else
    false

float longTrailingStopLossPrice = na
longTrailingStopLossPrice := if (strategy.position_size > 0)
    stopValue = longTrailingStarted == true ? high * (1 - longTrailingStopLossPerc) : strategy.position_avg_price * (1 - longTrailingStopLossPerc)
    max(stopValue, nz(longTrailingStopLossPrice[1]))
else
    na

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// STRATEGY EXECUTION ===============================================================================================

if (isWithinBacktestPeriod())
    // getting into LONG position
    strategy.entry(id = "Long", long = strategy.long, when = startLongDeal, comment = "Long", alert_message = "Long("  + syminfo.ticker + "): Started")
    if (strategy.position_size > 0)
        strategy.exit(id = "TTP", from_entry = "Long", qty = profitQuantityPerc * strategy.position_size, limit = enableTrailing ? na : longTakeProfitPrice, trail_price = enableTrailing ? longTakeProfitPrice : na, trail_offset = enableTrailing ? longTrailingTakeProfitStepTicks : na, oca_name = 'Exit Long', comment = "Long Take Profit", alert_message = "Long(" + syminfo.ticker + "): Trailing Take Profit activated")
        strategy.order(id = "TSL", long = strategy.short, qty = strategy.position_size, stop = longTrailingStopLossPrice, oca_name = 'Exit Long', oca_type = strategy.oca.cancel, comment = "Stop/Trail", when = true, alert_message = "Long("  + syminfo.ticker + "): Trailing Stop Loss activated")
    else
        strategy.cancel(id = "TTP", when = true)
        strategy.cancel(id = "TSL", when = true)
        
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// PLOT DATE POSITION MA AND TRAILING TAKE PROFIT STOP LOSS =========================================================

bgcolor(color = showDate and isWithinBacktestPeriod() ? color.gray : na, transp = 90)

plot(series = fastMA, color = #0056BD, style = plot.style_line, linewidth = 2, title = "Fast SMA")
plot(series = slowMA, color = #FF6A00, style = plot.style_line, linewidth = 2, title = "Slow SMA")
plotshape(series = isWithinBacktestPeriod() and startLongDeal and strategy.position_size <= 0 ? fastMA : na, title = "UpTrend Begins", location = location.absolute, style = shape.circle, size = size.tiny, color = color.green, transp = 0)
plotshape(series = isWithinBacktestPeriod() and startLongDeal and strategy.position_size <= 0 ? fastMA : na, title = "Buy", text = "Buy", location = location.absolute, style = shape.labelup, size = size.tiny, color = color.green, textcolor = color.black, transp = 0)

plot(series = strategy.position_avg_price, color = color.blue, style = plot.style_linebr, linewidth = 2, title = "Position")
plot(series = longTakeProfitPrice, color = #FFD700, style = plot.style_linebr, linewidth = 2, title = "Long Take Profit")
plot(series = longTrailingStopLossPrice, color = color.fuchsia, style = plot.style_linebr, linewidth = 2, title = "Long Trail Stop")

// ==================================================================================================================

अधिक