ইএমএ-এর গড় বিপরীতমুখী ট্রেডিং কৌশল

লেখক:চাওঝাং, তারিখ: ২০২৩-১০-২৬ 15:33:50
ট্যাগঃ

img

সারসংক্ষেপ

ইএমএ-এর মধ্যম রিভার্সন ট্রেডিং কৌশলটি মূল্যের ইএমএ থেকে বিচ্যুতির মাত্রার উপর ভিত্তি করে পজিশন খোলার এবং বন্ধ করে দেয়। এটি পজিশন পরিচালনার জন্য প্রবেশ সংকেত এবং ট্রেলিং স্টপ লস হিসাবে মূল্য এবং ইএমএর মধ্যে শতাংশ পার্থক্য ব্যবহার করে।

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

এই কৌশলটি ইএমএকে বেঞ্চমার্ক হিসাবে ব্যবহার করে এবং বর্তমান মূল্য এবং ইএমএর মধ্যে শতাংশ পার্থক্য গণনা করে। যখন দাম ইএমএ থেকে যথেষ্ট দূরে থাকে (ডিফল্ট 9%), এবং যখন দাম ইএমএ (ডিফল্ট 1%) এর যথেষ্ট কাছাকাছি আসে তখন অবস্থান বন্ধ করে দেয়। পজিশন খোলার পরে, এটি বৃদ্ধি পাওয়ার সাথে সাথে মুনাফা লক করতে ট্রেলিং স্টপ লস ব্যবহার করে।

বিশেষ করে, কৌশল নিম্নলিখিত উপাদানগুলি অন্তর্ভুক্ত করেঃ

  1. ইএমএ গণনা করুন। সময়কাল (ডিফল্ট 200), উৎস (বন্ধ মূল্য) এবং পদ্ধতি (ইএমএ, এসএমএ, আরএমএ, ডাব্লুএমএ) কনফিগারযোগ্য।

  2. বর্তমান মূল্য এবং EMA এর মধ্যে শতাংশ পার্থক্য গণনা করুন। ইতিবাচক / নেতিবাচক চিহ্নের দিকে মনোযোগ দিন।

  3. ডিফল্ট লং এন্ট্রি ৯% এবং শর্ট এন্ট্রি ৯%।

  4. সমর্থন সিঁড়ি এন্ট্রি. ধাপ সংখ্যা এবং ধাপ প্রতি শতাংশ কনফিগার করা যেতে পারে।

  5. এন্ট্রি করার পর ট্রেইলিং স্টপ লস ব্যবহার করুন। ট্রেইলিং শুরু করার জন্য থ্রেশহোল্ড (ডিফল্ট 1% মুনাফা) এবং ট্রেইলিং শতাংশ (ডিফল্ট 1%) কনফিগারযোগ্য।

  6. ডিফারেনশিয়াল থ্রেশহোল্ডের উপর ভিত্তি করে পজিশন বন্ধ করুন। লং এবং শর্ট উভয়ের জন্য ডিফল্ট প্রস্থান 1%।

  7. যখন দাম EMA-তে ফিরে আসে তখন অর্ডার বাতিল করুন।

  8. কনফিগারযোগ্য স্টপ লস শতাংশ।

  9. ব্যাকটেস্টিং এবং লাইভ ট্রেডিং সমর্থন করুন।

সুবিধা বিশ্লেষণ

এই কৌশলটির সুবিধাঃ

  1. ইএমএ বিচ্যুতির উপর ভিত্তি করে ট্রেড ট্রেন্ডে গড় বিপরীত ধারণা ব্যবহার করুন। ট্রেন্ড ট্রেডিং তত্ত্বের সাথে সামঞ্জস্যপূর্ণ।

  2. এন্ট্রি, স্টপ লস, এক্সট্রিপ প্যারামিটারগুলি বিভিন্ন বাজারের অবস্থার সাথে মানিয়ে নিতে কনফিগারযোগ্য।

  3. সিঁড়ি প্রবেশ ধীরে ধীরে অবস্থান নির্মাণ এবং খরচ হ্রাস করতে পারবেন।

  4. ট্রেলিং স্টপ লাভের ক্ষেত্রে লক করে এবং ঝুঁকি পরিচালনা করে।

  5. ইএমএ প্যারামিটার বা প্রবেশ/প্রস্থান প্রান্তিক সীমা সামঞ্জস্য করে অত্যন্ত অনুকূলিত করা যায়।

  6. পাইন স্ক্রিপ্ট ট্রেডিং ভিউতে সহজেই ব্যবহারের অনুমতি দেয়।

  7. পর্যবেক্ষণ এবং বিশ্লেষণের জন্য স্বজ্ঞাত চার্ট।

ঝুঁকি বিশ্লেষণ

এই কৌশলের ঝুঁকি:

  1. ব্যাকটেস্ট ওভারফিটিং ঝুঁকি। প্যারামিটার অপ্টিমাইজেশান ব্যাকটেস্ট ডেটা ওভারফিট করতে পারে এবং লাইভ ট্রেডিংয়ে নিম্ন ফল করতে পারে।

  2. ইএমএ ব্যর্থতার ঝুঁকি। দাম দীর্ঘ সময়ের জন্য ইএমএ থেকে বিচ্যুত হতে পারে।

  3. স্টপ লস ঝুঁকির উপর চলে যায়। স্টপ লস অস্থির গতি দ্বারা প্রবেশ করতে পারে।

  4. উচ্চ ট্রেডিং ফ্রিকোয়েন্সি কমিশন খরচ বৃদ্ধি করে।

  5. এর জন্য আরও বেশি সময় লাগবে, হঠাৎ ঘটতে পারে।

ঝুঁকি ব্যবস্থাপনাঃ

  1. অপ্টিমাইজেশান এবং মাল্টি মার্কেট ভেরিফিকেশনের মাধ্যমে শক্তিশালী প্যারামিটার নির্বাচন।

  2. যুক্তিসঙ্গত EMA সময়কাল, খুব কম বা খুব দীর্ঘ নয়।

  3. অকাল বন্ধ হওয়া এড়ানোর জন্য আরও বিস্তৃত স্টপ লস বাফার।

  4. বাণিজ্য ঘনত্ব হ্রাস করার জন্য কম আক্রমণাত্মক প্রবেশের নিয়ম।

  5. ভলিউম, বোলিংজার ব্যান্ড, আরএসআই এর মতো অতিরিক্ত সূচক অন্তর্ভুক্ত করুন।

অপ্টিমাইজেশান নির্দেশাবলী

কৌশলটি নিম্নলিখিত দিকগুলিতে উন্নত করা যেতে পারেঃ

  1. ভলিউম, বোলিংজার ব্যান্ড, আরএসআই এর মতো ফিল্টার যুক্ত করুন যাতে মিথ্যা সংকেত হ্রাস পায়।

  2. উচ্চতর সম্ভাব্যতার ট্রেডিং ট্রেন্ডের জন্য ডুয়াল ইএমএ যোগ করুন।

  3. ঝুঁকি আরও সীমিত করার জন্য অভিযোজনশীল স্টপ, চ্যান্ডেলিয়ার এক্সটেনশানগুলির সাথে স্টপ লসকে উন্নত করুন।

  4. আরও ভাল প্যারামিটার সেট খুঁজে পেতে অটো প্যারামিটার অপ্টিমাইজেশন যোগ করুন।

  5. ইএমএ বিচ্যুতির সম্ভাবনার জন্য মেশিন লার্নিং অন্তর্ভুক্ত করুন।

  6. গ্যাপের সুবিধা নেওয়ার জন্য ইনট্রা ডে বা ওভার নাইট পজিশন বিবেচনা করুন।

  7. বৃহত্তর ক্ষমতা জন্য স্টক মহাবিশ্ব নির্বাচন একীভূত করুন।

সিদ্ধান্ত

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


/*backtest
start: 2022-10-19 00:00:00
end: 2023-10-25 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/
// © jordanfray

//@version=5
strategy(title="EMA Mean Reversion Strategy", overlay=true, max_bars_back=5000, default_qty_type=strategy.percent_of_equity, default_qty_value=100,initial_capital=100000, commission_type=strategy.commission.percent, commission_value=0.05, backtest_fill_limits_assumption=2)


// Indenting Classs
indent_1 = " "
indent_2 = "  "
indent_3 = "   "
indent_4 = "    "


// Tooltips
longEntryToolTip = "When the percentage that the price is away from the selected EMA reaches this point, a long postion will open."
shortEntryToolTip = "When the percentage that the price is away from the selected EMA reaches this point, a short postion will open."
closeEntryToolTip = "When the percentage that the price is away from the selected EMA reaches this point, open postion will close."
ladderInToolTip = "Enable this to use the laddering settings below."
cancelEntryToolTip = "When the percentage that the price is away from the selected EMA reaches this point, any unfilled entries will be canceled."

// Group Titles
group_one_title = "EMA Settings"
group_two_title = "Entry Settings"


// Colors
blue = color.new(#00A5FF,0)
lightBlue = color.new(#00A5FF,90)
green = color.new(#2DBD85,0)
gray_80 =  color.new(#7F7F7F,80)
gray_60 =  color.new(#7F7F7F,60)
gray_40 =  color.new(#7F7F7F,40)
white = color.new(#ffffff,0)
red = color.new(#E02A4A,0)
transparent = color.new(#000000,100)


// Strategy Settings
EMAtimeframe = input.timeframe(defval="", title="Timeframe", group=group_one_title)
EMAlength = input.int(defval=200, minval=1, title="Length", group=group_one_title)
EMAtype = input.string(defval="EMA", options = ["EMA", "SMA", "RMA", "WMA"], title="Type", group=group_one_title)
EMAsource = input.source(defval=close, title="Source", group=group_one_title)

openLongEntryAbove = input.float(defval=9, title="Long Position Entry Trigger", tooltip=longEntryToolTip, group=group_two_title)
openEntryEntryAbove = input.float(defval=9, title="Short Position Entry Trigger", tooltip=shortEntryToolTip, group=group_two_title)
closeEntryBelow = input.float(defval=1.0, title="Close Position Trigger", tooltip=closeEntryToolTip, group=group_two_title)
cancelEntryBelow = input.float(defval=4, title="Cancel Unfilled Entries Trigger", tooltip=cancelEntryToolTip, group=group_two_title)

enableLaddering = input.bool(defval=true, title="Ladder Into Positions", tooltip=ladderInToolTip, group=group_two_title)
ladderRungs = input.int(defval=4, minval=2, maxval=4, step=1, title=indent_4+"Ladder Rungs", group=group_two_title)
ladderStep = input.float(defval=.5, title=indent_4+"Ladder Step (%)", step=.1, group=group_two_title)/100
stop_loss_val = input.float(defval=4.0, title="Stop Loss (%)", step=0.1, group=group_two_title)/100
start_trailing_after = input.float(defval=1, title="Start Trailing After (%)", step=0.1, group=group_two_title)/100
trail_behind = input.float(defval=1, title="Trail Behind (%)", step=0.1, group=group_two_title)/100

// Calculate trailing stop values
long_start_trailing_val = strategy.position_avg_price + (strategy.position_avg_price * start_trailing_after)
long_trail_behind_val = close - (strategy.position_avg_price * trail_behind)
long_stop_loss = strategy.position_avg_price * (1.0 - stop_loss_val)
short_start_trailing_val = strategy.position_avg_price - (strategy.position_avg_price * start_trailing_after)
short_trail_behind_val = close + (strategy.position_avg_price * trail_behind)
short_stop_loss = strategy.position_avg_price * (1 + stop_loss_val)


// Calulate EMA
EMA = switch EMAtype
    "EMA" => ta.ema(EMAsource, EMAlength)
    "SMA" => ta.sma(EMAsource, EMAlength)
    "RMA" => ta.rma(EMAsource, EMAlength)
    "WMA" => ta.wma(EMAsource, EMAlength)
    => na
EMA_ = EMAtimeframe == timeframe.period ? EMA : request.security(syminfo.ticker, EMAtimeframe, EMA[1], lookahead = barmerge.lookahead_on)
plot(EMA_, title="EMA", linewidth=2, color=blue, editable=true)

EMA_cloud_upper_band_val = EMA_ + (EMA_ * openLongEntryAbove/100)
EMA_cloud_lower_band_val = EMA_ - (EMA_ * openLongEntryAbove/100)
EMA_cloud_upper_band = plot(EMA_cloud_upper_band_val, title="EMA Cloud Upper Band", color=blue)
EMA_cloud_lower_band = plot(EMA_cloud_lower_band_val, title="EMA Cloud Upper Band", color=blue)
fill(EMA_cloud_upper_band, EMA_cloud_lower_band, editable=false, color=lightBlue)

distance_from_EMA = ((close - EMA_)/close)*100
if distance_from_EMA < 0
    distance_from_EMA := distance_from_EMA * -1

// Calulate Ladder Entries
long_ladder_1_limit_price = close - (close * 1 * ladderStep)
long_ladder_2_limit_price = close - (close * 2 * ladderStep)
long_ladder_3_limit_price = close - (close * 3 * ladderStep)
long_ladder_4_limit_price = close - (close * 4 * ladderStep)

short_ladder_1_limit_price = close + (close * 1 * ladderStep)
short_ladder_2_limit_price = close + (close * 2 * ladderStep)
short_ladder_3_limit_price = close + (close * 3 * ladderStep)
short_ladder_4_limit_price = close + (close * 4 * ladderStep)

var position_qty = strategy.equity/close
if enableLaddering
    position_qty := (strategy.equity/close) / ladderRungs
else
    position_qty := strategy.equity/close
    
plot(position_qty, color=white)
//plot(strategy.equity, color=green)

// Entry Conditions
currently_in_a_postion = strategy.position_size != 0
currently_in_a_long_postion = strategy.position_size > 0
currently_in_a_short_postion = strategy.position_size < 0
average_price = strategy.position_avg_price

bars_since_entry = currently_in_a_postion ? bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades - 1) + 1 : 5
long_run_up = ta.highest(high, bar_index == 0 ? 5000: bars_since_entry)
long_run_up_line = plot(long_run_up, style=plot.style_stepline, editable=false, color=currently_in_a_long_postion ? green : transparent)
start_trailing_long_entry = currently_in_a_long_postion and long_run_up > long_start_trailing_val
long_trailing_stop = start_trailing_long_entry ? long_run_up - (long_run_up * trail_behind) : long_stop_loss
long_trailing_stop_line = plot(long_trailing_stop, style=plot.style_stepline, editable=false, color=currently_in_a_long_postion ? long_trailing_stop > strategy.position_avg_price ? green : red : transparent)

short_run_up = ta.lowest(low, bar_index == 0 ? 5000: bars_since_entry)
short_run_up_line = plot(short_run_up, style=plot.style_stepline, editable=false, color=currently_in_a_short_postion ? green : transparent)
start_trailing_short_entry = currently_in_a_short_postion and short_run_up < short_start_trailing_val
short_trailing_stop = start_trailing_short_entry ? short_run_up + (short_run_up * trail_behind) : short_stop_loss
short_trailing_stop_line = plot(short_trailing_stop, style=plot.style_stepline, editable=false, color=currently_in_a_short_postion ? short_trailing_stop < strategy.position_avg_price ? green : red : transparent)

long_conditions_met = distance_from_EMA > openLongEntryAbove and close < EMA_ and not currently_in_a_postion
short_conditions_met = distance_from_EMA > openEntryEntryAbove and close > EMA_ and not currently_in_a_postion
close_long_entries = distance_from_EMA <= closeEntryBelow or close <= long_trailing_stop
close_short_entries = distance_from_EMA <= closeEntryBelow or close >= short_trailing_stop
cancel_entries = distance_from_EMA <= cancelEntryBelow

plotshape(long_conditions_met ? close : na, style=shape.diamond, title="Long Conditions Met" )
plotshape(short_conditions_met ? close : na, style=shape.diamond, title="Short Conditions Met" )
plot(average_price,style=plot.style_stepline, editable=false, color=currently_in_a_postion ? blue : transparent)

// Long Entry
if enableLaddering
    if ladderRungs == 2
        strategy.entry(id="Long Ladder 1", direction=strategy.long, qty=position_qty, limit=long_ladder_1_limit_price, when=long_conditions_met)
        strategy.entry(id="Long Ladder 2", direction=strategy.long, qty=position_qty, limit=long_ladder_2_limit_price, when=long_conditions_met)
    else if ladderRungs == 3
        strategy.entry(id="Long Ladder 1", direction=strategy.long, qty=position_qty, limit=long_ladder_1_limit_price, when=long_conditions_met)
        strategy.entry(id="Long Ladder 2", direction=strategy.long, qty=position_qty, limit=long_ladder_2_limit_price, when=long_conditions_met)
        strategy.entry(id="Long Ladder 3", direction=strategy.long, qty=position_qty, limit=long_ladder_3_limit_price, when=long_conditions_met)
    else if ladderRungs == 4
        strategy.entry(id="Long Ladder 1", direction=strategy.long, qty=position_qty, limit=long_ladder_1_limit_price, when=long_conditions_met)
        strategy.entry(id="Long Ladder 2", direction=strategy.long, qty=position_qty, limit=long_ladder_2_limit_price, when=long_conditions_met)
        strategy.entry(id="Long Ladder 3", direction=strategy.long, qty=position_qty, limit=long_ladder_3_limit_price, when=long_conditions_met)
        strategy.entry(id="Long Ladder 4", direction=strategy.long, qty=position_qty, limit=long_ladder_4_limit_price, when=long_conditions_met)
    
    strategy.exit(id="Close Long Ladder 1", from_entry="Long Ladder 1", stop=long_trailing_stop, limit=long_trailing_stop, when=close_long_entries)
    strategy.exit(id="Close Long Ladder 2", from_entry="Long Ladder 2", stop=long_trailing_stop, limit=long_trailing_stop, when=close_long_entries)
    strategy.exit(id="Close Long Ladder 3", from_entry="Long Ladder 3", stop=long_trailing_stop, limit=long_trailing_stop, when=close_long_entries)
    strategy.exit(id="Close Long Ladder 4", from_entry="Long Ladder 4", stop=long_trailing_stop, limit=long_trailing_stop, when=close_long_entries)
    
    strategy.cancel(id="Long Ladder 1", when=cancel_entries)
    strategy.cancel(id="Long Ladder 2", when=cancel_entries)
    strategy.cancel(id="Long Ladder 3", when=cancel_entries)
    strategy.cancel(id="Long Ladder 4", when=cancel_entries)
else
    strategy.entry(id="Long", direction=strategy.long, qty=100, when=long_conditions_met)
    strategy.exit(id="Close Long", from_entry="Long", stop=long_stop_loss, limit=EMA_, when=close_long_entries)
    strategy.cancel(id="Long", when=cancel_entries)

// Short Entry
if enableLaddering
    if ladderRungs == 2
        strategy.entry(id="Short Ladder 1", direction=strategy.short, qty=position_qty, limit=short_ladder_1_limit_price, when=short_conditions_met)
        strategy.entry(id="Short Ladder 2", direction=strategy.short, qty=position_qty, limit=short_ladder_2_limit_price, when=short_conditions_met)
    else if ladderRungs == 3
        strategy.entry(id="Short Ladder 1", direction=strategy.short, qty=position_qty, limit=short_ladder_1_limit_price, when=short_conditions_met)
        strategy.entry(id="Short Ladder 2", direction=strategy.short, qty=position_qty, limit=short_ladder_2_limit_price, when=short_conditions_met)
        strategy.entry(id="Short Ladder 3", direction=strategy.short, qty=position_qty, limit=short_ladder_3_limit_price, when=short_conditions_met)
    else if ladderRungs == 4
        strategy.entry(id="Short Ladder 1", direction=strategy.short, qty=position_qty, limit=short_ladder_1_limit_price, when=short_conditions_met)
        strategy.entry(id="Short Ladder 2", direction=strategy.short, qty=position_qty, limit=short_ladder_2_limit_price, when=short_conditions_met)
        strategy.entry(id="Short Ladder 3", direction=strategy.short, qty=position_qty, limit=short_ladder_3_limit_price, when=short_conditions_met)
        strategy.entry(id="Short Ladder 4", direction=strategy.short, qty=position_qty, limit=short_ladder_4_limit_price, when=short_conditions_met)
    
    strategy.exit(id="Close Short Ladder 1", from_entry="Short Ladder 1", stop=short_trailing_stop, limit=EMA_, when=close_short_entries)
    strategy.exit(id="Close Short Ladder 2", from_entry="Short Ladder 2", stop=short_trailing_stop, limit=EMA_, when=close_short_entries)
    strategy.exit(id="Close Short Ladder 3", from_entry="Short Ladder 3", stop=short_trailing_stop, limit=EMA_, when=close_short_entries)
    strategy.exit(id="Close Short Ladder 4", from_entry="Short Ladder 4", stop=short_trailing_stop, limit=EMA_, when=close_short_entries)
    
    strategy.cancel(id="Short Ladder 1", when=cancel_entries)
    strategy.cancel(id="Short Ladder 2", when=cancel_entries)
    strategy.cancel(id="Short Ladder 3", when=cancel_entries)
    strategy.cancel(id="Short Ladder 4", when=cancel_entries)
else
    strategy.entry(id="Short", direction=strategy.short, when=short_conditions_met)
    strategy.exit(id="Close Short", from_entry="Short", limit=EMA_, when=close_short_entries)
    strategy.cancel(id="Short", when=cancel_entries)



আরো