Indicator · Pine Script v4 · On the chart

Turtle Trader

by rocketbrainsurgeon

The Turtle Trader indicator merges Donchian channels with trend detection to classify market state.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code36
Settings2inputs
LicenceGPL-3.0
Last update5 years ago24 Jun 2021

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

36 lines of Pine Script v4 from Turtle.txt, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Turtle.txt
//@version=4
study("Turtle",shorttitle="T",overlay=true)

trend_length = input(title="Trend Length",defval=20)
stop_length = input(title="Stop Length",defval=10)
t_length = bar_index > trend_length ? trend_length : bar_index+1
s_length = bar_index > stop_length ? stop_length : bar_index+1

// === DONCHIAN CHANNEL ===
donchian_channel(l)=>
    t = highest(l)
    b = lowest(l)
    ba = avg(t,b)
    [t,b,ba]

// == CHANNELS ===
[top,bottom,_] = donchian_channel(trend_length)
[stop,sbottom,_] = donchian_channel(stop_length)

// === MARKET STATE ===
expansionUp = high==top
expansionDown = low==bottom
trend = barssince(expansionUp) < barssince(expansionDown or bar_index==0)
trendStart = expansionUp or expansionDown
trendFlip = (trend and not trend[1]) or (trend[1] and not trend)
trendEnd = (trend and low==sbottom) or (not trend and high==stop)
trending = barssince(trendStart) <= barssince(trendEnd or bar_index==0)
rangeStart = (trendEnd and trending[1]) or (trendFlip and trending[1])

// === DISPLAY STRATEGY ===
barcolor(trending and trend ? #2aa599 : trending and not trend ? #ee5451 : not trending ? color.gray : color.gray)
t = plot(top,color=#3bb3e4,linewidth=2,transp=65,title="Upper")
b = plot(bottom,color=#3bb3e4,linewidth=2,transp=65,title="Lower")
plot(stop,color=#3bb3e4,linewidth=2,transp=65)
plot(sbottom,color=#3bb3e4,linewidth=2,transp=65)
fill(t,b,transp=90,color=#3bb3e4,title="Background")

Overview

Turtle Trader computes upper and lower channel levels from recent highs and lows, along with stop levels, and plots them directly on the price chart. Green bars signal upward trends, red bars downward trends, and gray bars ranging conditions. Entry signals follow bar colors: long when green, short when red, and both sides when gray. Primary settings adjust trend length to 20 and stop length to 10. It draws exclusively on the price chart and suits scalping by highlighting clear trend phases.

Details

Published by

rocketbrainsurgeon on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Volatility & bands, Support & resistance

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.

Settings

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

SettingTypeDefaultVariable
Trend Lengthint20trend_length
Stop Lengthint10stop_length
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

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

ATR Trailing Stop

by mihakralj
99 stars

Calculates an ATR-based trailing stop overlaid on the price chart to assist with trend identification and stop placement. Using a specified ATR period and multiplier, it projects upper and lower bounds around the closing price. The stop line ratchets up during

Indicator v5 TrendVolatility & bands
Updated 4 weeks ago · Apache-2.0 GitHub repository of ATR Trailing Stop

Moon Dev Lunar Sniper

by moondevonyt
92 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev Lunar Sniper

SuperTrend & Pivots

by dcaoyuan
55 stars

This overlay indicator plots a SuperTrend line on the price chart using a fixed ATR length of 10 and a factor of 3. When the trend direction is up it draws a green line and a light green fill toward the candle midpoint; when down it draws a red line and a ligh

Indicator v6 TrendVolatility & bands
Updated 6 months ago · Apache-2.0 GitHub repository of SuperTrend & Pivots

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers