এই কৌশলটি একটি প্রবণতা অনুসরণকারী সিস্টেম যা চলমান গড় এবং বাইরের বার প্যাটার্নকে একত্রিত করে। এটি 5- এবং 9-পিরিয়ড এক্সপোনেনশিয়াল মুভিং এভারেজ (EMA) প্রধান প্রবণতা সূচক হিসাবে ব্যবহার করে, সংকেত নিশ্চিতকরণ হিসাবে আউটসাইড বার প্যাটার্নের সাথে মিলিত। কৌশলটিতে আউটসাইড বারের উচ্চতার উপর ভিত্তি করে ডায়নামিক স্টপ-লস এবং টেক-প্রফিট সেটিংসও রয়েছে, সেইসাথে স্টপ-লস ট্রিগার হওয়ার পরে একটি পজিশন রিভার্সাল মেকানিজম।
কৌশলটির মূল যুক্তি নিম্নলিখিত মূল উপাদানগুলির উপর ভিত্তি করে:
এটি একটি কৌশল ব্যবস্থা যা প্রযুক্তিগত বিশ্লেষণের ক্লাসিক তত্ত্ব এবং আধুনিক পরিমাণগত ট্রেডিং ধারণাকে একত্রিত করে। চলন্ত গড় এবং আউটসাইড বারের সম্মিলিত ব্যবহারের মাধ্যমে, এটি শুধুমাত্র ট্রেন্ড ট্র্যাকিংয়ের সময়োপযোগীতা নিশ্চিত করে না, তবে সিগন্যালের নির্ভরযোগ্যতাও উন্নত করে। গতিশীল স্টপ-লস, টেক-প্রফিট এবং পজিশন রিভার্সাল মেকানিজমের নকশা ঝুঁকি ব্যবস্থাপনার উপর জোর প্রতিফলিত করে, কৌশলটিকে অত্যন্ত বাস্তবসম্মত করে তোলে। যদিও অপ্টিমাইজেশানের জন্য এখনও জায়গা আছে, সামগ্রিক কাঠামোতে ইতিমধ্যেই রিয়েল-টাইম অপারেশনের জন্য প্রাথমিক শর্ত রয়েছে।
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-15 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy(title="Outside Bar EMA Crossover Strategy with EMA Shift", shorttitle="Outside Bar EMA Cross", overlay=true)
// Input for EMA lengths
lenEMA1 = input.int(5, title="EMA 5 Length")
lenEMA2 = input.int(9, title="EMA 9 Length")
// Input for EMA 9 shift
emaShift = input.int(1, title="EMA 9 Shift", minval=0)
// Calculate EMAs
ema1 = ta.ema(close, lenEMA1)
ema2 = ta.ema(close, lenEMA2)
// Apply shift to EMA 9
ema2Shifted = na(ema2[emaShift]) ? na : ema2[emaShift] // Dịch chuyển EMA 9 bằng cách sử dụng offset
// Plot EMAs
plot(ema1, title="EMA 5", color=color.blue, linewidth=2)
plot(ema2Shifted, title="EMA 9 Shifted", color=color.red, linewidth=2)
// Outside Bar condition
outsideBar() => high > high[1] and low < low[1]
// Cross above EMA 5 and EMA 9 (shifted)
crossAboveEMA = close > ema1 and close > ema2Shifted
// Cross below EMA 5 and EMA 9 (shifted)
crossBelowEMA = close < ema1 and close < ema2Shifted
// Outside Bar cross above EMA 5 and EMA 9 (shifted)
outsideBarCrossAbove = outsideBar() and crossAboveEMA
// Outside Bar cross below EMA 5 and EMA 9 (shifted)
outsideBarCrossBelow = outsideBar() and crossBelowEMA
// Plot shapes for visual signals
plotshape(series=outsideBarCrossAbove, title="Outside Bar Cross Above", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy", textcolor=color.white)
plotshape(series=outsideBarCrossBelow, title="Outside Bar Cross Below", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell", textcolor=color.white)
// Calculate Outside Bar height
outsideBarHeight = high - low // Chiều cao của nến Outside Bar
// Calculate TP and SL levels
tpRatio = 0.5 // TP = 50% chiều cao nến Outside Bar
slRatio = 1.0 // SL = 100% chiều cao nến Outside Bar
tpLevelLong = close + outsideBarHeight * tpRatio // TP cho lệnh mua
slLevelLong = close - outsideBarHeight * slRatio // SL cho lệnh mua
tpLevelShort = close - outsideBarHeight * tpRatio // TP cho lệnh bán
slLevelShort = close + outsideBarHeight * slRatio // SL cho lệnh bán
// Strategy logic
if (outsideBarCrossAbove)
strategy.entry("Buy", strategy.long)
strategy.exit("Take Profit/Stop Loss", "Buy", stop=slLevelLong, limit=tpLevelLong) // Thêm TP và SL
if (outsideBarCrossBelow)
strategy.entry("Sell", strategy.short)
strategy.exit("Take Profit/Stop Loss", "Sell", stop=slLevelShort, limit=tpLevelShort) // Thêm TP và SL
// Logic: Nếu lệnh Buy bị Stop Loss => Vào lệnh Sell
if (strategy.position_size > 0 and close <= slLevelLong)
strategy.close("Buy")
strategy.entry("Sell After Buy SL", strategy.short)
// Logic: Nếu lệnh Sell bị Stop Loss => Vào lệnh Buy
if (strategy.position_size < 0 and close >= slLevelShort)
strategy.close("Sell")
strategy.entry("Buy After Sell SL", strategy.long)
// Cảnh báo khi label Buy xuất hiện
alertcondition(condition=outsideBarCrossAbove, title="Label Buy Xuất Hiện", message="Label Buy xuất hiện tại giá: {{close}}")
// Cảnh báo khi label Sell xuất hiện
alertcondition(condition=outsideBarCrossBelow, title="Label Sell Xuất Hiện", message="Label Sell xuất hiện tại giá: {{close}}")