Pine Script Tutorial in Tamil for Beginners: Master Custom Indicators and Strategies
Pine Script, the proprietary programming language of TradingView, empowers traders and analysts to create custom indicators and automated trading strategies. For Tamil-speaking beginners, navigating this powerful tool can be challenging due to a lack of comprehensive resources in their native language. This tutorial aims to demystify Pine Script, providing a robust foundation for learning, specifically tailored to address the needs of the Tamil trading community by presenting complex concepts in an accessible English format.
What is Pine Script?
Pine Script is a lightweight, easy-to-learn programming language designed specifically for the TradingView platform. It enables users to develop their own analytical tools, visualize market data in unique ways, and automate trading decisions. Unlike general-purpose programming languages, Pine Script is highly specialized, focusing on time-series data and charting functionalities. Its integration within TradingView provides a seamless environment for coding, testing, and applying custom scripts directly to charts.
Why Learn Pine Script (Especially for Tamil Speakers)?
- Unleash Customization: Go beyond standard indicators. Create unique tools that reflect your personal trading philosophy and market insights.
- Backtest Strategies: Test your trading ideas against historical data to evaluate their profitability and robustness before risking capital.
- Automate Trading Logic: Develop scripts that generate buy/sell signals or even execute trades based on predefined conditions, removing emotional bias.
- Bridge the Language Gap: While this tutorial is in English, understanding Pine Script opens doors to a vast global community. Having structured learning material that acknowledges the Tamil beginner context makes complex technical topics more approachable, enabling faster comprehension for those who might find English-only resources daunting initially.
- Community Engagement: Share your custom indicators and strategies with the global TradingView community, or adapt existing ones to suit your needs.
Getting Started: The TradingView Environment
To begin your Pine Script journey, you’ll primarily interact with the Pine Editor within TradingView. Accessing it is straightforward:
- Log in to your TradingView account.
- Open any chart.
- Look for the “Pine Editor” tab at the bottom of the chart interface. Click it to open the editor.
The Pine Editor comprises:
- Code Editor: Where you write your Pine Script code.
- Open/Save/Compile Buttons: Tools for managing your scripts.
- “Add to Chart” Button: Applies your compiled script to the active chart.
- Console Panel: Displays errors, warnings, and messages from your script.
Basic Pine Script Concepts
Syntax & Structure
Every Pine Script starts with a version declaration and then defines whether it’s an indicator or a strategy.
- Version Declaration: All scripts must begin with `//@version=` followed by the Pine Script version number (e.g., `//@version=5`). This ensures compatibility.
- Indicator or Strategy Declaration:
- `indicator(“My Indicator”, “MI”, true)`: Declares a script as an indicator. Parameters include title, short title, and whether it should overlay on the price chart.
- `strategy(“My Strategy”, “MS”, true)`: Declares a script as a strategy. Parameters are similar to indicators.
- Comments: Use `//` for single-line comments or `/* … */` for multi-line comments. Comments are crucial for code readability and understanding.
Variables & Data Types
Variables store data. Pine Script supports several data types:
- `float`: Decimal numbers (e.g., `10.5`, `3.14`).
- `int`: Whole numbers (e.g., `1`, `100`, `-5`).
- `bool`: Boolean values (`true` or `false`).
- `string`: Text (e.g., `”Hello World”`, `”SMA”`).
Variables are typically declared using the `var` keyword for historical assignment, or simply assigned directly.
//@version=5
indicator("Variable Example")
myFloat = 10.5
myInt = 100
myBool = true
myString = "Example Text"
Operators
Operators perform operations on variables and values.
- Arithmetic: `+` (addition), `-` (subtraction), `*` (multiplication), `/` (division), `%` (modulo).
- Comparison: `==` (equal to), `!=` (not equal to), `<` (less than), `>` (greater than), `<=` (less than or equal to), `>=` (greater than or equal to).
- Logical: `and`, `or`, `not`.
Functions
Pine Script provides numerous built-in functions for common calculations, and you can also define your own.
- Built-in Functions:
- `close`: The closing price of the current bar. Similarly, `open`, `high`, `low`, `volume`.
- `ta.sma(source, length)`: Simple Moving Average.
- `ta.ema(source, length)`: Exponential Moving Average.
- `plot(series, title, color, style, linewidth)`: Plots a series on the chart.
- User-Defined Functions: You can create reusable blocks of code.
Plotting
The `plot()` function is fundamental for visualizing data on your chart.
//@version=5
indicator("My Simple Plot")
myPrice = close
plot(myPrice, title="Closing Price", color=color.blue, linewidth=2, style=plot.style_line)
Your First Pine Script: A Simple Moving Average
Let’s create a script that plots a 20-period Simple Moving Average (SMA) on the chart.
//@version=5
indicator("20-Period SMA Indicator", "SMA 20", true)
// Input for SMA length, allowing users to change it easily
smaLength = input.int(20, title="SMA Length", minval=1)
// Calculate the Simple Moving Average of the closing price
smaValue = ta.sma(close, smaLength)
// Plot the SMA on the chart
plot(smaValue, title="SMA", color=color.blue, linewidth=2)
// Plot the closing price for reference (optional)
plot(close, title="Close", color=color.black, linewidth=1, style=plot.style_line)
Explanation:
- `indicator(…)`: Declares this script as an indicator, named “20-Period SMA Indicator”, with a short title “SMA 20”, and overlays it on the price chart.
- `smaLength = input.int(…)`: Creates an input field on the indicator’s settings, allowing you to change the SMA period without editing the code. Default is 20.
- `smaValue = ta.sma(close, smaLength)`: Calls the built-in `ta.sma` function. `close` is the data source (closing price of each bar), and `smaLength` is the period.
- `plot(smaValue, …)`: Draws the calculated `smaValue` on the chart as a blue line.
- `plot(close, …)`: (Optional) Plots the closing price as a thinner black line for comparison.
To use this: Copy the code into the Pine Editor, click “Add to Chart”.
Building a Basic Strategy: SMA Cross-over
Now, let’s build a simple strategy that generates buy/sell signals when a fast SMA crosses a slow SMA.
//@version=5
strategy("SMA Crossover Strategy", "SMA Cross", overlay=true)
// Define input lengths for the two SMAs
fastLength = input.int(9, title="Fast SMA Length", minval=1)
slowLength = input.int(21, title="Slow SMA Length", minval=1)
// Calculate the SMAs
fastSMA = ta.sma(close, fastLength)
slowSMA = ta.sma(close, slowLength)
// Plot the SMAs
plot(fastSMA, color=color.red, title="Fast SMA")
plot(slowSMA, color=color.blue, title="Slow SMA")
// Define entry and exit conditions
longCondition = ta.crossover(fastSMA, slowSMA)
shortCondition = ta.crossunder(fastSMA, slowSMA)
// Execute strategy orders
if (longCondition)
strategy.entry("LongEntry", strategy.long) // Enter a long position
if (shortCondition)
strategy.close("LongEntry") // Close the existing long position
strategy.entry("ShortEntry", strategy.short) // Enter a short position (optional)
Explanation:
- `strategy(…)`: Declares this script as a strategy.
- `fastLength`, `slowLength`: User-definable lengths for the SMAs.
- `fastSMA`, `slowSMA`: Calculate the two moving averages.
- `plot(…)`: Visualizes the two SMAs on the chart.
- `longCondition = ta.crossover(fastSMA, slowSMA)`: A built-in function that returns `true` when the `fastSMA` crosses above the `slowSMA`.
- `shortCondition = ta.crossunder(fastSMA, slowSMA)`: Returns `true` when the `fastSMA` crosses below the `slowSMA`.
- `strategy.entry(“LongEntry”, strategy.long)`: Executes a market order to go long when `longCondition` is true. “LongEntry” is a unique ID for this order.
- `strategy.close(“LongEntry”)`: Closes any open position with the ID “LongEntry” when `shortCondition` is true.
- `strategy.entry(“ShortEntry”, strategy.short)`: (Optional) Enters a short position when `shortCondition` is true.
After adding this strategy to your chart, TradingView’s Strategy Tester will show its performance metrics.
Key Pine Script Functions for Traders
Familiarize yourself with these essential functions:
- `open`, `high`, `low`, `close`, `volume`: Accesses historical price and volume data for the current bar.
- `time`: Returns the UNIX timestamp of the current bar’s open time.
- `barstate.islast`, `barstate.ishistory`: Useful for conditions that should only trigger on the very last (real-time) bar or only on historical bars.
- `input.int()`, `input.float()`, `input.bool()`, `input.string()`: Creates user-definable inputs in the script settings.
- `color.new(color, transparency)`: Creates a new color with transparency.
- `math.abs()`, `math.sqrt()`, `math.round()`: Common mathematical functions.
- `ta.atr(length)`: Average True Range.
- `ta.rsi(source, length)`: Relative Strength Index.
- `ta.macd(source, fastlen, slowlen, siglen)`: Moving Average Convergence Divergence.
Maximizing Your Pine Script Learning Journey for Tamil Speakers
- Consistent Practice: The best way to learn is by doing. Experiment with existing scripts, modify them, and try to implement your own ideas.
- Utilize TradingView Documentation: TradingView offers extensive, well-structured official documentation for Pine Script. While in English, it’s the definitive resource for function definitions and usage.
- Deconstruct Community Scripts: Explore the “Public Library” on TradingView to see how experienced developers write their scripts. Analyzing these can provide invaluable learning.
- Start Small: Begin with simple indicators and gradually increase complexity. Don’t try to build a super-strategy on day one.
- Focus on Core Concepts: A solid understanding of variables, functions, conditional logic (`if`, `else`), and loops is more important than memorizing every function.
- Leverage Tamil Trading Communities: While Pine Script itself is a technical language, connecting with Tamil-speaking trading communities can provide support, clarify concepts in a relatable context, and share practical applications specific to local market conditions. Even if the discussion is in Tamil, the underlying Pine Script syntax remains universal.
Mastering Pine Script unlocks a new dimension in your trading analysis on TradingView. For Tamil-speaking beginners, this comprehensive tutorial provides a clear English pathway, breaking down complex programming concepts into manageable steps. Embrace the learning process, experiment frequently, and leverage the power of Pine Script to refine your trading edge.
Follow Us : https://telegram.me/gagashare1
https://facebook.com/gagashareindia




