Strategy · Pine Script v6 · On the chart

200-Day Rule (Paul Tudor Jones) [JR]

by jayadevrana

This trend-following strategy implements Paul Tudor Jones' long-term moving average rule directly on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code47
Settings8inputs
LicenceMPL-2.0
Last update2 days ago26 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

47 lines of Pine Script v6 from scripts/paul-tudor-jones-200-day-rule.pine.txt, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

paul-tudor-jones-200-day-rule.pine.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JayadevRana
//@version=6
// Paul Tudor Jones — "my metric for everything I look at is the 200-day moving average of closing prices."
// Be long while price is above its long average, step aside when it closes below. A band and a confirmation
// count keep the rule from flipping on every small cross.
// Default = 100 days: the optimised setting on Nifty 2000-2014 (minimum 40 trades), validated on 2015-2026; PTJ's own line is 200.
strategy("200-Day Rule (Paul Tudor Jones) [JR]", shorttitle = "PTJ 200", overlay = true,
     initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100,
     commission_type = strategy.commission.percent, commission_value = 0.02, slippage = 2,
     margin_long = 0, margin_short = 0, process_orders_on_close = true, pyramiding = 0)

G1 = "1 · The average"
maLen   = input.int(100, "Average length (days)", minval = 10, group = G1)
maType  = input.string("SMA", "Average type", options = ["SMA", "EMA"], group = G1)
G2 = "2 · Whipsaw filter"
bandPct = input.float(0.0, "Band around the average (%)", minval = 0, step = 0.5, group = G2, tooltip = "Buy above average + band, sell below average − band")
confirm = input.int(1, "Closes needed beyond the line", minval = 1, maxval = 10, group = G2)
shortOn = input.bool(false, "Also short below the average", group = G2)
G3 = "3 · Test window"
fromT = input.time(timestamp("2000-01-01T00:00:00"), "Trade from", group = G3)
toT   = input.time(timestamp("2100-01-01T00:00:00"), "Trade until", group = G3)
showLv = input.bool(true, "Show average and band", group = G3)

inWin = time >= fromT and time <= toT
ma    = maType == "EMA" ? ta.ema(close, maLen) : ta.sma(close, maLen)
upper = ma * (1 + bandPct / 100)
lower = ma * (1 - bandPct / 100)
above = ta.barssince(close <= upper) >= confirm - 1 and close > upper
below = ta.barssince(close >= lower) >= confirm - 1 and close < lower

if inWin and not na(ma)
    if above and strategy.position_size <= 0
        strategy.entry("PTJ L", strategy.long)
    if below and strategy.position_size > 0
        strategy.close("PTJ L", comment = "below")
    if shortOn and below and strategy.position_size >= 0
        strategy.entry("PTJ S", strategy.short)
    if shortOn and above and strategy.position_size < 0
        strategy.close("PTJ S", comment = "above")
if not inWin and strategy.position_size != 0
    strategy.close_all(comment = "window end")

plot(showLv ? ma : na, "Average", color.new(color.orange, 0), 2)
plot(showLv and bandPct > 0 ? upper : na, "Upper band", color.new(color.teal, 40), 1)
plot(showLv and bandPct > 0 ? lower : na, "Lower band", color.new(color.red, 40), 1)
bgcolor(showLv and strategy.position_size > 0 ? color.new(color.teal, 92) : na, title = "In the market")

Overview

200-Day Rule (Paul Tudor Jones) [JR] calculates an SMA or EMA baseline with an optional percentage band and a confirmation close counter to filter out false breakouts. The strategy enters long positions when prices close above the upper band for a set number of bars and exits when prices close below the lower band. It can optionally trade short positions, and orders are managed without hard stop losses.

Details

Published by

jayadevrana on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingema-crossoverpine-scriptpine-script-v6pinescriptrsitechnical-analysistrading-automationtrading-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Average length (days)int100maLen
Average typestringSMAmaType
Band around the average (%)float0.0bandPct
Closes needed beyond the lineint1confirm
Also short below the averageboolfalseshortOn
Trade fromtimetimestamp("2000-01-01T00:00:00")fromT
Trade untiltimetimestamp("2100-01-01T00:00:00")toT
Show average and bandbooltrueshowLv
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers