Posts

Showing posts with the label TradingView

SuperTrend Indicator in Pine Script v6: Canonical Formula, Flip Logic, and Non-Repainting Signals

Image
Every trend-following trader eventually faces the same frustration: a moving average that lags too far behind price, generating entries long after the move has started and exits well into the reversal. The SuperTrend indicator was designed to solve exactly this problem — it combines Average True Range (ATR) volatility with a dynamic band-switching mechanism to produce a single, clean line that sits below price in an uptrend and above price in a downtrend. When price closes beyond the opposite band, the line flips, generating a confirmed signal on the closed bar. This post builds a precise, well-defined SuperTrend variant in Pine Script v6 , maps every formula term to its code variable, explains the exact flip conditions, and clarifies non-repainting behavior. What Is SuperTrend? The Mathematical Foundation SuperTrend is built on two components: a midpoint price and an ATR-scaled offset . The midpoint is typically the average of the hig...

CCI Indicator in Pine Script v6: Detect Cyclical Price Reversals with Precision

Image
Every trader has faced this frustrating scenario: you enter a trend just as it exhausts itself, or you exit a position right before a powerful reversal completes. The Commodity Channel Index (CCI) was engineered specifically to solve this problem — it quantifies how far price has deviated from its statistical norm, giving you a mathematically grounded signal for when a cycle is overextended and likely to reverse. In this guide, we'll build a fully functional CCI indicator in Pine Script v6 , dissect the math behind it, and wire up actionable overbought/oversold signals — all with verified, compile-ready code. 📐 The Mathematics of CCI Developed by Donald Lambert in 1980, the CCI measures the deviation of the Typical Price from its Simple Moving Average, normalized by the Mean Absolute Deviation (MAD). The formula is: $$\text{Typical Price} = \frac{\text{High} + \text{Low} + \text{Close}}{3}$$ $$\text{CCI} = \frac{\text{TP} - \text...

ADX Trend Strength Indicator in Pine Script v6: Build a Compile-Tested DMI Filter

Image
Every trader has experienced the frustration of entering what looks like a clean breakout, only to watch price immediately reverse into a choppy, sideways grind. The Average Directional Index (ADX) was designed by J. Welles Wilder specifically to solve this problem — not to tell you which direction the market is moving, but how strongly it is moving at all. In this guide, we will build a complete, compile-tested ADX indicator in Pine Script v6, dissect the mathematics behind every calculation step, and show you exactly how to use ADX as a regime filter to avoid low-conviction trades. The Core Problem: Trend vs. Noise Most directional indicators — moving averages, MACD, RSI — assume the market is trending. When it is not, they generate a relentless stream of false signals. ADX quantifies trend strength on a scale from 0 to 100, independent of direction. A rising ADX means the market is developing a trend (bullish...

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