kotak-logo
ट्रेडिंगव्यू (TradingView) सिंप्लिफाइड Logo Light Mode

Kotak

Stockshaala

Module 7
पाइन स्क्रिप्ट (Pine Script) – बनाएं और बैकटेस्ट (backtest) करें
Course Index
Read in
English
हिंदी

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) का उपयोग करती हैं ताकि बार के भीतर प्राइस मूवमेंट का निर्धारण किया जा सके और डिफॉल्ट रूप से ऑर्डर्स को निष्पादित करने के लिए बार के बंद होने की प्रतीक्षा करती हैं, जो इंडिकेटर प्रकारों की तुलना में मुख्य अंतर है।

खरीद प्रवेश की शर्तें (Buy Entry Conditions):

  • RSI < 30 (ओवरसोल्ड)
  • सुपरट्रेंड अपट्रेंड मोड (बुलिश) में है
  • RSI > 70 (ओवरबॉट)
  • या सुपरट्रेंड बियरिश हो जाता है

इंडिकेटर() स्क्रिप्ट्स के विपरीत, एक स्ट्रेटेजी() स्क्रिप्ट पाइन स्क्रिप्ट™ में ट्रेडिंगव्यू के ब्रोकर एमुलेटर (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)

  1. कोड को ट्रेडिंगव्यू के पाइन एडिटर (Pine Editor) में पेस्ट करें
  2. "Add to Chart" पर क्लिक करें
  3. स्ट्रेटेजी टेस्टर (Strategy Tester) टैब खोलें
  4. मेट्रिक्स चेक करें जैसे:
  • नेट प्रॉफिट (Net Profit)
  • विन रेट (Win Rate)
  • ड्रॉडाउन (Drawdown)
  • ट्रेड्स की संख्या (Number of Trades)
  • प्रॉफिट फैक्टर (Profit Factor)

आप विभिन्न टाइमफ्रेम्स (15-मिन, 1H, डेली) में परिवर्तन कर सकते हैं ताकि यह देखा जा सके कि प्रदर्शन कैसे बदलता है।

  • RSI को स्टोकेस्टिक (Stochastic) या MACD से बदलें
  • स्ट्रेटेजी एग्जिट का उपयोग कर एक स्टॉप-लॉस जोड़ें
  • EMA फिल्टर्स या मल्टी-टाइमफ्रेम कन्फर्मेशन के साथ टेस्ट करें
  • शॉर्टिंग लॉजिक जोड़ें: strategy.entry("Sell", strategy.short)

अब आपने एक काम करने वाली स्ट्रेटेजी लिख ली है जो दो लोकप्रिय इंडिकेटर्स - 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.

Is this chapter helpful?
Previous
कम्युनिटी सेटअप्स (community setups) से सीखना
Next
इनपुट्स (inputs) और बैकटेस्ट कंट्रोल (backtest control) के साथ स्ट्रेटेजी (strategy) को ऑप्टिमाइज़ करना

Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Neo Research Team, nor is it a report published by the Kotak Neo Research Team. The information presented is compiled from several secondary sources available on the internet and may change over time. Investors should conduct their own research and consult with financial professionals before making any investment decisions. Read the full disclaimer here.

Investments in securities market are subject to market risks, read all the related documents carefully before investing. Brokerage will not exceed SEBI prescribed limit. The securities are quoted as an example and not as a recommendation. SEBI Registration No-INZ000200137 Member Id NSE-08081; BSE-673; MSE-1024, MCX-56285, NCDEX-1262.

Discover our extensive knowledge center

Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.

PreviousCourse IndexNext