RSI اشارے پر مبنی الٹ کرنے کی حکمت عملی

مصنف:چاؤ ژانگ، تاریخ: 2024-01-08 16:47:07
ٹیگز:

img

جائزہ

یہ حکمت عملی RSI اشارے کی بنیاد پر overbought یا oversold حالات کے بعد واپسی کے مواقع کی نشاندہی کرتی ہے۔ یہ ممکنہ مستقبل میں واپسی کے امکانات کا تعین کرنے کے لئے RSI overbought یا oversold زون میں داخل ہونے کے بعد قیمت اور RSI کے مابین فرق کی نگرانی کرے گی۔

حکمت عملی منطق

یہ حکمت عملی مارکیٹ میں زیادہ خریدنے اور زیادہ فروخت ہونے کی صورتحال کا تعین کرنے کے لئے آر ایس آئی اشارے کا استعمال کرتی ہے۔ جب آر ایس آئی پہلے سے طے شدہ زیادہ خریدنے یا زیادہ فروخت والے زون میں داخل ہوتا ہے تو ، یہ الٹ پھیرنے کے اختلافات کی نگرانی شروع کردے گا۔

خاص طور پر ، اگر آر ایس آئی اوور بک زون میں داخل ہوتا ہے تو ، یہ اس بات کی نگرانی کرے گا کہ آیا قیمت میں اضافہ جاری ہے (جسے اعلی نچلی سطحیں تشکیل دی جاتی ہیں) جبکہ آر ایس آئی کم نچلی سطحیں تشکیل دیتی ہے - ایک باقاعدہ تیزی سے تغیر؛ یا قیمت کم نچلی سطحیں تشکیل دیتی ہے اور آر ایس آئی اعلی نچلی سطحیں تشکیل دیتی ہے ایک پوشیدہ تیزی سے تغیر۔ دونوں صورتوں میں ممکنہ نیچے کی طرف رخ موڑنے کی نشاندہی ہوتی ہے۔

اسی طرح ، اگر آر ایس آئی oversold زون میں داخل ہوتا ہے تو ، یہ نگرانی کرے گا کہ آیا قیمت میں کمی جاری ہے (ذیلی اونچائیوں کی تشکیل) جبکہ آر ایس آئی اعلی اونچائیوں کی تشکیل کرتا ہے ایک باقاعدگی سے bearish انحراف؛ یا قیمت اعلی اونچائیوں کی تشکیل کرتی ہے اور آر ایس آئی کم اونچائیوں کی تشکیل کرتی ہے ایک پوشیدہ bearish انحراف۔ دونوں صورتوں میں ممکنہ اوپر کی تبدیلیوں کی نشاندہی بھی ہوتی ہے۔

ایک بار جب مذکورہ بالا الٹ سگنل کا پتہ چل جاتا ہے تو ، تشکیل شدہ پیرامیٹرز کے مطابق لمبی یا مختصر پوزیشنیں لی جائیں گی۔

فوائد

اس حکمت عملی کا سب سے بڑا فائدہ یہ ہے کہ وہ مارکیٹ کی انتہائی صورتحال کی نشاندہی کرنے میں کامیاب ہے جہاں الٹ جانے کا امکان زیادہ ہوتا ہے اور الٹ جانے والی کارروائیوں کے لئے منافع کا مارجن بڑا ہوتا ہے۔ سادہ رجحان کی پیروی کرنے والی حکمت عملیوں کے مقابلے میں ، اس طرح کے انسداد رجحان کی حکمت عملیوں میں جیت کی شرح اور منافع کی شرح زیادہ ہوتی ہے۔

اس کے علاوہ، حکمت عملی میں باقاعدہ اور پوشیدہ اختلافات دونوں کی نگرانی شامل ہے تاکہ زیادہ سے زیادہ واپسی کے مواقع کی نشاندہی کی جاسکے اور ایک بار کی صورتحال کی وجہ سے اچھے مواقع ضائع نہیں ہوں گے۔

خطرات

اس حکمت عملی کا سب سے بڑا خطرہ اس سے بھی زیادہ شدید اوور بک یا اوور سیلنگ کی صورت حال ہے ، جسے کہا جاتا ہے سیدھے اوپر ، 90 ڈگری نیچے ۔ ایسے معاملات میں طویل یا مختصر کارروائیوں کو جاری رکھنا زیادہ امکان ہے ، اور الٹ جانے کی کارروائی کرنے سے آسانی سے اسٹاپ نقصان ہوسکتا ہے۔

اس کے علاوہ، اگر پیرامیٹرز کو صحیح طریقے سے مقرر نہیں کیا جاتا ہے اور زیادہ خریدنے اور زیادہ فروخت کی صورت حال کا فیصلہ کرنے میں غلطیاں ہیں، تو غلطیاں آسانی سے ہوسکتی ہیں.

اس سے نمٹنے کا طریقہ یہ ہے کہ زیادہ خریدنے اور زیادہ فروخت کرنے والے علاقوں کے لئے بالائی اور نچلی حدود کو معقول حد تک مقرر کیا جائے تاکہ انتہائی انتہائی حالات سے بچ سکے۔ ایک ہی اسٹاپ نقصان کی رقم پر قابو پانے کے لئے براہ راست تجارت میں پوزیشن کا سائز بھی کم کریں۔

اصلاح کی ہدایات

حکمت عملی کو مندرجہ ذیل پہلوؤں میں بہتر بنایا جاسکتا ہے:

  1. صرف آر ایس آئی پر انحصار کرنے سے بچنے کے لئے زیادہ خریدنے اور زیادہ فروخت کی حالتوں کا تعین کرنے کے لئے دوسرے اشارے شامل کریں

  2. جب الٹ جانے کا امکان زیادہ ہو تو بریک آؤٹ سے پہلے استحکام کی نشاندہی کرنے کے لئے منطق شامل کریں

  3. زیادہ سائنسی پوزیشن سائزنگ کی اجازت دینے کے لئے واپسی کے بعد منافع کے ہدف کی ترتیبات کو بہتر بنائیں

  4. خودکار طور پر پیرامیٹرز کو بہتر بنانے کے لئے حالیہ سالوں کے تاریخی اعداد و شمار پر مشین لرننگ کے طریقوں کا استعمال کریں

  5. سٹاپ نقصان منطق کی اصلاح کو بہتر بنائیں، مثال کے طور پر بروقت منافع لینے، وقفے وقفے سے سٹاپ نقصان، پیچھے سٹاپ نقصان وغیرہ.

نتیجہ

اختتام کے طور پر ، یہ ایک عام شماریاتی ثالثی کی حکمت عملی ہے۔ جب مارکیٹ انتہائی صورتحال سے توازن کی طرف لوٹتی ہے تو مواقع کو حاصل کرنے کی کوشش کرتی ہے۔ رجحانات پر عمل کرنے والی حکمت عملیوں کے مقابلے میں ، اس میں جیت کی شرح اور منافع بخش ہونے کی شرح زیادہ ہے لیکن اس میں زیادہ خطرات بھی ہیں۔ پیرامیٹر کی اصلاح اور رسک کنٹرول کے ساتھ اس قسم کی حکمت عملی مستقل طور پر منافع بخش ہوسکتی ہے۔


/*backtest
start: 2023-01-01 00:00:00
end: 2024-01-07 00:00:00
period: 1d
basePeriod: 1h
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/
// made by Imal_Max 
// thanks to neo the crypto trader's idea
//
// thanks to JayTradingCharts RSI Divergence /w Alerts indicator for the base code. 
// we modified this to detect the divergence only if price was oversold or overbought recently and a few more settings
// also now you can backtest the settings easy

//@version=5

// 🔥 comment out the line below to disable the alerts and enable the backtester 
//indicator(title="RSI Divergence Indicator with Alerts Overbought Oversold", shorttitle="RSI OB/OS Divergence", format=format.price, timeframe="")



// 🔥 uncomment the line below to enable the backtester + uncomment the lines slightly below and at the bottom of the script
strategy(title="RSI Divergence Indicator with Alerts Overbought Oversold", shorttitle="RSI OB/OS Divergence", overlay=true)





len = input.int(title='RSI Period', minval=1, defval=14, group='regular RSI settings')
src = input.source(title='RSI Source', defval=close, group='regular RSI settings')
lbR = input.int(title='Pivot Lookback Right', defval=5, group='regular RSI settings')
lbL = input.int(title='Pivot Lookback Left', defval=5, group='regular RSI settings')


rangeUpper = input.int(title='Max of Lookback Range', defval=60, group='regular RSI settings')
rangeLower = input.int(title='Min of Lookback Range', defval=5, group='regular RSI settings')
plotBull = input.bool(title='Plot Bullish', defval=true, group='regular RSI settings')
plotHiddenBull = input.bool(title='Plot Hidden Bullish', defval=true, group='regular RSI settings')
plotBear = input.bool(title='Plot Bearish', defval=true, group='regular RSI settings')
plotHiddenBear = input.bool(title='Plot Hidden Bearish', defval=true, group='regular RSI settings')



// ob/os divergence settings

obvalue = input.int(title='OB RSI Value', defval=70, group='look for RSI divergence after OverBought/OverSold', inline='Input 0', tooltip="min RSI Level needed within lookback period to look for bullish divergences")
oblookback = input.int(title='OB lookback period', defval=30, group='look for RSI divergence after OverBought/OverSold', inline='Input 0')
osvalue = input.int(title='OS RSI Value', defval=35, group='look for RSI divergence after OverBought/OverSold', inline='Input 1', tooltip="max RSI Level needed within lookback period to look for bearish divergences")
oslookback = input.int(title='OS lookback period', defval=30, group='look for RSI divergence after OverBought/OverSold', inline='Input 1')
minBearRSI = input.int(title='min RSI for bear Alerts', defval=60, group='look for RSI divergence after OverBought/OverSold', tooltip="min RSI needed at the time where bearish divergence gets detected")
maxBullRSI = input.int(title='max RSI for Bull Alerts', defval=50, group='look for RSI divergence after OverBought/OverSold', tooltip="max RSI needed at the time where bullish divergence gets detected")


// Backtesteer Info
enableBacktesterInfo = input(true, title="to enable the Backtester, uncomment/comment the 🔥 lines in the source code", group='enable Backtester')


// Backtester input stuff

// long settings - 🔥 uncomment the 3 lines below to disable the alerts and enable the backtester 
longTrading = input(true, title="enable Long Backtester (to disable uncheck 'plot Bullish' and 'plot hidden Bullish as well')", group='Long Backtester')
longStopLoss = input.float(0.5, title='Stop Loss %', group='Long Backtester') / 100
longTakeProfit = input.float(2.0, title='Take Profit %', group='Long Backtester') / 100

// short settings - 🔥 uncomment the 3 lines below to disable the alerts and enable the backtester 
shortTrading = input(true, title="enable Short Backtester (to disable uncheck 'plot Bearish' and 'plot hidden Bearish as well'", group='Short Backtester')
shortStopLoss = input.float(0.5, title='Stop Loss %', group='Short Backtester') / 100
shortTakeProfit = input.float(2.0, title='Take Profit %', group='Short Backtester') / 100

// Backtesting Range settings - 🔥 uncomment the 6 lines below to disable the alerts and enable the backtester 
startDate = input.int(title='Start Date', defval=1, minval=1, maxval=31, group='Backtesting range')
startMonth = input.int(title='Start Month', defval=1, minval=1, maxval=12, group='Backtesting range')
startYear = input.int(title='Start Year', defval=2016, minval=1800, maxval=2100, group='Backtesting range')
endDate = input.int(title='End Date', defval=1, minval=1, maxval=31, group='Backtesting range')
endMonth = input.int(title='End Month', defval=1, minval=1, maxval=12, group='Backtesting range')
endYear = input.int(title='End Year', defval=2040, minval=1800, maxval=2100, group='Backtesting range')





bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)
osc = ta.rsi(src, len)

plot(osc, title='RSI', linewidth=2, color=color.new(#00bcd4, 0))
obLevel = hline(obvalue, title='Overbought', linestyle=hline.style_dotted)
osLevel = hline(osvalue, title='Oversold', linestyle=hline.style_dotted)

minRSIline = hline(minBearRSI, title='max RSI for Bull divergence', linestyle=hline.style_dotted)
maxRSIline = hline(maxBullRSI, title='max RSI for Bull divergence', linestyle=hline.style_dotted)

fill(obLevel, minRSIline, title='Bear Zone Background', color=color.new(#f44336, 90))
fill(osLevel, maxRSIline, title='Bull Zone Background', color=color.new(#4caf50, 90))

RSI0line = hline(0, title='RSI 0 Line', linestyle=hline.style_dotted)
RSI100line = hline(100, title='RSI 100 Line', linestyle=hline.style_dotted)

fill(obLevel, RSI100line, title='Overbought Zone Background', color=color.new(#e91e63, 75))
fill(osLevel, RSI0line, title='Oversold Zone Background', color=color.new(#4caf50, 75))


plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
    bars = ta.barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper


// check if RSI was OS or OB recently

obHighestRsi = ta.highest(osc, oblookback)
osLowestRsi = ta.lowest(osc, oslookback)


//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low

oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Lower Low

priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)


bullCond = plotBull and priceLL and oscHL and plFound and osLowestRsi < osvalue and osc < maxBullRSI


plot(plFound ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond ? bullColor : noneColor, transp=0)

plotshape(bullCond ? osc[lbR] : na, offset=-lbR, title='Regular Bullish Label', text=' Bull ', style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, transp=0)

//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low

oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Higher Low

priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)


hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound and osLowestRsi < osvalue and osc < maxBullRSI


plot(plFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond ? hiddenBullColor : noneColor, transp=0)

plotshape(hiddenBullCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish Label', text=' H Bull ', style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, transp=0)

//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High

oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Higher High

priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)

bearCond = plotBear and priceHH and oscLH and phFound and obHighestRsi > obvalue and osc > minBearRSI

plot(phFound ? osc[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=2, color=bearCond ? bearColor : noneColor, transp=0)

plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title='Regular Bearish Label', text=' Bear ', style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, transp=0)

//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High

oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Lower High

priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)



hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound and obHighestRsi > obvalue and osc > minBearRSI



plot(phFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish', linewidth=2, color=hiddenBearCond ? hiddenBearColor : noneColor, transp=0)

plotshape(hiddenBearCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish Label', text=' H Bear ', style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, transp=0)



alertcondition(bullCond, title='Bullish divergence', message='Regular Bull Div {{ticker}} XXmin')
alertcondition(bearCond, title='Bearish divergence', message='Regular Bear Div {{ticker}} XXmin')
alertcondition(hiddenBullCond, title='Hidden Bullish divergence', message='Hidden Bull Div {{ticker}} XXmin')
alertcondition(hiddenBearCond, title='Hidden Bearish divergence', message='Hidden Bear Div {{ticker}} XXmin')




// 🔥 uncomment the all lines below for the backtester and revert for alerts
longTP = strategy.position_size > 0 ? strategy.position_avg_price * (1 + longTakeProfit) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - longTakeProfit) : na
longSL = strategy.position_size > 0 ? strategy.position_avg_price * (1 - longStopLoss) : strategy.position_size < 0 ? strategy.position_avg_price * (1 + longStopLoss) : na
shortTP = strategy.position_size > 0 ? strategy.position_avg_price * (1 + shortTakeProfit) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - shortTakeProfit) : na
shortSL = strategy.position_size > 0 ? strategy.position_avg_price * (1 - shortStopLoss) : strategy.position_size < 0 ? strategy.position_avg_price * (1 + shortStopLoss) : na
strategy.risk.allow_entry_in(longTrading == true and shortTrading == true ? strategy.direction.all : longTrading == true ? strategy.direction.long : shortTrading == true ? strategy.direction.short : na)
strategy.entry('Bull', strategy.long, comment='Long', when=bullCond)
strategy.entry('Bull', strategy.long, comment='Long', when=hiddenBullCond)
strategy.entry('Bear', strategy.short, comment='Short', when=bearCond)
strategy.entry('Bear', strategy.short, comment='Short', when=hiddenBearCond)
strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP, stop=longSL)
strategy.exit(id='shortTP-SL', from_entry='Bear', limit=shortTP, stop=shortSL)




مزید