رجحان کے بعد ٹیک پرافٹ اور ٹریلنگ اسٹاپ لاس سٹریٹیجی


تخلیق کی تاریخ: 2023-12-11 09:58:35 آخر میں ترمیم کریں: 2023-12-11 09:58:35
کاپی: 0 کلکس کی تعداد: 849
1
پر توجہ دیں
1621
پیروکار

رجحان کے بعد ٹیک پرافٹ اور ٹریلنگ اسٹاپ لاس سٹریٹیجی

جائزہ

ٹرینڈ ٹریکنگ اسٹاپ ٹریکنگ اسٹاپ حکمت عملی ایک مقداری تجارتی حکمت عملی ہے جس میں رجحان کی پیروی ، جزوی اسٹاپ اور مکمل ٹریکنگ اسٹاپ کی خصوصیات شامل ہیں ، جس کا مقصد بیل مارکیٹ کے حالات میں قیمتوں میں اضافے کے رجحان کو پکڑنا اور اسمارٹ اسٹاپ کا استعمال کرکے منافع کمانا ہے ، جبکہ ٹریکنگ اسٹاپ کا استعمال کرتے ہوئے نیچے جانے والے خطرے کو کنٹرول کرنا ہے۔

حکمت عملی کا اصول

یہ حکمت عملی تیزی سے چلنے والی اوسط اور سست چلنے والی اوسط کے درمیان ایک خریدنے کے سگنل کے طور پر استعمال کرتی ہے۔ جب تیزی سے چلنے والی اوسط پر سست چلنے والی اوسط سے ٹکرا جاتا ہے تو ، اس کا مطلب یہ ہے کہ قیمتوں میں اضافے کا رجحان پیدا ہوتا ہے ، اس وقت حکمت عملی زیادہ پوزیشن کھولتی ہے۔

اس کے بعد ، حکمت عملی ایک اسٹاپ قیمت طے کرتی ہے ، جو پوزیشن کھولنے کی قیمت کے برابر ہوتی ہے اور اس کی روک تھام کا تناسب طے ہوتا ہے۔ جب قیمت اس اسٹاپ قیمت تک پہنچ جاتی ہے تو ، حکمت عملی جزوی طور پر خالی ہوجاتی ہے ، اور 50٪ پوزیشن کو ڈیفالٹ طور پر فروخت کرتی ہے۔ اس سے جزوی اسٹاپ حاصل ہوتا ہے ، جس سے کچھ منافع کو لاک کیا جاتا ہے۔

اس کے بعد ، حکمت عملی رجحان سے باخبر رہنے والے اسٹاپ میکانیزم کو بھی چالو کرتی ہے۔ جب قیمت بڑھتی رہتی ہے تو ، اسٹاپ قیمت قیمت کو ایک مقررہ قدمی تناسب trailingTakeProfitDeviationPerc کے ساتھ ٹریک کرتی ہے۔ اس سے اسٹاپ قیمت قیمت میں اضافے کے رجحان کے قریب رہ سکتی ہے ، اور رجحان سے باخبر رہنے والے اسٹاپ کو حاصل کرتی ہے۔

اس کے علاوہ ، حکمت عملی اسٹاپ ٹریکنگ کو بھی شروع کرتی ہے۔ جب قیمت اسٹاپ قیمت تک پہنچ جاتی ہے تو ، اسٹاپ قیمت اوپر کی طرف چلنے لگتی ہے ، اور یہ ہمیشہ اونچائی پر برقرار رہتی ہے تاکہ اسٹاپ نقصان کی کمی کا تناسب طے کیا جاسکے۔ اس سے اسٹاپ قیمت کو اوپر کی طرف جانے کی اجازت ملتی ہے ، جس سے زیادہ منافع کو لاک کیا جاسکتا ہے ، جبکہ نیچے جانے کے خطرے پر بھی قابو پایا جاتا ہے۔

جب قیمت میں ردوبدل ہوتا ہے تو ، اگر ٹریکنگ اسٹاپ نقصان کی قیمت کو توڑ دیا جائے تو ، حکمت عملی ٹریکنگ کو روک دیتی ہے ، اور براہ راست مارکیٹ کی قیمت کو صاف کرنے کے لئے باقی پوزیشنوں کو مکمل کرتی ہے۔ اس وقت ، پوری تجارتی سائیکل مکمل ہے۔

طاقت کا تجزیہ

اس حکمت عملی میں ٹرینڈ ٹریکنگ، پارٹیکل اسٹاپس اور مکمل ٹریکنگ اسٹاپس جیسے متعدد افعال شامل ہیں۔ اس کے فوائد یہ ہیں:

  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")

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