Posts

How Does the Stochastic Indicator Work? A Beginner's Guide to Overbought & Oversold Signals in Pine Script v6

Image
The Stochastic Oscillator is one of the most widely used momentum indicators in technical analysis, designed to measure where the current closing price sits relative to the high-low range over a specified lookback period. By normalizing price into a 0–100 scale, it provides a mathematically consistent framework for identifying when an asset may be statistically extended — either to the upside (overbought) or downside (oversold). This guide walks through the mathematics, the Pine Script v6 implementation, and the key parameters that govern its behavior. 1. The Mathematics Behind the Stochastic Oscillator The Stochastic Oscillator was developed by George Lane and is built on a straightforward normalization formula. The core value, called %K , answers the question: "Where does today's close fall within the recent price range?" The formula for %K is: $$\%K = \frac{\text{Close} - \text{Lowest Low}(n)}{\text{Highest High}(n) -...

How to Build a Volume Indicator in Pine Script v6: Buying & Selling Pressure Analysis

Image
Volume is one of the most fundamental data points in technical analysis — it tells you how much was traded, not just at what price . In this post, you will learn how to build a complete volume indicator in Pine Script v6 that color-codes bars by buying or selling pressure, detects volume spikes using a dynamic SMA baseline, and annotates those spikes directly on the chart using plotshape() with location.absolute . 1. What Is Volume and Why Does It Matter? Volume represents the total number of contracts or shares exchanged during a given bar. When price moves on high volume , the move is considered more significant. When price moves on low volume , it may lack conviction. The key analytical concepts are: Buying Pressure: Close price is above the open price — bulls dominated the bar. Selling Pressure: Close price is below the open price — bears dominated the bar. Volume Spike: Current volume exceeds a rolling average by a con...

Why Is VWAP Important? A Pine Script v6 Deep Dive for Intraday Traders

Image
VWAP (Volume-Weighted Average Price) is one of the most widely referenced benchmarks in intraday trading, used by institutional desks and algorithmic systems alike to assess whether a trade was executed at a favorable price relative to the day's volume-weighted mean. This article explains the mathematical foundation of VWAP, why it matters for intraday analysis, and how to implement a precise, session-aware VWAP indicator in Pine Script v6. 1. What Is VWAP? The Mathematical Definition VWAP is defined as the cumulative sum of price × volume divided by the cumulative sum of volume, reset at the start of each trading session: $$\text{VWAP}_t = \frac{\sum_{i=1}^{t} P_i \times V_i}{\sum_{i=1}^{t} V_i}$$ Where: $P_i$ = Typical price at bar $i$, defined as $\frac{\text{High}_i + \text{Low}_i + \text{Close}_i}{3}$ $V_i$ = Volume at bar $i$ The summation resets at the start of each new trading session (e.g., each new day on a 1...

How to Use Bollinger Bands in Pine Script v6: Volatility Measurement and Breakout Detection

Image
Bollinger Bands are a statistical volatility envelope built from a simple moving average and a rolling standard deviation, giving traders a dynamic price channel that expands during high-volatility regimes and contracts during low-volatility regimes. Understanding the mathematics behind the bands — and the Pine Script v6 constraints that govern their implementation — is essential before writing production-quality indicators. This article walks through the exact formulas, type-system rules, and verified code patterns required to build a correct Bollinger Band indicator in Pine Script v6. 1. Mathematical Foundation Given a source series $x_t$ and a lookback window of $n$ bars, the three Bollinger Band lines are defined as: $$\text{Basis}_t = \frac{1}{n}\sum_{i=0}^{n-1} x_{t-i}$$ $$\text{Upper}_t = \text{Basis}_t + k \cdot \sigma_t$$ $$\text{Lower}_t = \text{Basis}_t - k \cdot \sigma_t$$ where $k$ is the standard-deviation multiplier (co...

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,...