ডাবল ইএমএ এবং আরএসআই সমন্বিত ট্রেন্ড ট্র্যাকিং কৌশল

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

img

সারসংক্ষেপ

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

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

  1. প্রধান প্রবণতা দিক নির্ধারণের জন্য 200 সময়ের ইএমএ ব্যবহার করুন। ইএমএ লাইনের উপরে মূল্য ক্রসিং bullish দৃষ্টিভঙ্গি নির্দেশ করে, যখন নীচে ক্রসিং bearish দৃষ্টিভঙ্গি নির্দেশ করে।

  2. আরএসআই সূচক প্যারামিটার ১০ পেরিওডে সেট। আরএসআই ৪০ সিগন্যালের উপরে অতিক্রম করে ওভারসোল্ড অবস্থা অতিক্রম করে, ৬০ সিগন্যালের নিচে অতিক্রম করে ওভারক্রয় অবস্থা অতিক্রম করে।

  3. যখন প্রধান প্রবণতা বাড়ছে (ইএমএ লাইনের উপরে মূল্য) এবং আরএসআই 40 এর নিচে অতিক্রম করে, তখন লম্বা হয়ে যান।

  4. যখন প্রধান প্রবণতা নেমে যায় (মূল্য EMA লাইনের নিচে) এবং RSI 60 এর উপরে ক্রসিং করে, যখন অতিরিক্ত ক্রয়ের সংকেত আসে, তখন শর্ট হয়ে যায়।

  5. স্টপ লস ATR ইন্ডিকেটরের 4 গুণে সেট করুন। 2: 1 ঝুঁকি পুরস্কার অনুপাতের জন্য লাভটি স্টপ লসের 2 গুণে সেট করুন।

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

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

  1. কার্যকর প্রবণতা ট্র্যাকিংয়ের জন্য প্রাথমিক প্রবণতা দিক নির্ধারণের জন্য দ্বৈত EMA সিস্টেম ব্যবহার করা।

  2. RSI সূচক স্বল্পমেয়াদী অতিরিক্ত ক্রয়/অতিরিক্ত বিক্রয় শর্তগুলি চিহ্নিত করে, প্রবেশের সময়কে সহায়তা করে।

  3. এটিআর সূচকের মাধ্যমে স্টপ লস সেট করা হয়েছে যা ঝুঁকি নিয়ন্ত্রণের জন্য বাজারের অস্থিরতার সাথে সামঞ্জস্যপূর্ণ।

  4. ট্রেন্ড ট্রেডিং নীতিগুলি কঠোরভাবে অনুসরণ করা অপ্রয়োজনীয় ট্রেডিং এবং সিস্টেম ঝুঁকি হ্রাস করে।

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

এই কৌশলটির প্রধান ঝুঁকিগুলির মধ্যে রয়েছেঃ

  1. প্রবণতা দুর্বল হলে এবং দাম অস্থির হলে মিথ্যা ট্রেডিং সংকেত দেখা দিতে পারে। এই সময়ে সতর্কতার সাথে ট্রেড করুন।

  2. এটিআর দ্বারা নির্ধারিত স্টপ লস খুব বিস্তৃত বা খুব সংকীর্ণ হতে পারে চরম বাজারের পরিস্থিতিতে। গতিশীল সমন্বয় বা অন্যান্য স্টপ লস প্রক্রিয়া বিবেচনা করা উচিত।

  3. সম্ভাব্য উচ্চ সংকেত ফ্রিকোয়েন্সির জন্য ব্যক্তিগত ট্রেডিং ফ্রিকোয়েন্সি পছন্দ অনুসারে প্রয়োজন।

  4. সময়মত অপ্টিমাইজেশনের জন্য আরএসআই পরামিতির উপযুক্ততা পর্যবেক্ষণ করা প্রয়োজন।

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

মূল অপ্টিমাইজেশান দিকগুলির মধ্যে রয়েছেঃ

  1. প্রবণতা মূল্যায়নে সহায়তা করার জন্য ম্যাকডের মতো অন্যান্য প্রবণতা সূচক যুক্ত করে পরীক্ষা করুন।

  2. আরও ভাল সংকেতের জন্য কেডিজে, বলিংজার ব্যান্ডের মতো অন্যান্য বিপরীতমুখী সূচকগুলির সাথে আরএসআই একত্রিত করে পরীক্ষা করুন।

  3. গতিশীল পরামিতি সমন্বয় এবং অভিযোজিত স্টপ লস/লাভ গ্রহণের জন্য মেশিন লার্নিং অ্যালগরিদম চালু করা।

  4. আরও বেশি সংখ্যক কারণ যেমন অনুভূতি, সংবাদ, যাতে সিস্টেম আরও শক্তিশালী হয়।

সিদ্ধান্ত

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


/*backtest
start: 2024-01-10 00:00:00
end: 2024-01-14 13:00:00
period: 5m
basePeriod: 1m
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/
// © kevinmck100

// @description
// This strategy is intended to be used as a base template for building new strategies.
//
// It incorporates the following features:
//
//      - Risk management:  Configurable X% loss per stop loss
//                          Configurable R:R ratio
//
//      - Trade entry:      Calculated position size based on risk tolerance
//
//      - Trade exit:       Stop Loss currently configurable ATR multiplier but can be replaced based on strategy
//                          Take Profit calculated from Stop Loss using R:R ratio
//
//      - Backtesting:      Configurable backtesting range by date
//
//      - Trade drawings:   TP/SL boxes drawn for all trades. Can be turned on and off
//                          Trade exit information labels. Can be turned on and off
//                          NOTE: Trade drawings will only be applicable when using overlay strategies
//
//      - Debugging:        Includes section with useful debugging techniques
//
// Strategy conditions:
//
//      - Trade entry:      LONG:   C1: Price is above EMA line
//                                  C2: RSI is crossing out of oversold area
//                          SHORT:  C1: Price is below EMA line
//                                  C2: RSI is crossing out of overbought area
//
//      - Trade exit:       Stop Loss:      Stop Loss ATR multiplier is hit
//                          Take Profit:    R:R multiplier * Stop Loss is hit
//
// The idea is to use RSI to catch pullbacks within the main trend. Note that
// this strategy is intended to be a simple base strategy for building upon.
// It was not designed to be traded in its current form.

//@version=5
INITIAL_CAPITAL = 1000
DEFAULT_COMMISSION = 0.02
MAX_DRAWINGS = 500
IS_OVERLAY = true

strategy("Risk Management Strategy Template", "Strategy Template", overlay = IS_OVERLAY, initial_capital = INITIAL_CAPITAL, currency = currency.NONE, max_labels_count = MAX_DRAWINGS, max_boxes_count = MAX_DRAWINGS, max_lines_count = MAX_DRAWINGS, default_qty_type = strategy.cash, commission_type = strategy.commission.percent, commission_value = DEFAULT_COMMISSION)

// =============================================================================
// INPUTS
// =============================================================================

// ------------------------ Replacable section - Start -------------------------
// ------------------
// Indicator Settings
// ------------------
emaLength           = input.int (200,   "EMA Length          ",             group = "Indicators: Settings",         inline = "IS1", minval = 1,                 tooltip = "EMA line to identify trend direction. Above EMA trend line is bullish. Below EMA trend line is bearish")
rsiLength           = input.int (10,    "RSI Length            ",           group = "Indicators: Settings",         inline = "IS2", minval = 1)

// ----------------------
// Trade Entry Conditions
// ----------------------
rsiOverbought       = input.int (60,    "RSI Overbought        ",           group = "Strategy: Conditions",         inline = "SC1", minval = 50, maxval = 100,  tooltip = "RSI overbought level used to identify pullbacks within the main trend. RSI crossing BELOW this level triggers a SHORT when in a DOWN trend")
rsiOversold         = input.int (40,    "RSI Oversold          ",           group = "Strategy: Conditions",         inline = "SC2", minval = 0,  maxval = 50,   tooltip = "RSI overbought level used to identify pullbacks within the main trend. RSI crossing ABOVE this level triggers a LONG when in an UP trend")

// ---------------------
// Trade Exit Conditions
// ---------------------
atrLength           = input.int  (14,   "Stop Loss ATR Length      ",       group = "Strategy: Exit Conditions",    inline = "EC1", minval = 0,                 tooltip = "Length of ATR used to calculate Stop Loss.")
slAtrMultiplier     = input.float(4,    "Stop Loss ATR Multiplier     ",    group = "Strategy: Exit Conditions",    inline = "EC2", minval = 0, step = 0.1,     tooltip = "Size of StopLoss is determined by multiplication of ATR value. Take Profit is derived from this also by multiplying the StopLoss value by the Risk:Reward multiplier.")
// ------------------------- Replacable section - End --------------------------

// ---------------
// Risk Management
// ---------------
riskReward          = input.float(2,    "Risk : Reward        1 :",         group = "Strategy: Risk Management",    inline = "RM1", minval = 0, step = 0.1,     tooltip = "Previous high or low (long/short dependant) is used to determine TP level. 'Risk : Reward' ratio is then used to calculate SL based of previous high/low level.\n\nIn short, the higher the R:R ratio, the smaller the SL since TP target is fixed by previous high/low price data.")
accountRiskPercent  = input.float(1,    "Portfolio Risk %         ",        group = "Strategy: Risk Management",    inline = "RM1", minval = 0, step = 0.1,     tooltip = "Percentage of portfolio you lose if trade hits SL.\n\nYou then stand to gain\n  Portfolio Risk % * Risk : Reward\nif trade hits TP.")

// ----------
// Date Range
// ----------
startYear           = input.int (2022,  "Start Date       ",                group = 'Strategy: Date Range',         inline = 'DR1', minval    = 1900, maxval = 2100)
startMonth          = input.int (1,     "",                                 group = 'Strategy: Date Range',         inline = 'DR1', options   = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
startDate           = input.int (1,     "",                                 group = 'Strategy: Date Range',         inline = 'DR1', options   = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])
endYear             = input.int (2100,  "End Date      ",                   group = 'Strategy: Date Range',         inline = 'DR2', minval    = 1900, maxval = 2100)
endMonth            = input.int (1,     "",                                 group = 'Strategy: Date Range',         inline = 'DR2', options   = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
endDate             = input.int (1,     "",                                 group = 'Strategy: Date Range',         inline = 'DR2', options   = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])

// ----------------
// Drawing Settings
// ----------------
showTpSlBoxes       = input.bool(false,  "Show TP / SL Boxes",               group = "Strategy: Drawings",           inline = "D1",  tooltip = "Show or hide TP and SL position boxes.\n\nNote: TradingView limits the maximum number of boxes that can be displayed to 500 so they may not appear for all price data under test.")
showLabels          = input.bool(false, "Show Trade Exit Labels",           group = "Strategy: Drawings",           inline = "D2",  tooltip = "Useful labels to identify Profit/Loss and cumulative portfolio capital after each trade closes.\n\nAlso note that TradingView limits the max number of 'boxes' that can be displayed on a chart (max 500). This means when you lookback far enough on the chart you will not see the TP/SL boxes. However you can check this option to identify where trades exited.")

// =============================================================================
// INDICATORS
// =============================================================================

// ------------------------ Replacable section - Start -------------------------
// ---
// EMA
// ---
ema = ta.ema(close, emaLength)
plot(ema, "EMA Trend Line", color.white)

// ---
// RSI
// ---
rsi = ta.rsi(close, rsiLength)
// ------------------------- Replacable section - End --------------------------


// =============================================================================
// STRATEGY LOGIC
// =============================================================================

// ---------
// FUNCTIONS
// ---------

percentAsPoints(pcnt) =>
    math.round(pcnt / 100 * close / syminfo.mintick)
    
calcStopLossPrice(pointsOffset, isLong) =>
    priceOffset = pointsOffset * syminfo.mintick
    if isLong
        close - priceOffset
    else 
        close + priceOffset

calcProfitTrgtPrice(pointsOffset, isLong) =>
    calcStopLossPrice(-pointsOffset, isLong)
    
        
printLabel(barIndex, msg) => label.new(barIndex, close, msg)

printTpSlHitBox(left, right, slHit, tpHit, entryPrice, slPrice, tpPrice) => 
    if showTpSlBoxes
        box.new (left = left,   top = entryPrice,   right = right,  bottom = slPrice,   bgcolor = slHit ? color.new(color.red, 60)   : color.new(color.gray, 90), border_width = 0)
        box.new (left = left,   top = entryPrice,   right = right,  bottom = tpPrice,   bgcolor = tpHit ? color.new(color.green, 60) : color.new(color.gray, 90), border_width = 0)
        line.new(x1 = left,     y1 = entryPrice,    x2 = right,     y2 = entryPrice,    color = color.new(color.yellow, 20))
        line.new(x1 = left,     y1 = slPrice,       x2 = right,     y2 = slPrice,       color = color.new(color.red, 20))
        line.new(x1 = left,     y1 = tpPrice,       x2 = right,     y2 = tpPrice,       color = color.new(color.green, 20))
        
printTpSlNotHitBox(left, right, entryPrice, slPrice, tpPrice) => 
    if showTpSlBoxes
        box.new (left = left,   top = entryPrice,   right = right,  bottom = slPrice,   bgcolor = color.new(color.gray, 90), border_width = 0)
        box.new (left = left,   top = entryPrice,   right = right,  bottom = tpPrice,   bgcolor = color.new(color.gray, 90), border_width = 0)
        line.new(x1 = left,     y1 = entryPrice,    x2 = right,     y2 = entryPrice,    color = color.new(color.yellow, 20))
        line.new(x1 = left,     y1 = slPrice,       x2 = right,     y2 = slPrice,       color = color.new(color.red, 20))
        line.new(x1 = left,     y1 = tpPrice,       x2 = right,     y2 = tpPrice,       color = color.new(color.green, 20))
        
printTradeExitLabel(x, y, posSize, entryPrice, pnl) => 
    if showLabels
        labelStr = "Position Size: " + str.tostring(math.abs(posSize), "#.##") + "\nPNL: " + str.tostring(pnl, "#.##") + "\nCapital: " + str.tostring(strategy.equity, "#.##") + "\nEntry Price: " + str.tostring(entryPrice, "#.##")
        label.new(x = x, y = y, text = labelStr, color = pnl > 0 ? color.new(color.green, 60) : color.new(color.red, 60), textcolor = color.white, style = label.style_label_down)

// ----------
// CONDITIONS
// ----------

inDateRange         = time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0) and time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0)

// ------------------------ Replacable section - Start -------------------------
// Condition 1: Price above EMA indicates bullish trend, price below EMA indicates bearish trend
bullEma             = close > ema
bearEma             = close < ema

// Condition 2: RSI crossing back from overbought/oversold indicates pullback within trend
bullRsi             = ta.crossover  (rsi, rsiOversold)
bearRsi             = ta.crossunder (rsi, rsiOverbought)

// Combine all entry conditions
goLong              = inDateRange and bullEma and bullRsi
goShort             = inDateRange and bearEma and bearRsi
// ------------------------- Replacable section - End --------------------------

// Trade entry and exit variables
var tradeEntryBar   = bar_index
var profitPoints    = 0.
var lossPoints      = 0.
var slPrice         = 0.
var tpPrice         = 0.
var inLong          = false
var inShort         = false

// Entry decisions
openLong            = (goLong and not inLong)
openShort           = (goShort and not inShort)
flippingSides       = (goLong and inShort) or (goShort and inLong)
enteringTrade       = openLong or openShort
inTrade             = inLong or inShort

// ------------------------ Replacable section - Start -------------------------
// Exit calculations
atr                 = ta.atr(atrLength)
slAmount            = atr * slAtrMultiplier
slPercent           = math.abs((1 - (close - slAmount) / close) * 100)
tpPercent           = slPercent * riskReward
// ------------------------- Replacable section - End --------------------------

// Risk calculations
riskAmt             = strategy.equity * accountRiskPercent / 100
entryQty            = math.abs(riskAmt / slPercent * 100)  / close

if openLong
    if strategy.position_size < 0
        printTpSlNotHitBox(tradeEntryBar + 1, bar_index + 1, strategy.position_avg_price, slPrice, tpPrice)
        printTradeExitLabel(bar_index + 1, math.max(tpPrice, slPrice), strategy.position_size, strategy.position_avg_price, strategy.openprofit)
    strategy.entry("Long", strategy.long, qty = entryQty, alert_message = "Long Entry")
    enteringTrade   := true
    inLong          := true
    inShort         := false

if openShort
    if strategy.position_size > 0
        printTpSlNotHitBox(tradeEntryBar + 1, bar_index + 1, strategy.position_avg_price, slPrice, tpPrice)
        printTradeExitLabel(bar_index + 1, math.max(tpPrice, slPrice), strategy.position_size, strategy.position_avg_price, strategy.openprofit)
    strategy.entry("Short", strategy.short, qty = entryQty, alert_message = "Short Entry")
    enteringTrade   := true
    inShort         := true
    inLong          := false

if enteringTrade
    profitPoints    := percentAsPoints(tpPercent)
    lossPoints      := percentAsPoints(slPercent)
    slPrice         := calcStopLossPrice(lossPoints, openLong)
    tpPrice         := calcProfitTrgtPrice(profitPoints, openLong)
    tradeEntryBar   := bar_index

strategy.exit("TP/SL", profit = profitPoints, loss = lossPoints, comment_profit = "TP Hit", comment_loss = "SL Hit", alert_profit = "TP Hit Alert", alert_loss = "SL Hit Alert")

// =============================================================================
// DRAWINGS
// =============================================================================

// -----------
// TP/SL Boxes
// -----------

slHit           = (inShort and high >= slPrice) or (inLong  and low <= slPrice)
tpHit           = (inLong  and high >= tpPrice) or (inShort and low <= tpPrice)
exitTriggered   = slHit or tpHit
entryPrice      = strategy.closedtrades.entry_price (strategy.closedtrades - 1)
pnl             = strategy.closedtrades.profit      (strategy.closedtrades - 1)
posSize         = strategy.closedtrades.size        (strategy.closedtrades - 1)

// Print boxes for trades closed at profit or loss
if (inTrade and exitTriggered) 
    inShort    := false
    inLong     := false 
    printTpSlHitBox(tradeEntryBar + 1, bar_index, slHit, tpHit, entryPrice, slPrice, tpPrice)
    printTradeExitLabel(bar_index, math.max(tpPrice, slPrice), posSize, entryPrice, pnl)

// Print TP/SL box for current open trade
if barstate.islastconfirmedhistory and strategy.position_size != 0
    printTpSlNotHitBox(tradeEntryBar + 1, bar_index + 1, strategy.position_avg_price, slPrice, tpPrice)
    
// =============================================================================
// DEBUGGING
// =============================================================================

// Data window plots
plotchar(slPrice,    "Stop Loss Price",     "")
plotchar(tpPrice,    "Take Profit Price",   "")

// Label plots
plotDebugLabels = false
if plotDebugLabels
    if bar_index == tradeEntryBar 
        printLabel(bar_index, "Position size: " + str.tostring(entryQty * close, "#.##"))


আরো