
यह रणनीति आरएसआई को चलती औसत (एमए) के साथ जोड़ती है ताकि ट्रेडिंग सिग्नल उत्पन्न किया जा सके। आरएसआई का उपयोग यह निर्धारित करने के लिए किया जाता है कि बाजार ओवरबॉय या ओवरसोल्ड है या नहीं, और एमए का उपयोग मूल्य प्रवृत्ति का आकलन करने के लिए किया जाता है। जब आरएसआई ओवरबॉय होता है और एमए से अधिक कीमत होती है तो यह एक खरीद संकेत उत्पन्न करता है; जब आरएसआई ओवरसोल्ड होता है या एमए एक डेड फोर्क उत्पन्न करता है तो यह एक बिक्री संकेत उत्पन्न करता है। इसके अलावा, रणनीति में एक यादृच्छिक आरएसआई सूचक (स्टोच आरएसआई) को एक सहायक निर्णय के रूप में पेश किया गया है, जो स्टोच आरएसआई के संकेत के रूप में चार्ट पर संकेत देता है।
इस रणनीति में RSI और MA दो क्लासिक संकेतक के संयोजन के माध्यम से, ट्रेंडिंग ट्रेंड और ओवरबॉट ओवरबॉट समय को पकड़ने में सक्षम है, जबकि स्टोचआरएसआई संकेतक को सहायक निर्णय के रूप में पेश किया गया है, समग्र विचार सरल और स्पष्ट है। लेकिन रणनीति में कुछ कमियां भी हैं, जैसे कि जोखिम नियंत्रण उपायों की कमी, संकेत सटीकता में सुधार करना है। भविष्य में, अधिक संकेतक, अनुकूलित संकेत नियम, जोखिम नियंत्रण मॉड्यूल आदि को शामिल करने के लिए रणनीति को बेहतर बनाया जा सकता है, ताकि अधिक स्थिर लाभ प्राप्त किया जा सके।
/*backtest
start: 2023-05-22 00:00:00
end: 2024-05-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("RSI Strategy with Customizable MA and StochRSI Alert", overlay=true)
// กำหนดค่า RSI สำหรับการเปิดสัญญาณซื้อและขาย
rsiOverbought = input(70, title="RSI Overbought Level")
rsiOversold = input(30, title="RSI Oversold Level")
// เลือกชนิดของเส้นค่าเฉลี่ยเคลื่อนที่
maType = input.string("EMA", title="MA Type", options=["EMA", "SMA", "HMA", "WMA"])
// กำหนดค่าเส้นค่าเฉลี่ยเคลื่อนที่
maShortLength = input(12, title="MA Short Length")
maLongLength = input(26, title="MA Long Length")
// เลือกการแสดงผลของเส้นค่าเฉลี่ยเคลื่อนที่
showShortMA = input(true, title="Show Short Moving Average")
showLongMA = input(true, title="Show Long Moving Average")
// ฟังก์ชันสำหรับเลือกชนิดของเส้นค่าเฉลี่ยเคลื่อนที่
f_ma(src, length, type) =>
switch type
"SMA" => ta.sma(src, length)
"EMA" => ta.ema(src, length)
"HMA" => ta.hma(src, length)
"WMA" => ta.wma(src, length)
// คำนวณค่าเส้นค่าเฉลี่ยเคลื่อนที่
maShort = showShortMA ? f_ma(close, maShortLength, maType) : na
maLong = showLongMA ? f_ma(close, maLongLength, maType) : na
// คำนวณค่า RSI
rsiValue = ta.rsi(close, 14)
// สร้างสัญญาณซื้อและขาย
buySignal = (rsiValue > rsiOverbought and ((showShortMA and showLongMA and close > maShort and maShort > maLong) or (showShortMA and not showLongMA and close > maShort) or (showLongMA and not showShortMA and close > maLong)))
sellSignal = (showShortMA and showLongMA and ta.crossover(maLong, maShort)) or (showShortMA and not showLongMA and ta.crossover(maShort, close)) or (showLongMA and not showShortMA and ta.crossover(maLong, close))
// แสดงค่าเส้นค่าเฉลี่ยเคลื่อนที่บนกราฟ
plot(maShort, color=color.red, title="MA Short")
plot(maLong, color=color.green, title="MA Long")
// คำนวณค่า Stochastic RSI
smoothK = 3
smoothD = 3
RSIlen = 14
STOlen = 14
SRsrc = close
OSlevel = 30
OBlevel = 70
rsi1 = ta.rsi(SRsrc, RSIlen)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, STOlen), smoothK)
d = ta.sma(k, smoothD)
stochRSIOverbought = OBlevel
stochRSIOversold = OSlevel
stochRSIBuyAlert = ta.crossover(k, stochRSIOversold)
stochRSISellAlert = ta.crossunder(k, stochRSIOverbought)
// สร้างคำสั่งซื้อและขายเมื่อมีสัญญาณจาก RSI และ MA เท่านั้น
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.close("Buy")
// แสดงสัญญาณเตือนจาก Stochastic RSI บนกราฟ
plotshape(series=stochRSIBuyAlert, location=location.belowbar, color=color.green, style=shape.labelup, title="StochRSI Buy Alert")
plotshape(series=stochRSISellAlert, location=location.abovebar, color=color.red, style=shape.labeldown, title="StochRSI Sell Alert")
// แสดงสัญญาณซื้อและขายจาก RSI และ MA บนกราฟ
plotshape(series=buySignal, location=location.top, color=color.green, style=shape.triangleup, title="RSI>70")
plotshape(series=sellSignal, location=location.top, color=color.red, style=shape.triangledown, title="MA crossoverDown")