
حکمت عملی ایک رجحان کی پیروی کرنے والا نظام ہے جو متحرک اوسط کو آؤٹ سائیڈ بار پیٹرن کے ساتھ جوڑتا ہے۔ یہ سگنل کی تصدیق کے طور پر آؤٹ سائیڈ بار پیٹرن کے ساتھ مل کر بنیادی رجحان کے اشارے کے طور پر 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}}")