স্টপ লস ট্র্যাকিং মুভিং এভারেজ ট্রেডিং কৌশল

লেখক:চাওঝাং, তারিখঃ ২০২৪-০২-০১ ১০ঃ৫৯ঃ০৬
ট্যাগঃ

img

সারসংক্ষেপ

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

কৌশলগত যুক্তি

এই কৌশলটি দ্রুত এবং ধীর ইএমএ লাইন ব্যবহার করে। দ্রুত ইএমএ সংবেদনশীলভাবে প্রতিক্রিয়া দেখায় যখন ধীর ইএমএ আরও স্থিতিশীল উপায়ে চলে। দুটি লাইন ক্রস করার জন্য ক্রস করার সময় গোল্ডেন ক্রস গঠিত হয়, ক্রয় সংকেত উত্পন্ন করে। মৃত ক্রস ঘটে যখন তারা নীচে ক্রস করে, বিক্রয় সংকেত প্রেরণ করে। এটি চলমান গড় কৌশলগুলির পিছনে অন্তর্নিহিত যুক্তি।

ট্রেডিংয়ের সময় স্টপ লস এবং মুনাফা লক্ষ্যমাত্রা নির্ধারণ করা হয়। স্টপ লস এবং মুনাফা লক্ষ্যমাত্রা নির্ধারণ করা হয়। স্টপ লস এবং মুনাফা লক্ষ্যমাত্রা নির্ধারণ করা হয়। স্টপ লস এবং মুনাফা লক্ষ্যমাত্রা নির্ধারণ করা হয়। স্টপ লস এবং মুনাফা লক্ষ্যমাত্রা নির্ধারণ করা হয়।

সুবিধা

  1. গুণমানের সংকেত এবং স্থিতিশীল রিটার্ন তৈরি করতে ডুয়াল ইএমএ ক্রসওভার ব্যবহার করে।
  2. ট্রেলিং স্টপ লস এবং লাভ গ্রহণ লাভ এবং ঝুঁকি কার্যকরভাবে নিয়ন্ত্রণ করে।
  3. নমনীয় ট্রেলিংয়ের জন্য শতাংশ এবং স্থির পয়েন্ট উভয়ই সমর্থন করে।
  4. দীর্ঘমেয়াদে ভাল পারফর্ম করে।

ঝুঁকি ও অপ্টিমাইজেশন

  1. খুব ঘন ঘন স্টপ লস ট্রিগারগুলি রেঞ্জিং মার্কেটে লাভজনকতাকে প্রভাবিত করতে পারে। স্টপ লস জোন প্রসারিত করুন বা ট্রেলিংয়ের সক্রিয়করণের স্তর বাড়ান।
  2. ইএমএ ক্রসওভার সংকেতগুলির বিলম্বিত প্রভাব রয়েছে এবং কিছু সুযোগ মিস করতে পারে। সংবেদনশীলতা উন্নত করতে গতি যোগ করার বিষয়টি বিবেচনা করুন।
  3. পর্যাপ্ত ব্যাকটেস্ট ডেটা অতিরিক্ত ফিটিংয়ের কারণ হতে পারে। দীর্ঘ সময়সীমা এবং আরও পণ্য জুড়ে পুঙ্খানুপুঙ্খভাবে যাচাই করুন।

সিদ্ধান্ত

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


/*backtest
start: 2023-01-31 00:00:00
end: 2024-01-31 00:00:00
period: 1d
basePeriod: 1h
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/
// © Sharad_Gaikwad
//@version=5

strategy("Traling.SL.Target", overlay=true, process_orders_on_close = true, max_labels_count = 500)
// << Parameters section {
_1 = input.bool(title = "━━━━━━━ ↓ Pivot parameters for trade ↓ ━━━━━━━", defval = false)
fast_len = input.int(title = 'Fast len', defval = 20)
slow_len = input.int(title = 'Slow len', defval = 50)
label_bg_color = input.color(title = 'BG color for ongoing trade SL/Target label', defval=color.white)
sl_target_method = input.string(title = 'Method to be used for SL/Target trailing', defval='% Based Target and SL', options = ['% Based Target and SL','Fix point Based Target and SL'])
_2 = input.bool(title = "━━━━━━━ ↓ % Based Target and SL ↓ ━━━━━━━", defval = true)
initial_profit_percent = input.float(title = 'Inital profit %', defval = 1) / 100
initial_sl_percent = input.float(title = 'Inital SL %', defval = 1) / 100
initiate_trailing_percent = input.float(title = 'Initiate trailing %', defval = 0.5, tooltip = 'Initiate trailing of target and SL after change in price in % after taking trade') / 100
trail_profit_percent = input.float(title = 'Trail profit by %', defval = 0.3) / 100
trail_sl_percent = input.float(title = 'Trail SL by %', defval = 0.3) / 100

_3 = input.bool(title = "━━━━━━━ ↓ Fix point Based Target and SL ↓ ━━━━━━━", defval = false)
initial_profit_points = input.float(title = 'Inital profit target points', defval = 100)
initial_sl_points = input.float(title = 'Inital SL points', defval = 50)
initiate_trailing_points = input.float(title = 'Initiate trailing points', defval = 60, tooltip = 'Initiate trailing of target and SL after change in price in points after taking trade')
trail_profit_points = input.float(title = 'Trail profit by points', defval = 25)
trail_sl_points = input.float(title = 'Trail SL by %', defval = 30)
// } Parameters section >>


// } << Common function {
tab = table.new(position=position.bottom_right, columns=7, rows=200,frame_color = color.yellow, frame_width = 1)
msg(int row, int col, string msg_str, clr=color.blue) =>
    table.cell(table_id=tab, column=col, row=row, text=msg_str, text_color=clr)

getVal(val) =>
    ret_val = na(val) ? 0 : val

t(val) => str.tostring(val, "0.00")

timeToString(int _t) =>
         str.tostring(dayofmonth(_t), '00') + '/' + 
         str.tostring(month(_t), '00') + '/' + 
         str.tostring(year(_t), '0000') + ' ' + 
         str.tostring(hour(_t), '00') + ':' + 
         str.tostring(minute(_t), '00') + ':' + 
         str.tostring(second(_t), '00')
    
// } Common functions>>


// Variable declarations {
percent_based = sl_target_method  == '% Based Target and SL' ? true : false
var initial_long_entry_price = float(na)
var initial_short_entry_price = float(na)
var long_target = float(na)
var long_sl = float(na)
var short_target = float(na)
var short_sl = float(na)
var long_entry_price = float(na)
var short_entry_price = float(na)
var initial_long_percent_target = float(na)
var initial_long_percent_sl = float(na)
var initial_long_point_target = float(na)
var initial_long_point_sl = float(na)
var initial_short_percent_target = float(na)
var initial_short_percent_sl = float(na)
var initial_short_point_target = float(na)
var initial_short_point_sl = float(na)
var is_long = bool(na)
var is_short = bool(na)
var trail_long_iteration = int(na)
var trail_short_iteration = int(na)

// }

// derive important variable values



// Strategy logic
fast_ema = ta.ema(close, fast_len)
slow_ema = ta.ema(close, slow_len)
plot(fast_ema, color = color.red)
plot(slow_ema, color = color.green)
go_long = ta.crossover(fast_ema, slow_ema) and strategy.position_size == 0
go_short = ta.crossunder(fast_ema, slow_ema) and strategy.position_size == 0

// barcolor(ph ? color.purple : na, offset = -lb)
// barcolor(pl ? color.yellow : na, offset = -lb)


// barcolor(ph ? color.white : na)
// barcolor(pl ? color.blue : na)

// //trailing logic for long
long_trailing_point = percent_based ? (close >= long_entry_price + (long_entry_price * initiate_trailing_percent)) :
     (close >= long_entry_price + initiate_trailing_points)

short_trailing_point = percent_based ? (close <= short_entry_price - (short_entry_price * initiate_trailing_percent)) :
     (close >= short_entry_price - initiate_trailing_points)

if(is_long and long_trailing_point)
    // initial_long_percent_target = initial_long_percent_target + (initial_long_percent_target * trail_profit_percent)
    // initial_long_percent_sl = initial_long_percent_sl - (initial_long_percent_sl * trail_sl_percent)

    // initial_long_point_target = initial_long_point_target + trail_profit_points
    // initial_long_point_sl = initial_long_point_sl - trail_sl_points
    trail_long_iteration :=  trail_long_iteration + 1
    long_target := percent_based ? (long_target + (long_target * trail_profit_percent)) : 
         (long_target + trail_profit_points)
         
    long_sl := percent_based ? (long_sl + (long_sl * trail_sl_percent)) :
         (long_sl + trail_sl_points)
    
    long_entry_price := percent_based ? (long_entry_price + (long_entry_price * initiate_trailing_percent)) :
         (long_entry_price + initiate_trailing_points)

if(is_short and short_trailing_point)
    // initial_short_percent_target = initial_short_percent_target - (initial_short_percent_target * trail_profit_percent)
    // initial_short_percent_sl = initial_short_percent_sl + (initial_short_percent_sl * trail_sl_percent)

    // initial_short_point_target = initial_short_point_target - trail_profit_points
    // initial_short_point_sl = initial_short_point_sl + trail_sl_points
    trail_short_iteration :=  trail_short_iteration + 1
    short_target := percent_based ? (short_target - (short_target * trail_profit_percent)) : 
         (short_target - trail_profit_points)
         
    short_sl := percent_based ? (short_sl - (short_sl * trail_sl_percent)) :
         (short_sl - trail_sl_points)
    
    short_entry_price := percent_based ? (short_entry_price - (short_entry_price * initiate_trailing_percent)) :
         (short_entry_price - initiate_trailing_points)
    
if(go_long)
    is_long := true
    is_short := false
    trail_long_iteration := 0
    trail_short_iteration := 0
    initial_long_entry_price := close
    long_entry_price := close
    
    initial_long_percent_target := close + (close * initial_profit_percent)
    initial_long_percent_sl := close - (close * initial_sl_percent)

    initial_long_point_target := close + initial_profit_points
    initial_long_point_sl := close - initial_sl_points
    
    long_target := percent_based ? initial_long_percent_target : initial_long_point_target
    long_sl := percent_based ? initial_long_percent_sl : initial_long_point_sl 
    
    strategy.entry(id = 'Long', direction = strategy.long)

if(go_short)
    is_long := false
    is_short := true
    trail_long_iteration := 0
    trail_short_iteration := 0
    initial_short_entry_price := close
    short_entry_price := close

    initial_short_percent_target := close - (close * initial_profit_percent)
    initial_short_percent_sl := close + (close * initial_sl_percent)

    initial_short_point_target := close - initial_profit_points
    initial_short_point_sl := close + initial_sl_points

    short_target := percent_based ? initial_short_percent_target : initial_short_point_target
    short_sl := percent_based ? initial_short_percent_sl : initial_short_point_sl 
    
    strategy.entry(id = 'Short', direction = strategy.short)

method = percent_based ? '% Based' : 'Fixed Points'
long_tooltip = 'Long @ ' + timeToString(time) + '\n' +
     'Method             : ' + method + '\n' +
     'Initial Trade Price: ' + t(initial_long_entry_price) + '\n' +
     'Inital Target      : ' + t(long_target) + '\n' + 
     'Inital SL          : ' + t(long_sl) 

short_tooltip = 'Short @ ' + timeToString(time) + '\n' +
     'Method             : ' + method + '\n' +
     'Initial Trade Price: ' + t(initial_short_entry_price) + '\n' +
     'Inital Target      : ' + t(short_target) + '\n' + 
     'Inital SL          : ' + t(short_sl)
     
     
label.new(go_long ? bar_index : na, go_long ? bar_index : na,
     style = label.style_diamond, yloc = yloc.belowbar, color = color.green, size=size.tiny, tooltip = long_tooltip)
     
label.new(go_short ? bar_index : na, go_short ? bar_index : na,
     style = label.style_diamond, yloc = yloc.abovebar, color = color.red, size=size.tiny, tooltip = short_tooltip)
 
trail_long_tooltip = 'Trail @ ' + timeToString(time) + '\n' +
     'Iteration no : ' + t(trail_long_iteration) + '\n' +
     'New Target   : ' + t(long_target) + '\n' +
     'New SL       : ' + t(long_sl)

trail_short_tooltip = 'Trail @ ' + timeToString(time) + '\n' +
     'Iteration no : ' + t(trail_short_iteration) + '\n' +
     'New Target   : ' + t(short_target) + '\n' +
     'New SL       : ' + t(short_sl) 

label.new(is_long and long_trailing_point and strategy.position_size > 0 ? bar_index : na, is_long and long_trailing_point and strategy.position_size > 0 ? bar_index : na,
      text = str.tostring(trail_long_iteration), style = label.style_circle, textcolor = color.white, yloc = yloc.belowbar, color = color.green, size=size.tiny, tooltip = trail_long_tooltip)
     
label.new(is_short and short_trailing_point and strategy.position_size < 0 ? bar_index : na, is_short and short_trailing_point and strategy.position_size < 0 ? bar_index : na,
     text = str.tostring(trail_short_iteration), style = label.style_circle, textcolor = color.white,  yloc = yloc.abovebar, color = color.red, size=size.tiny, tooltip = trail_short_tooltip)
     
strategy.close(id = 'Long', when = close <= long_sl, comment = 'SL')
strategy.close(id = 'Short', when = close >= short_sl, comment = 'SL')

strategy.close(id = 'Long', when = close >= long_target, comment = 'Target')
strategy.close(id = 'Short', when = close <= short_target, comment = 'Target')

// no_of_labels = 1
// label_q(_array, _val) =>
//     array.push(_array, _val)
//     _return = array.shift(_array)

// var target_label = float(na)
// var sl_label = float(na)
// if(strategy.position_size > 0)
//     target_label := long_target
//     sl_label := long_sl
// else if(strategy.position_size < 0)
//     target_label := short_target
//     sl_label := short_sl
// else
//     target_label := float(na)
//     sl_label := float(na)

// var label[] target_array = array.new_label(no_of_labels)
// label.delete(label_q(target_array, label.new(bar_index, target_label, "Target:"+t(target_label), style = label.style_label_down, color = label_bg_color, size=size.small, textcolor = color.green)))

// var label[] sl_array = array.new_label(no_of_labels)
// label.delete(label_q(sl_array, label.new(bar_index, sl_label, "SL:"+t(sl_label), style = label.style_label_up, color = label_bg_color, size=size.small, textcolor = color.red)))




আরো