
বিল উইলিয়ামসের এক-তৃতীয়াংশ কে-লাইন বিশ্লেষণ পদ্ধতি এবং ডায়নামিক ট্র্যাকিং স্টপ লস ফাংশনকে একত্রিত করে এটি একটি পরিমাণগত ট্রেডিং কৌশল। এই কৌশলটি বর্তমান এবং পূর্ববর্তী কে-লাইনের কাঠামোগত বৈশিষ্ট্য বিশ্লেষণ করে একটি সুস্পষ্ট পলিহোম সিগন্যাল তৈরি করে এবং একটি কনফিগারযোগ্য ট্র্যাকিং স্টপ লস মেকানিজম ব্যবহার করে পজিশনের সুরক্ষার জন্য, সঠিক প্রবেশ / প্রস্থান এবং ঝুঁকি পরিচালনার জন্য।
এই কৌশলটি নিম্নলিখিত কয়েকটি মূল অংশের উপর ভিত্তি করে তৈরি করা হয়েছেঃ
এটি একটি কাঠামোগত, যুক্তিসঙ্গত এবং স্পষ্ট পরিমাণে ট্রেডিং কৌশল যা ক্লাসিক প্রযুক্তিগত বিশ্লেষণ পদ্ধতি এবং আধুনিক ঝুঁকি ব্যবস্থাপনা প্রযুক্তির সমন্বয় ব্যবহার করে ভাল ব্যবহারযোগ্যতা রয়েছে। কৌশলটির নকশাটি সিগন্যাল জেনারেশন, হোল্ডিং ম্যানেজমেন্ট এবং ঝুঁকি নিয়ন্ত্রণের মতো গুরুত্বপূর্ণ অংশ সহ রিয়েল-টাইম ট্রেডিংয়ের প্রয়োজনীয়তা পুরোপুরি বিবেচনা করে। আরও অপ্টিমাইজেশন এবং পরিমার্জনের মাধ্যমে, কৌশলটি বাস্তব ট্রেডিংয়ে আরও ভাল পারফরম্যান্সের সম্ভাবনা রয়েছে।
/*backtest
start: 2024-02-18 00:00:00
end: 2025-02-16 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("TrinityBar with Trailing Stop", overlay=true, initial_capital=100000,
default_qty_type=strategy.percent_of_equity, default_qty_value=250)
//─────────────────────────────────────────────────────────────
// 1. BAR THIRDS CALCULATIONS
//─────────────────────────────────────────────────────────────
cur_range = high - low
cur_lowerThird = low + cur_range / 3
cur_upperThird = high - cur_range / 3
prev_range = high[1] - low[1]
prev_lowerThird = low[1] + prev_range / 3
prev_upperThird = high[1] - prev_range / 3
//─────────────────────────────────────────────────────────────
// 2. DEFINE BULLISH & BEARISH BAR TYPES (CURRENT & PREVIOUS)
//─────────────────────────────────────────────────────────────
// Current bar types
is_1_3 = (open <= cur_lowerThird) and (close >= cur_upperThird)
is_3_3 = (open >= cur_upperThird) and (close >= cur_upperThird)
is_2_3 = (open > cur_lowerThird) and (open < cur_upperThird) and (close >= cur_upperThird)
is_3_1 = (open >= cur_upperThird) and (close <= cur_lowerThird)
is_1_1 = (open <= cur_lowerThird) and (close <= cur_lowerThird)
is_2_1 = (open > cur_lowerThird) and (open < cur_upperThird) and (close <= cur_lowerThird)
// Previous bar types
prev_is_1_3 = (open[1] <= prev_lowerThird) and (close[1] >= prev_upperThird)
prev_is_3_3 = (open[1] >= prev_upperThird) and (close[1] >= prev_upperThird)
prev_is_2_3 = (open[1] > prev_lowerThird) and (open[1] < prev_upperThird) and (close[1] >= prev_upperThird)
prev_is_3_1 = (open[1] >= prev_upperThird) and (close[1] <= prev_lowerThird)
prev_is_1_1 = (open[1] <= prev_lowerThird) and (close[1] <= prev_lowerThird)
prev_is_2_1 = (open[1] > prev_lowerThird) and (open[1] < prev_upperThird) and (close[1] <= prev_lowerThird)
//─────────────────────────────────────────────────────────────
// 3. VALID SIGNAL CONDITIONS
//─────────────────────────────────────────────────────────────
validBuy = (prev_is_2_3 or prev_is_3_3 or prev_is_1_3) and (is_1_3 or is_3_3)
validSell = (prev_is_2_1 or prev_is_1_1 or prev_is_3_1) and (is_1_1 or is_3_1)
//─────────────────────────────────────────────────────────────
// 4. PLOT SIGNAL TRIANGLES
//─────────────────────────────────────────────────────────────
plotshape(validBuy, title="Valid Buy", style=shape.triangleup, location=location.belowbar,
color=color.green, size=size.small, text="B")
plotshape(validSell, title="Valid Sell", style=shape.triangledown, location=location.abovebar,
color=color.red, size=size.small, text="S")
//─────────────────────────────────────────────────────────────
// 5. MARKET ORDER EXECUTION BASED ON SIGNALS
//─────────────────────────────────────────────────────────────
if validBuy
// Close any short positions.
strategy.close("Short", comment="")
// If not already long, enter a market long.
if strategy.position_size <= 0
strategy.entry("Long", strategy.long, comment="")
if validSell
// Close any long positions.
strategy.close("Long", comment="")
// If not already short, enter a market short.
if strategy.position_size >= 0
strategy.entry("Short", strategy.short, comment="")
//─────────────────────────────────────────────────────────────
// 6. TRAILING STOP LOSS FUNCTION
//─────────────────────────────────────────────────────────────
// Inputs for trailing stop settings:
trailBars = input.int(title="Trailing Stop Bars Back", defval=1, minval=1)
trailTF = input.timeframe(title="Trailing Stop Timeframe", defval="") // "" = current timeframe
// For long positions, use the low from 'trailBars' bars back on the specified timeframe.
// For short positions, use the high from 'trailBars' bars back.
trailStopLong = request.security(syminfo.tickerid, trailTF, low[trailBars])
trailStopShort = request.security(syminfo.tickerid, trailTF, high[trailBars])
// Apply trailing stops if a position is open.
if strategy.position_size > 0
strategy.exit("Trailing Stop Long", from_entry="Long", stop=trailStopLong)
if strategy.position_size < 0
strategy.exit("Trailing Stop Short", from_entry="Short", stop=trailStopShort)