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

مصنف:چاؤ ژانگ، تاریخ: 2023-11-28 14:56:59
ٹیگز:

img

جائزہ

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

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

حکمت عملی سٹاپ نقصان لائن کا حساب کرنے کے لئے اے ٹی آر اشارے کا استعمال کرتی ہے۔ مخصوص فارمولے یہ ہیں:

atr = multplierFactor * atr(barsBack)

longStop = hl2 - atr  
shortStop = hl2 + atr

جہاں ملٹی پلیئر فیکٹر اے ٹی آر ضرب ہے ، اور بارز بیک اے ٹی آر کی مدت ہے۔ اے ٹی آر کی قیمت جتنی زیادہ ہوگی ، مارکیٹ میں اتار چڑھاؤ اتنا ہی زیادہ ہوگا۔

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

اس کے علاوہ، رجحان کی سمت کا تعین کرنے کے لئے ایک سمت متغیر متعارف کرایا جاتا ہے:

direction = 1 
direction := nz(direction[1], direction)
direction := direction == -1 and close > shortStopPrev ? 1 : direction == 1 and close < longStopPrev ? -1 : direction 

اگر سمت 1 ہے تو یہ ایک تیزی کا رجحان ظاہر کرتا ہے۔ اگر سمت -1 ہے تو یہ ایک bearish رجحان ظاہر کرتا ہے۔

سمت متغیر کی قیمت کی بنیاد پر، مختلف رنگوں کے ساتھ سٹاپ نقصان کی لائنیں تیار کی جائیں گی:

if (direction == 1)
    valueToPlot := longStop
    colorToPlot := color.green
else  
    valueToPlot := shortStop 
    colorToPlot := color.red  

یہ واضح طور پر موجودہ رجحان کی سمت اور سٹاپ نقصان لائن کی پوزیشن کو ظاہر کرتا ہے.

پیچھے ہٹنے والے سٹاپ نقصان

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

مخصوص منطق یہ ہے:

strategyPercentege = (close - updatedEntryPrice) / updatedEntryPrice * 100.00
rideUpStopLoss = hasOpenTrade() and strategyPercentege > 1 

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

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

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

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

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

  1. ٹرینڈنگ مارکیٹس میں زیادہ منافع کو مقفل کرنا

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

  2. رینج سے منسلک مارکیٹوں میں سٹاپ نقصان کے فرق کے خطرے کو کم کرنا

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

  3. سادہ آپریشن، خودکار کرنے میں آسان

    یہ حکمت عملی مکمل طور پر پیچیدہ رجحان فیصلے کی منطق کے بغیر اشارے کے حساب پر مبنی ہے۔ اسے آسانی سے خودکار کیا جاسکتا ہے۔

  4. مختلف مصنوعات کے لئے موزوں حسب ضرورت پیرامیٹرز

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

خطرے کا تجزیہ

اگرچہ اس حکمت عملی کے بہت سے فوائد ہیں، لیکن مندرجہ ذیل خطرات کو نوٹ کیا جانا چاہئے:

  1. رجحان کے الٹ پوائنٹس کا تعین کرنے کے قابل نہیں، اعلی خریدنے اور کم فروخت کرنے کا خطرہ ہے

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

  2. غلط پیرامیٹر کی ترتیبات نقصانات کو بڑھا سکتے ہیں

    اگر اے ٹی آر پیریڈ پیرامیٹر کو بہت کم مقرر کیا جائے تو ، اسٹاپ نقصان کی لائن بہت حساس ہوگی اور اکثر مارکیٹس کے اتار چڑھاؤ سے متحرک ہوسکتی ہے۔

  3. نیچے کی ماہی گیری سے روکنے کا خطرہ

    یہ حکمت عملی اہم نکات کو اسٹاپ نقصان کی حمایت کے طور پر نہیں سمجھتی ہے۔ لہذا اسے قلیل مدتی واپسی کے دوران بھی مارکیٹ سے باہر پھینک دیا جاسکتا ہے۔

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

  1. رجحان کی تبدیلی کی پیش گوئی کرنے کے لئے رجحان فلٹرنگ اشارے شامل کریں

  2. بہترین پیرامیٹر مجموعہ کا انتخاب کرنے کے لئے پیرامیٹر کی اصلاح کی جانچ

  3. بعض معاونت کی سطحوں کے قریب سٹاپ نقصان کی حد کو بڑھانا

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

اس حکمت عملی کو مزید بہتر بنانے کی گنجائش ہے:

  1. شمعدان پیٹرن کی شناخت شامل کریں

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

  2. ٹریننگ پیرامیٹرز کی متحرک اصلاح

    پیرامیٹرز جیسے اے ٹی آر کی مدت اور ضرب کار کو متحرک طور پر تبدیل کرنے کی اجازت دیں۔ بڑی حد تک اتار چڑھاؤ والی منڈیوں میں طویل اے ٹی آر کی مدت اور وسیع اسٹاپ نقصان کی حد کا استعمال کریں۔

  3. مشین لرننگ ماڈلز کو شامل کریں

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

خلاصہ

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


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

//@version=4
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 
//  -----------------------------------------------------------------------------
//  Copyright 2019 Mauricio Pimenta | exit490
//  SuperTrend with 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:     5-Aug-2019
//
//  Description
//  ===========
//  SuperTrend is a moving stop and reversal line based on the volatility (ATR).
//  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.
//  The strategy will close operation when the line based on the volatility will crossed
//
//  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.
//  ATR PERIOD - To select number of bars back to execute calculation
//  ATR MULTPLIER - To add a multplier factor on volatility
//  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 multplierFactoriplierFactoriple 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(title = "SUPERTREND ATR WITH TRAILING STOP LOSS",
         shorttitle = "SUPERTREND ATR WITH TSL",
         overlay = true,
         precision = 8,
         calc_on_order_fills = true,
         calc_on_every_tick = true,
         backtest_fill_limits_assumption = 0,
         default_qty_type = strategy.percent_of_equity,
         default_qty_value = 100,
         initial_capital = 1000,
         currency = currency.USD,
         linktoseries = true)

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

// === 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 = 2019, 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")

// === INPUT TO SELECT BARS BACK
barsBack = input(title="ATR Period", defval=1)

// === INPUT TO SELECT MULTPLIER FACTOR 
multplierFactor = input(title="ATR multplierFactoriplier", step=0.1, defval=3.0)

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

// LOGIC TO FIND DIRECTION WHEN THERE IS TREND CHANGE ACCORDING VOLATILITY
atr = multplierFactor * atr(barsBack)

longStop = hl2 - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop

shortStop = hl2 + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop

direction = 1
direction := nz(direction[1], direction)
direction := direction == -1 and close > shortStopPrev ? 1 : direction == 1 and close < longStopPrev ? -1 : direction

longColor = color.blue
shortColor = color.blue

var valueToPlot = 0.0
var colorToPlot = color.white

if (direction == 1)
    valueToPlot := longStop
    colorToPlot := color.green
else
    valueToPlot := shortStop
    colorToPlot := color.red

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //
//
// === GLOBAL VARIABLES AND FUNCTIONS TO STORE IMPORTANT CONDITIONALS TO TRAILING STOP
hasEntryLongConditional() => direction == 1
hasCloseLongConditional() => direction == -1

hasEntryShortConditional() => direction == -1
hasCloseShortConditional() => direction == 1

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)

plot(valueToPlot == 0.0 ? na : valueToPlot, title="BuyLine", linewidth=2, color=colorToPlot)
plotshape(direction == 1 and direction[1] == -1 ? longStop : na, title="Buy", style=shape.labelup, location=location.absolute, size=size.normal, text="Buy", transp=0, textcolor = color.white, color=color.green, transp=0)
plotshape(direction == -1 and direction[1] == 1 ? shortStop : na, title="Sell", style=shape.labeldown, location=location.absolute, size=size.normal, text="Sell", transp=0, textcolor = color.white, color=color.red, transp=0)

alertcondition(direction == 1 and direction[1] == -1 ? longStop : na, title="Buy", message="Buy!")
alertcondition(direction == -1 and direction[1] == 1 ? shortStop : na, title="Sell", message="Sell!")

مزید