

Kotak
Stockshaala
Chapter 1 | 3 min read
स्ट्रेटेजी लॉजिक बिल्डिंग (strategy logic building) (उदाहरण: आरएसआई (RSI) + सुपरट्रेंड (supertrend))
आपने अपना पहला कस्टम इंडिकेटर बना लिया है। अब समय है चीजों को एक कदम आगे ले जाने का:
- वास्तविक खरीद/बिक्री लॉजिक (buy/sell logic) के साथ एक ट्रेडिंग स्ट्रेटेजी (trading strategy) बनाएं
- इसे वास्तविक ऐतिहासिक डेटा पर टेस्ट करें
- यह देखने के लिए कि यह काम करता है या नहीं, बिना कोई पैसा जोखिम में डाले
इस चैप्टर में, आप एक स्ट्रेटेजी बनाएंगे जो:
- एक खरीद ट्रेड (buy trade) में प्रवेश करती है जब RSI ओवरसोल्ड (oversold) होता है और सुपरट्रेंड बुलिश (bullish) होता है।
- एग्जिट करती है जब RSI एक निश्चित स्तर से ऊपर जाता है या सुपरट्रेंड बियरिश (bearish) हो जाता है।
इंडिकेटर स्क्रिप्ट्स के विपरीत, स्ट्रेटेजी स्क्रिप्ट्स ब्रोकर एमुलेटर लॉजिक (broker emulator logic) का उपयोग करती हैं ताकि बार के भीतर प्राइस मूवमेंट का निर्धारण किया जा सके और डिफॉल्ट रूप से ऑर्डर्स को निष्पादित करने के लिए बार के बंद होने की प्रतीक्षा करती हैं, जो इंडिकेटर प्रकारों की तुलना में मुख्य अंतर है।
स्ट्रेटेजी लॉजिक (Strategy Logic)
खरीद प्रवेश की शर्तें (Buy Entry Conditions):
- RSI < 30 (ओवरसोल्ड)
- सुपरट्रेंड अपट्रेंड मोड (बुलिश) में है
एग्जिट की शर्तें (Exit Conditions):
- RSI > 70 (ओवरबॉट)
- या सुपरट्रेंड बियरिश हो जाता है
फुल पाइन स्क्रिप्ट्स™ स्ट्रेटेजी कोड (Full Pine Scripts™ Strategy Code) (टिप्पणियों के साथ)
इंडिकेटर() स्क्रिप्ट्स के विपरीत, एक स्ट्रेटेजी() स्क्रिप्ट पाइन स्क्रिप्ट™ में ट्रेडिंगव्यू के ब्रोकर एमुलेटर (TradingView’s broker emulator) का उपयोग करती है ताकि ऐतिहासिक डेटा पर ट्रेड्स का सिमुलेशन किया जा सके। यह मॉडल करता है कि प्रत्येक बार के भीतर प्राइस कैसे मूव होता है और डिफॉल्ट रूप से ऑर्डर निष्पादित करने से पहले बार के बंद होने की प्रतीक्षा करता है — इसे बैकटेस्टिंग (backtesting) और प्रदर्शन मूल्यांकन के लिए आदर्श बनाता है।
//@version=6
strategy("RSI + Supertrend Strategy", overlay=true)
// === इनपुट्स (INPUTS) ===
rsiPeriod = input.int(14, title="RSI Period")
rsiBuyLevel = input.int(30, title="RSI Buy Threshold")
rsiSellLevel = input.int(70, title="RSI Sell Threshold")
atrPeriod = input.int(10, title="Supertrend ATR Period")
factor = input.float(3.0, title="Supertrend Multiplier")
// === इंडिकेटर्स (INDICATORS) ===
// RSI
rsi = ta.rsi(close, rsiPeriod)
// सुपरट्रेंड फंक्शन (Supertrend Function)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
isBullish = direction == 1
isBearish = direction == -1
// === स्ट्रेटेजी की शर्तें (STRATEGY CONDITIONS) ===
// जब RSI < 30 हो और ट्रेंड बुलिश हो, तब प्रवेश करें
longCondition = (rsi < rsiBuyLevel) and isBullish
if (longCondition)
strategy.entry("Buy", strategy.long)
// जब RSI > 70 हो या ट्रेंड बियरिश हो जाए, तब एग्जिट करें
exitCondition = (rsi > rsiSellLevel) or isBearish
if (exitCondition)
strategy.close("Buy")
// === विजुअल्स (VISUALS) ===
plot(supertrend, title="Supertrend", color=isBullish ? color.green : color.red, linewidth=1)
स्ट्रेटेजी कैसे काम करती है (How the Strategy Works)
प्रवेश (Entry) | RSI 30 से नीचे है और सुपरट्रेंड बुलिश है |
एग्जिट (Exit) | RSI 70 से ऊपर है या सुपरट्रेंड बियरिश हो जाता है |
पोजीशन प्रकार (Position Type) | केवल लंबी (Long only) (आप बाद में शॉर्ट लॉजिक जोड़ सकते हैं) |
टेस्टिंग मेथड (Testing Method) | ट्रेडिंगव्यू में स्ट्रेटेजी टेस्टर (Strategy Tester) |
इसे कैसे बैकटेस्ट करें (How to Backtest It)
- कोड को ट्रेडिंगव्यू के पाइन एडिटर (Pine Editor) में पेस्ट करें
- "Add to Chart" पर क्लिक करें
- स्ट्रेटेजी टेस्टर (Strategy Tester) टैब खोलें
- मेट्रिक्स चेक करें जैसे:
- नेट प्रॉफिट (Net Profit)
- विन रेट (Win Rate)
- ड्रॉडाउन (Drawdown)
- ट्रेड्स की संख्या (Number of Trades)
- प्रॉफिट फैक्टर (Profit Factor)
आप विभिन्न टाइमफ्रेम्स (15-मिन, 1H, डेली) में परिवर्तन कर सकते हैं ताकि यह देखा जा सके कि प्रदर्शन कैसे बदलता है।
वैकल्पिक बदलाव जो आप आजमा सकते हैं (Optional Tweaks You Can Try)
- RSI को स्टोकेस्टिक (Stochastic) या MACD से बदलें
- स्ट्रेटेजी एग्जिट का उपयोग कर एक स्टॉप-लॉस जोड़ें
- EMA फिल्टर्स या मल्टी-टाइमफ्रेम कन्फर्मेशन के साथ टेस्ट करें
- शॉर्टिंग लॉजिक जोड़ें: strategy.entry("Sell", strategy.short)
संक्षेप में (To Sum Up)
अब आपने एक काम करने वाली स्ट्रेटेजी लिख ली है जो दो लोकप्रिय इंडिकेटर्स - RSI और सुपरट्रेंड को जोड़ती है और यहां तक कि वास्तविक डेटा का उपयोग करके इसे बैकटेस्ट भी किया है।
यह बिना पैसा जोखिम में डाले, स्ट्रेटेजीज बनाने, टेस्ट करने और सुधारने की दिशा में एक बड़ा कदम है।
This content has been translated using a translation tool. We strive for accuracy; however, the translation may not fully capture the nuances or context of the original text. If there are discrepancies or errors, they are unintended, and we recommend original language content for accuracy.
Recommended Courses for you
Beyond Stockshaala
Discover our extensive knowledge center
Learn, Invest, and Grow with Kotak Videos
Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.














