লফট স্টপ কৌশল

লেখক:চাওঝাং, তারিখ: ২০২৩-১০-০৭ 16:11:45
ট্যাগঃ

সারসংক্ষেপ

এই কৌশলটি মূল্য ট্র্যাক করার জন্য একটি কালমান ফিল্টার ব্যবহার করে এবং গতিশীলভাবে স্টপ লস লাইন দিয়ে স্টপ লস পয়েন্ট সামঞ্জস্য করে একটি স্লাইডিং স্টপ লস অর্জন করে।

নীতি

এই কৌশলটি রিয়েল টাইমে দাম ট্র্যাক করার জন্য একটি কালমান ফিল্টার ব্যবহার করে। কালমান ফিল্টারে দুটি সমীকরণ রয়েছেঃ

পূর্বাভাস সমীকরণঃ

মসৃণ = kf[1] + dk * sqrt(লাভ / 10000 * 2)

আপডেট সমীকরণঃ

kf = মসৃণ + ভেলো

যেখানে dk হল পূর্বাভাসের ত্রুটি, লাভ হল কালমান লাভ যা ট্র্যাকিং সংবেদনশীলতা নির্ধারণ করে।

উপরন্তু, কৌশলটি মুনাফা লক করার জন্য একটি স্লাইডিং স্টপ লস লাইন ব্যবহার করে। প্রাথমিক স্টপ লস দূরত্বটি স্টপ লস শতাংশ সেটিং, যেমন 2%।

যখন লং হয়, যদি মূল্য বৃদ্ধি পায়, স্টপ লস লাইনটিও ক্রমাগত ক্যালমান লাইনের কাছাকাছি চলে যায়, যেমন 0.5% এর মতো ডাউনস্টেপের স্টেপ আকারের সাথে। যদি দাম স্টপ লসের কাছে পড়ে তবে অবস্থানটি পুনরায় খুলুন এবং প্রাথমিক স্টপ লস দূরত্ব সেট করুন।

সংক্ষিপ্ত অনুরূপ।

সুতরাং, কৌশলটি ধীরে ধীরে প্রবণতা অনুসারে মুনাফা অর্জন করতে পারে, ভাল ঝুঁকি ব্যবস্থাপনা সহ।

সুবিধা

  1. দ্রুত সাড়া দিয়ে রিয়েল টাইমে দাম ট্র্যাক করতে কালমান ফিল্টার ব্যবহার করুন।

  2. স্লাইডিং স্টপ লস লাইনের সাহায্যে লাভকে লক করুন, ভাল ঝুঁকি ব্যবস্থাপনা অর্জন করুন। কাস্টমাইজযোগ্য স্টপ লস দূরত্ব।

  3. নমনীয়ভাবে লং/শর্ট বা শুধুমাত্র লং/শর্ট নির্বাচন করুন।

  4. ট্রেন্ডের ভিত্তিতে সক্রিয় বা সংরক্ষণমূলকভাবে স্টপ লস।

  5. প্রয়োজনে লাভ এবং স্টপ লস নিতে নমনীয়ভাবে সেট করুন।

ঝুঁকি

  1. কালমান ফিল্টারের ভুল প্যারামিটার সেটিং অস্থির ট্র্যাকিংয়ের কারণ হতে পারে।

  2. স্লিপিং অকাল স্টপ লস পয়েন্ট ট্রিগার করতে পারে। যথাযথভাবে স্টপ লস দূরত্ব প্রসারিত করুন।

  3. স্লাইডিং স্টপ লস শক্তিশালী ট্রেন্ডিং মার্কেটের জন্য উপযুক্ত নয়, ট্রেন্ড অনুসরণ করা উচিত।

  4. স্টপ লস প্রায়শই রেঞ্জিং মার্কেটে ট্রিগার হতে পারে। স্টপ লস দূরত্ব প্রসারিত করুন বা স্লাইডিং স্টপ লস ব্যবহার করবেন না।

অপ্টিমাইজেশন

  1. এন্ট্রি টাইমিং অপ্টিমাইজ করার জন্য আরও সূচক অন্তর্ভুক্ত করুন।

  2. বাজারের অস্থিরতার উপর ভিত্তি করে স্টপ লস লাইনের গতির ধাপ সামঞ্জস্য করুন।

  3. মেশিন লার্নিং ব্যবহার করে অপ্টিম স্টপ লস প্যারামিটার ট্রেনিং করা।

  4. ডায়নামিকভাবে পজিশনের আকার সামঞ্জস্য করার জন্য আরো ঝুঁকি সূচক অন্তর্ভুক্ত করা।

সিদ্ধান্ত

লফ্ট স্টপ কৌশলটি মূল্যের পরিবর্তনগুলি ট্র্যাক করতে এবং ঝুঁকি নিয়ন্ত্রণের সময় লাভজনকতা নিশ্চিত করে একটি স্লাইডিং স্টপ লস লাইনের সাহায্যে মুনাফা লক করার জন্য একটি কালমান ফিল্টার ব্যবহার করে। এটি একটি নির্ভরযোগ্য এবং সহজেই অনুকূলিত কৌশল। প্রবণতা বিচার এবং গতিশীল অবস্থানের আকারের সাথে এটি একত্রিত করে আরও ভাল কৌশল কর্মক্ষমতা অর্জন করতে পারে।


/*backtest
start: 2023-09-06 00:00:00
end: 2023-10-06 00:00:00
period: 2h
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/
// © BigCoinHunter

//@version=5
// strategy(title='Loft Strategy V1', overlay=true, 
//      pyramiding=0, default_qty_type=strategy.fixed, 
//      default_qty_value=100, initial_capital=100000, 
//      currency=currency.USD, commission_value=0.05, 
//      commission_type=strategy.commission.percent, 
//      process_orders_on_close=true)

//-------------- fetch user inputs ------------------
gain = input.float(title="Kalman Gain:", defval=1.0, minval=1.0, maxval=5000.0, step=100.0)
src = input(defval=close, title='Source:')

stopPercentMax = input.float(title='Beginning Approach(%):', defval=2.0, minval=0.1, maxval=30.0, step=0.1)
stopPercentMin = input.float(title='Final Approach(%):    ', defval=0.5, minval=0.1, maxval=30.0, step=0.1)
downStep = input.float(title='Approach Decrease Step:', defval=0.005, minval=0.0, maxval = 5, step=0.005)

tp = input.float(title="Take Profit:", defval=1.5, minval=0.0, maxval=100.0, step=0.1) * 0.01
sl = input.float(title="Stop Loss:  ", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01

longEntry = input.bool(defval=true, title= 'Long Entry', inline="11")
shortEntry = input.bool(defval=true, title='Short Entry', inline="11")

//---------- backtest range setup ------------
fromDay   = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear  = input.int(defval = 2021, title = "From Year", minval = 2010)
toDay     = input.int(defval = 30, title = "To Day", minval = 1, maxval = 31)
toMonth   = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)
toYear    = input.int(defval = 2022, title = "To Year", minval = 2010)


//------------ time interval setup -----------
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)  // backtest start window
finish    = timestamp(toYear, toMonth, toDay, 23, 59)        // backtest finish window
window()  => true // create function "within window of time"

//------- define the global variables ------
enterLongComment = "ENTER LONG"
exitLongComment = "EXIT LONG"

enterShortComment = "ENTER SHORT"
exitShortComment = "EXIT SHORT"

longTPSL = "Long TP/SL"
longTP = "Long TP"
longSL = "Long SL"
shortTPSL = "Short TP/SL"
shortTP = "Short TP"
shortSL = "Short SL"

var bool long = true
var bool stoppedOutLong = false
var bool stoppedOutShort = false
var float kf = 0.0
var float velo = 0.0

//------ kalman filter calculation --------
dk = src - nz(kf[1], src)
smooth = nz(kf[1], src) + dk * math.sqrt(gain / 10000 * 2)
velo := nz(velo[1], 0) + gain / 10000 * dk
kf := smooth + velo

//--------- calculate the loft stopLoss line ---------
var stopPercent = stopPercentMax
var stopLoss = kf - kf * (stopPercent /100)

if long == true
    stopLoss := kf - (kf * (stopPercent / 100))
    
    if long[1] == true and stopLoss <= stopLoss[1]
        stopLoss := stopLoss[1]
    else if (long[1] == true)
        stopPercent := stopPercent - downStep
        if(stopPercent < stopPercentMin)
            stopPercent := stopPercentMin
    
    if(kf < stopLoss)
        long := false
        stopPercent := stopPercentMax
        stopLoss := kf + (kf * (stopPercent / 100))
        
else
    stopLoss := kf + (kf * (stopPercent / 100))
    
    if long[1] == false and stopLoss >= stopLoss[1]
        stopLoss := stopLoss[1]
    else if(long[1] == false)
        stopPercent := stopPercent - downStep
        if(stopPercent < stopPercentMin)
            stopPercent := stopPercentMin
            
    if(kf > stopLoss)
        long := true
        stopPercent := stopPercentMax
        stopLoss := kf - (kf * (stopPercent / 100))
        
//--------- calculate the input/output points -----------
longProfitPrice  = strategy.position_avg_price * (1 + tp)     // tp -> take profit percentage
longStopPrice = strategy.position_avg_price * (1 - sl)        // sl -> stop loss percentage

shortProfitPrice  = strategy.position_avg_price * (1 - tp)
shortStopPrice = strategy.position_avg_price * (1 + sl)

//------------------- determine buy and sell points ---------------------
buySignall = window() and long  and (not stoppedOutLong)
sellSignall = window() and (not long)  and (not stoppedOutShort)

//---------- execute the strategy -----------------
if(longEntry and shortEntry)
    if long 
        strategy.entry("LONG", strategy.long, when = buySignall, comment = enterLongComment)
        stoppedOutLong := true
        stoppedOutShort := false
    else 
        strategy.entry("SHORT", strategy.short, when = sellSignall, comment = enterShortComment)
        stoppedOutLong  := false
        stoppedOutShort := true

else if(longEntry)
    strategy.entry("LONG", strategy.long,  when = buySignall, comment = enterLongComment)
    strategy.close("LONG", when = sellSignall, comment = exitLongComment)
    if long 
        stoppedOutLong := true
    else
        stoppedOutLong  := false

else if(shortEntry)
    strategy.entry("SHORT", strategy.short, when = sellSignall, comment = enterShortComment)
    strategy.close("SHORT", when = buySignall, comment = exitShortComment)
    if not long
        stoppedOutShort := true
    else
        stoppedOutShort := false
    

//----------------- take profit and stop loss -----------------
if(tp>0.0 and sl>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG", limit=longProfitPrice, stop=longStopPrice, comment = longTPSL)

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT", limit=shortProfitPrice, stop=shortStopPrice, comment = shortTPSL)

else if(tp>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG", limit=longProfitPrice, comment = longTP)

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT", limit=shortProfitPrice, comment = shortTP)
        
else if(sl>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG",  stop=longStopPrice, comment = longSL)

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT",  stop=shortStopPrice, comment = shortSL)
        
//------------- plot charts ---------------------
lineColor1 = long ? color.green : color.red
lineColor2 = long ? color.aqua : color.fuchsia

kalmanLine = plot(kf, color=lineColor1, linewidth=3, title = "Kalman Filter")
stopLine = plot(stopLoss, color=lineColor2, linewidth=2, title = "Stop Loss Line")






আরো