Posts

Showing posts with the label Technical Indicators

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

Pine Script Tutorial for Beginners: Hello World, Pine Editor Setup & First Chart Script

Image
Pine Script is TradingView's built-in scripting language, purpose-built for creating custom technical indicators, strategies, and libraries directly on live charts. This step-by-step tutorial walks through opening the Pine Editor, understanding the minimal required structure of a Pine Script, writing a verified Hello World script, and applying it to a chart — all grounded in Pine Script v6 syntax and TradingView's documented behavior. 1. What Is Pine Script? A Technical Overview Pine Script is a domain-specific language (DSL) compiled and executed on TradingView's servers. It operates on a bar-by-bar execution model : the script is called once per historical bar and once per real-time tick, processing data as a time series. Key engine characteristics include: Strongly typed with implicit typing: Pine is strongly typed, but the compiler infers types in most cases. Variables carry series qualifiers such as series float...