Strategy · Pine Script v5 · On the chart

Bill Williams NTD Strategy

by saleh-ato· code credited to Saleh_Toodarvari

This strategy uses Bill Williams indicators including the Alligator (jaw, teeth, lips with RMA smoothing and offsets), Awesome Oscillator, and Accelerator Oscillator.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code115
Settings1inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago16 Jun 2025

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

115 lines of Pine Script v5 from Bill Williams NTD Strategy/NTD-Strategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

NTD-Strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Saleh_Toodarvari

//@version=5
strategy("Bill Williams NTD Strategy", overlay=true, 
     default_qty_type=strategy.percent_of_equity, default_qty_value=10,
     initial_capital=100000, currency=currency.USD)

// Create Enable Plot Boolean
showPlot = input.bool(false, title="Enable Plot") 

//------------------------------------------
// 1. Calculate Alligator Lines Using RMA (Smoothed MA)
//    Standard Bill Williams parameters:
//       Jaw   : Period 13, Offset 8
//       Teeth : Period 8,  Offset 5
//       Lips  : Period 5,  Offset 3
//------------------------------------------
jawPeriod    = 13
jawOffset    = 8
teethPeriod  = 8
teethOffset  = 5
lipsPeriod   = 5
lipsOffset   = 3

jaw    = ta.rma(close, jawPeriod)
teeth  = ta.rma(close, teethPeriod)
lips   = ta.rma(close, lipsPeriod)

// Apply offset to the lines (using historical data to compensate for delay)
jaw_val   = jaw[jawOffset]
teeth_val = teeth[teethOffset]
lips_val  = lips[lipsOffset]

//------------------------------------------
// 2. Calculate Awesome Oscillator (AO)
//    Difference between the 5-period and 34-period SMA of the median price ((high + low) / 2)
//------------------------------------------
ao = ta.sma((high + low) / 2, 5) - ta.sma((high + low) / 2, 34)

//------------------------------------------
// 3. Calculate Accelerator Oscillator (AC)
//    Formula: AC = AO - SMA(AO, 5)
//------------------------------------------
ac = ao - ta.sma(ao, 5)

//------------------------------------------
// 4. Identify Fractals (5-Bar Model)
//    - Bull Fractal: When the middle bar (index 2) has the lowest low in the 5-bar window.
//    - Bear Fractal: When the middle bar (index 2) has the highest high in the 5-bar window.
//------------------------------------------
bullFractalLow  = low[2]  == ta.lowest(low, 5) ? low[2]  : na
bearFractalHigh = high[2] == ta.highest(high, 5) ? high[2] : na

// Store the latest fractal levels for stop or signal confirmation
var float lastBullFractalLow  = na  // Suitable as stop loss for long trades
var float lastBearFractalHigh = na  // Suitable as stop loss for short trades

if not na(bullFractalLow)
    lastBullFractalLow := bullFractalLow
if not na(bearFractalHigh)
    lastBearFractalHigh := bearFractalHigh

//------------------------------------------
// 5. Define Market Conditions Based on Bill Williams Indicators
//------------------------------------------
// Alligator Sequence:
// - Bullish: Lips > Teeth > Jaw
// - Bearish: Lips < Teeth < Jaw
bullAlligator = (lips_val > teeth_val) and (teeth_val > jaw_val)
bearAlligator = (lips_val < teeth_val) and (teeth_val < jaw_val)

// Conditions for trade entry (only when there is no active position)
// For a long trade:
//   • Bullish Alligator alignment
//   • AO and AC are positive (signifying upward momentum)
//   • The close is above the last Bear Fractal (serving as a potential breakout level)
longCondition = bullAlligator and (ao > 0) and (ac > 0) and (not na(lastBearFractalHigh)) and (close > lastBearFractalHigh)

// For a short trade:
//   • Bearish Alligator alignment
//   • AO and AC are negative
//   • The close is below the last Bull Fractal
shortCondition = bearAlligator and (ao < 0) and (ac < 0) and (not na(lastBullFractalLow)) and (close < lastBullFractalLow)

//------------------------------------------
// Enter trades only when there is no active position
//------------------------------------------
if (longCondition and strategy.position_size == 0)
    // Set stop loss: Preferably at the last Bull Fractal; if unavailable, use the Jaw line as a fallback.
    long_stop = not na(lastBullFractalLow) ? lastBullFractalLow : jaw_val
    risk      = close - long_stop
    takeProfit= close + risk * 2  // Risk-to-reward ratio of 1:2
    strategy.entry("Long", strategy.long)
    strategy.exit("Exit Long", "Long", stop=long_stop, limit=takeProfit)
    
if (shortCondition and strategy.position_size == 0)
    short_stop = not na(lastBearFractalHigh) ? lastBearFractalHigh : jaw_val
    risk       = short_stop - close
    takeProfit = close - risk * 2
    strategy.entry("Short", strategy.short)
    strategy.exit("Exit Short", "Short", stop=short_stop, limit=takeProfit)

//------------------------------------------
// 6. Plot Alligator Lines and Fractal Markers
//------------------------------------------
// Plot Alligator lines
plot(showPlot ? jaw_val : na,   color=color.blue,  title="Jaw")
plot(showPlot ? teeth_val : na, color=color.red,   title="Teeth")
plot(showPlot ? lips_val : na,  color=color.green, title="Lips")

// Mark fractals (using an offset of -2 to account for a 2-bar delay)
// Bull Fractal (upward triangle) and Bear Fractal (downward triangle)
plotshape(showPlot ? bullFractalLow : na, title="Bull Fractal Low", style=shape.triangleup, location=location.belowbar, color=color.green, offset=-2, size=size.tiny)
plotshape(showPlot ? bearFractalHigh : na, title="Bear Fractal High", style=shape.triangledown, location=location.abovebar, color=color.red, offset=-2, size=size.tiny)

Overview

Bill Williams NTD Strategy also plots fractals on the chart. Long entries occur when the Alligator is aligned bullish, AO and AC are positive, and price is above the last bear fractal level. Short entries trigger on bearish Alligator alignment with negative AO and AC, and price below the last bull fractal. Trades only open when no position is active. The Alligator lines and fractals provide trend context on the price chart with optional plotting.

Details

Published by

saleh-ato on GitHub

Code credit

Saleh_Toodarvari, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescriptindicatorpinescript-indicators

Settings

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

SettingTypeDefaultVariable
Enable PlotboolfalseshowPlot
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

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

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

SMA RSI Strategy

by PythonForForex
64 stars

This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI Strategy

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