پائیدار ٹریلنگ سٹاپ نقصان ٹریڈنگ کی حکمت عملی

مصنف:چاؤ ژانگ، تاریخ: 2023-12-12 17:29:24
ٹیگز:

img

جائزہ

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

حکمت عملی منطق

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

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

فوائد کا تجزیہ

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

خطرے کا تجزیہ

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

اصلاح کی ہدایات

اسٹریٹیجی کو مندرجہ ذیل پہلوؤں میں بہتر بنایا جاسکتا ہے:

  1. انٹری کی درستگی کو بہتر بنانے کے لئے انٹری اور سٹاپ نقصان کے حالات کو بہتر بنائیں

  2. نقصان کو روکنے اور منافع کو زیادہ سے زیادہ کرنے کے درمیان توازن کے لئے اسٹاپ نقصان کا فیصد بہتر بنائیں

  3. بہتر منافع کی تالے کے لئے منافع لینے کے حالات شامل کریں

  4. زیادہ لچک کے لئے زیادہ پیرامیٹرنگ متعارف کروائیں

نتیجہ

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


/*backtest
start: 2022-12-05 00:00:00
end: 2023-12-11 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 
//  -----------------------------------------------------------------------------
//  Copyright 2019 Mauricio Pimenta | exit490
//  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:  @exit490
//  Revision: v1.0.0
//  Date:     03-Aug-2019
//
//  DESCRIPTION
//  ===========
//
//  This TradingView strategy it is designed to integrate with other strategies with indicators. 
//  It performs a trailing stop loss from entry and exit conditions. 
//  In this strategy you can add conditions for long and short positions.
//  The strategy will ride up your stop loss when price moviment 1%.
//  The strategy will close your operation when the market price crossed the stop loss.
//  Also is possible to select the period that strategy will execute the backtest.
//
//  The strategy has the following parameters:
//  INITIAL STOP LOSS - Where can isert the value to first stop.
//  POSITION TYPE - Where can to select trade position.
//  BACKTEST PERIOD - To select range.
//  
//  -----------------------------------------------------------------------------
//
//  DISCLAIMER:
//    1. I am not licensed financial advisors or broker dealers. I do not tell you 
//       when or what to buy or sell. I developed this software which enables you 
//       execute manual or automated trades multiple 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.
//  -----------------------------------------------------------------------------
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //

strategy("TRAILING STOP LOSS TO LONG AND SHORT", overlay=true)

// === ADD YOUR CONTIDIONAL HERE ====

hasEntryLongConditional() => 1 == 1
hasCloseLongConditional() => 1 != 1

hasEntryShortConditional() => 1 == 1
hasCloseShortConditional() => 1 != 1

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //

// === BACKTEST RANGE ===
backTestSectionFrom = input(title = "═══════════════ FROM ═══════════════", defval = true, type = input.bool)

FromMonth       = input(defval = 1, title = "Month", minval = 1)
FromDay         = input(defval = 1, title = "Day", minval = 1)
FromYear        = input(defval = 2014, title = "Year", minval = 2014)

backTestSectionTo = input(title = "════════════════ TO ════════════════", defval = true, type = input.bool)
ToMonth         = input(defval = 31, title = "Month", minval = 1)
ToDay           = input(defval = 12, title = "Day", minval = 1)
ToYear          = input(defval = 9999, title = "Year", minval = 2014)

backTestPeriod() => (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //


parameterSection = input(title = "═════════════ STRATEGY ═════════════", defval = true, type = input.bool)
// === INPUT TO SELECT POSITION ===
positionType = input(defval="LONG", title="Position Type", options=["LONG", "SHORT"])

// === INPUT TO SELECT INITIAL STOP LOSS
initialStopLossPercent = input(defval = 3.0, minval = 0.0, title="Initial Stop Loss")

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //

// === GLOBAL VARIABLES AND FUNCTIONS TO STORE IMPORTANT CONDITIONALS
stopLossPercent = positionType == "LONG" ? initialStopLossPercent * -1 : initialStopLossPercent

var entryPrice = 0.0
var updatedEntryPrice = 0.0
var stopLossPrice = 0.0

hasOpenTrade() => strategy.opentrades != 0
notHasOpenTrade() => strategy.opentrades == 0

strategyClose() =>
    if positionType == "LONG"
        strategy.close("LONG", when=true)
    else 
        strategy.close("SHORT", when=true)

strategyOpen() =>
    if positionType == "LONG"
        strategy.entry("LONG", strategy.long, when=true)
    else 
        strategy.entry("SHORT", strategy.short, when=true)

isLong() => positionType == "LONG" ? true : false
isShort() => positionType == "SHORT" ? true : false

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //

// === LOGIC TO TRAILING STOP IN LONG POSITION
if (isLong() and backTestPeriod())

    crossedStopLoss = close <= stopLossPrice
    terminateOperation = hasOpenTrade() and (crossedStopLoss or hasCloseLongConditional())

    if (terminateOperation)
        entryPrice := 0.0
        updatedEntryPrice := entryPrice
        stopLossPrice := 0.0
        strategyClose()
    
    startOperation = notHasOpenTrade() and hasEntryLongConditional()

    if(startOperation)
        entryPrice := close
        updatedEntryPrice := entryPrice
        stopLossPrice := entryPrice + (entryPrice * stopLossPercent) / 100
        strategyOpen()
        
    strategyPercentege = (close - updatedEntryPrice) / updatedEntryPrice * 100.00
    rideUpStopLoss = hasOpenTrade() and strategyPercentege > 1

    if (isLong() and rideUpStopLoss)
        stopLossPercent := stopLossPercent + strategyPercentege - 1.0
        newStopLossPrice = updatedEntryPrice + (updatedEntryPrice * stopLossPercent) / 100  
        stopLossPrice := max(stopLossPrice, newStopLossPrice)
        updatedEntryPrice := stopLossPrice


//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //

// === LOGIC TO TRAILING STOP IN SHORT POSITION
if (isShort() and backTestPeriod())

    crossedStopLoss = close >= stopLossPrice
    terminateOperation = hasOpenTrade() and (crossedStopLoss or hasCloseShortConditional())

    if (terminateOperation)
        entryPrice := 0.0
        updatedEntryPrice := entryPrice
        stopLossPrice := 0.0
        strategyClose()
    
    startOperation = notHasOpenTrade() and hasEntryShortConditional()

    if(startOperation)
        entryPrice := close
        updatedEntryPrice := entryPrice
        stopLossPrice := entryPrice + (entryPrice * stopLossPercent) / 100
        strategyOpen()
        
    strategyPercentege = (close - updatedEntryPrice) / updatedEntryPrice * 100.00
    rideDownStopLoss = hasOpenTrade() and strategyPercentege < -1

    if (rideDownStopLoss)
        stopLossPercent := stopLossPercent + strategyPercentege + 1.0
        newStopLossPrice = updatedEntryPrice + (updatedEntryPrice * stopLossPercent) / 100  
        stopLossPrice := min(stopLossPrice, newStopLossPrice)
        updatedEntryPrice := stopLossPrice
    

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //

// === DRAWING SHAPES 

entryPricePlotConditinal = entryPrice == 0.0 ? na : entryPrice
trailingStopLossPlotConditional = stopLossPrice == 0.0  ? na : stopLossPrice

plotshape(entryPricePlotConditinal, title= "Entry Price", color=color.blue, style=shape.circle, location=location.absolute, size=size.tiny)
plotshape(trailingStopLossPlotConditional, title= "Stop Loss", color=color.red, style=shape.circle, location=location.absolute, size=size.tiny)


مزید