
یہ ایک رجحان کی پیروی کرنے والی حکمت عملی ہے جو ایکسپونینشل موونگ ایوریج (EMA) اور رشتہ دار طاقت انڈیکس (RSI) کو یکجا کرتی ہے۔ حکمت عملی تیز اور سست EMAs کے کراس اوور پر نظر رکھتی ہے، اور RSI اشارے کی زیادہ خریدی ہوئی اور زیادہ فروخت ہونے والی سطحوں کے ساتھ ساتھ RSI ڈائیورجن کو تجارتی سگنلز کا تعین کرنے کے لیے جوڑتی ہے، اس طرح مارکیٹ کے رجحانات کو مؤثر طریقے سے سمجھتی ہے۔ حکمت عملی 1 گھنٹے کی مدت پر چلتی ہے اور متعدد تکنیکی اشارے کی تصدیق کے ذریعے لین دین کی درستگی کو بہتر بناتی ہے۔
حکمت عملی کی بنیادی منطق میں درج ذیل کلیدی عناصر شامل ہیں:
یہ حکمت عملی موونگ ایوریج سسٹم، مومینٹم انڈیکیٹرز اور ڈائیورجینس تجزیہ کو ملا کر ایک نسبتاً مکمل تجارتی نظام تشکیل دیتی ہے۔ حکمت عملی سگنلز کی متعدد تصدیقوں پر توجہ مرکوز کرتی ہے، مؤثر طریقے سے غلط فہمی کے خطرے کو کم کرتی ہے۔ اگرچہ ایک خاص وقفہ ہے، حکمت عملی میں پیرامیٹر کی اصلاح اور رسک مینجمنٹ میں بہتری کے ذریعے عملی اطلاق کی اچھی قدر ہے۔
/*backtest
start: 2024-12-10 00:00:00
end: 2025-01-08 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA9_RSI_Strategy_LongShort", overlay=true)
// Parameters
fastLength = input.int(9, minval=1, title="Fast EMA Length")
slowLength = input.int(26, minval=1, title="Slow EMA Length")
rsiPeriod = input.int(14, minval=1, title="RSI Period")
rsiLevelLong = input.int(65, minval=1, title="RSI Level (Long)")
rsiLevelShort = input.int(35, minval=1, title="RSI Level (Short)")
// Define 1-hour timeframe
timeframe_1h = "60"
// Fetch 1-hour data
high_1h = request.security(syminfo.tickerid, timeframe_1h, high)
low_1h = request.security(syminfo.tickerid, timeframe_1h, low)
rsi_1h = request.security(syminfo.tickerid, timeframe_1h, ta.rsi(close, rsiPeriod))
// Current RSI
rsi = ta.rsi(close, rsiPeriod)
// Find highest/lowest price and corresponding RSI in the 1-hour timeframe
highestPrice_1h = ta.highest(high_1h, 1) // ราคาสูงสุดใน 1 ช่วงของ timeframe 1 ชั่วโมง
lowestPrice_1h = ta.lowest(low_1h, 1) // ราคาต่ำสุดใน 1 ช่วงของ timeframe 1 ชั่วโมง
highestRsi_1h = ta.valuewhen(high_1h == highestPrice_1h, rsi_1h, 0)
lowestRsi_1h = ta.valuewhen(low_1h == lowestPrice_1h, rsi_1h, 0)
// Detect RSI Divergence for Long
bearishDivLong = high > highestPrice_1h and rsi < highestRsi_1h
bullishDivLong = low < lowestPrice_1h and rsi > lowestRsi_1h
divergenceLong = bearishDivLong or bullishDivLong
// Detect RSI Divergence for Short (switch to low price for divergence check)
bearishDivShort = low > lowestPrice_1h and rsi < lowestRsi_1h
bullishDivShort = high < highestPrice_1h and rsi > highestRsi_1h
divergenceShort = bearishDivShort or bullishDivShort
// Calculate EMA
emaFast = ta.ema(close, fastLength)
emaSlow = ta.ema(close, slowLength)
// Long Conditions
longCondition = emaFast > emaSlow and rsi > rsiLevelLong and not divergenceLong
// Short Conditions
shortCondition = emaFast < emaSlow and rsi < rsiLevelShort and not divergenceShort
// Plot conditions
plotshape(longCondition, title="Buy", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(shortCondition, title="Sell", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")
// Execute the strategy
if (longCondition)
strategy.entry("Long", strategy.long, comment="entry long")
if (shortCondition)
strategy.entry("Short", strategy.short, comment="entry short")
// Alert
alertcondition(longCondition, title="Buy Signal", message="Buy signal triggered!")
alertcondition(shortCondition, title="Sell Signal", message="Sell signal triggered!")