Posts

Showing posts with the label SMA

What Is an SMA Moving Average? Pine Script v6 Guide to Simple Moving Averages

Image
When analyzing price charts, raw candlestick data can appear noisy and difficult to interpret — the Simple Moving Average (SMA) is one of the most fundamental mathematical tools used to smooth that noise and reveal the underlying directional trend of a market. 1. What Is a Simple Moving Average (SMA)? A Simple Moving Average is a statistical calculation that computes the arithmetic mean of a price series over a fixed number of periods. At each bar, the SMA sums the most recent N closing prices and divides by N , producing a single smoothed value that "rolls" forward with each new bar. Mathematical Definition For a window of length $N$, the SMA at time $t$ is defined as: $$\text{SMA}_t = \frac{1}{N} \sum_{i=0}^{N-1} P_{t-i}$$ Where $P_{t-i}$ is the price at bar $t - i$. Every observation within the window receives an equal weight of $\frac{1}{N}$. Numerical Example Consider 5 consecutive closing prices: 10, 12, 11, 13,...

Pine Script v6: How to Use request.security to Fetch Higher-Timeframe Data

Image
When building multi-timeframe indicators in TradingView, one of the most common needs is to overlay a higher-timeframe signal — such as a daily moving average — onto a lower-timeframe chart like a 15-minute view. The request.security() function is the primary tool for this task in Pine Script v6, and understanding its parameters precisely is essential for writing accurate, non-repainting indicators and strategies. 1. What Is request.security() ? request.security() allows a Pine Script to fetch the value of any expression as it would be calculated on a different symbol or timeframe. The result is then mapped back onto the current chart's bar timeline. This is the foundation of multi-timeframe (MTF) analysis in Pine Script. For the full official signature, refer to the Reference Manual: request.security() — Pine Script v6 Reference . 2. Core Parameters Explained The following table describes the most critical parameters you will u...

A Beginner's Guide to Pine Script: What It Is and How It Works in TradingView

Image
Pine Script is TradingView's proprietary scripting language, purpose-built for creating custom technical indicators, strategies, and alerts directly within the TradingView platform. Understanding its foundational architecture is essential before writing a single line of code, as Pine Script operates on a unique execution model that differs fundamentally from general-purpose programming languages. This guide provides an objective, engineering-focused introduction to Pine Script's core concepts for absolute beginners. 1. What Is Pine Script? Pine Script is a domain-specific language (DSL) developed by TradingView, designed exclusively for financial chart analysis. It is a lightweight, interpreted language that runs on TradingView's servers, meaning all computations are executed in the cloud and rendered directly on the chart. As of this writing, the current stable version is Pine Script v6 . Key characteristics of Pine Script...