Strategy · Pine Script v6 · On the chart

TRAMA Turtle

by dwightspitz

A strategy that draws a triple Hull moving average cloud and up to five TRAMA adaptive average clouds on the price chart, each with its own length, delay and timeframe.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code201
Settings27inputs
LicenceMIT
Last update2 months ago31 Aug 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

201 lines of Pine Script v6 from TRAMA_Turtle.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

TRAMA_Turtle.pine
//@version=6
strategy("TRAMA Turtle", overlay=true, default_qty_type=strategy.percent_of_equity, pyramiding=10, process_orders_on_close=true)

// ===== INPUT PARAMETERS =====

// THMA Cloud Settings
enable_hma_cloud = input.bool(true, "Enable THMA Cloud", group="THMA Cloud")
hma_length = input.int(50, "THMA Length", minval=1, group="THMA Cloud")
hma_delay = input.int(2, "THMA Delay", minval=1, group="THMA Cloud")
hma_timeframe = input.timeframe("", "THMA Timeframe", tooltip="Leave blank to use chart timeframe", group="THMA Cloud")

// TRAMA Cloud Settings
enable_trama_cloud = input.bool(true, "Enable TRAMA Cloud", group="TRAMA Cloud")
trama_length = input.int(20, "TRAMA Length", minval=1, group="TRAMA Cloud")
trama_delay = input.int(2, "TRAMA Delay", minval=1, group="TRAMA Cloud")
trama_timeframe = input.timeframe("", "TRAMA Timeframe", tooltip="Leave blank to use chart timeframe", group="TRAMA Cloud")

// TRAMA 2 Settings
enable_trama2_cloud = input.bool(false, "Enable TRAMA 2 Cloud", group="TRAMA 2")
trama2_length = input.int(50, "TRAMA 2 Length", minval=1, group="TRAMA 2")
trama2_delay = input.int(2, "TRAMA 2 Delay", minval=1, group="TRAMA 2")
trama2_timeframe = input.timeframe("", "TRAMA 2 Timeframe", tooltip="Leave blank to use chart timeframe", group="TRAMA 2")

// TRAMA 3 Settings
enable_trama3_cloud = input.bool(false, "Enable TRAMA 3 Cloud", group="TRAMA 3")
trama3_length = input.int(100, "TRAMA 3 Length", minval=1, group="TRAMA 3")
trama3_delay = input.int(2, "TRAMA 3 Delay", minval=1, group="TRAMA 3")
trama3_timeframe = input.timeframe("", "TRAMA 3 Timeframe", tooltip="Leave blank to use chart timeframe", group="TRAMA 3")

// TRAMA 4 Settings
enable_trama4_cloud = input.bool(false, "Enable TRAMA 4 Cloud", group="TRAMA 4")
trama4_length = input.int(150, "TRAMA 4 Length", minval=1, group="TRAMA 4")
trama4_delay = input.int(2, "TRAMA 4 Delay", minval=1, group="TRAMA 4")
trama4_timeframe = input.timeframe("", "TRAMA 4 Timeframe", tooltip="Leave blank to use chart timeframe", group="TRAMA 4")

// TRAMA 5 Settings
enable_trama5_cloud = input.bool(false, "Enable TRAMA 5 Cloud", group="TRAMA 5")
trama5_length = input.int(200, "TRAMA 5 Length", minval=1, group="TRAMA 5")
trama5_delay = input.int(2, "TRAMA 5 Delay", minval=1, group="TRAMA 5")
trama5_timeframe = input.timeframe("", "TRAMA 5 Timeframe", tooltip="Leave blank to use chart timeframe", group="TRAMA 5")

// ATR Position Sizing Settings
atr_length = input.int(3920, "ATR Length", minval=1, group="ATR Position Sizing")
use_atr_sizing = input.bool(true, "Use ATR Position Sizing", group="ATR Position Sizing")
atr_add_multiple = input.float(0.5, "ATR Add Multiple", minval=0.1, step=0.1, group="ATR Position Sizing", tooltip="Add to position every X ATR move")

// ===== HELPER FUNCTIONS =====

// Triple Hull Moving Average (THMA)
thma(src, length) =>
    hma1 = ta.wma(2 * ta.wma(src, length / 2) - ta.wma(src, length), math.round(math.sqrt(length)))
    hma2 = ta.wma(2 * ta.wma(hma1, length / 2) - ta.wma(hma1, length), math.round(math.sqrt(length)))
    ta.wma(2 * ta.wma(hma2, length / 2) - ta.wma(hma2, length), math.round(math.sqrt(length)))

// TRAMA CALCULATION FUNCTION
trama_calc(src, length) =>
    var float ama = na
    hh = math.max(math.sign(ta.change(ta.highest(length))), 0)
    ll = math.max(math.sign(ta.change(ta.lowest(length)) * -1), 0)
    tc = math.pow(ta.sma((hh + ll) > 0 ? 1 : 0, length), 2)
    ama := nz(ama[1] + tc * (src - ama[1]), src)
    ama

// ===== INDICATOR CALCULATIONS =====

// Helper function to get close data from timeframe (or chart if blank)
get_tf_close(tf) =>
    tf == "" ? close : request.security(syminfo.tickerid, tf, close)

// Get THMA data from selected timeframe
hma_close = get_tf_close(hma_timeframe)
thma_current = enable_hma_cloud ? thma(hma_close, hma_length) : na
hma1 = thma_current
hma2 = enable_hma_cloud ? thma_current[hma_delay] : na

// Get TRAMA data from selected timeframe
trama_close = get_tf_close(trama_timeframe)
trama_current = enable_trama_cloud ? trama_calc(trama_close, trama_length) : na
trama1 = trama_current
trama2 = enable_trama_cloud ? trama_current[trama_delay] : na

// Get TRAMA 2 data from selected timeframe
trama2_close = get_tf_close(trama2_timeframe)
trama2_current = enable_trama2_cloud ? trama_calc(trama2_close, trama2_length) : na
trama2_1 = trama2_current
trama2_2 = enable_trama2_cloud ? trama2_current[trama2_delay] : na

// Get TRAMA 3 data from selected timeframe
trama3_close = get_tf_close(trama3_timeframe)
trama3_current = enable_trama3_cloud ? trama_calc(trama3_close, trama3_length) : na
trama3_1 = trama3_current
trama3_2 = enable_trama3_cloud ? trama3_current[trama3_delay] : na

// Get TRAMA 4 data from selected timeframe
trama4_close = get_tf_close(trama4_timeframe)
trama4_current = enable_trama4_cloud ? trama_calc(trama4_close, trama4_length) : na
trama4_1 = trama4_current
trama4_2 = enable_trama4_cloud ? trama4_current[trama4_delay] : na

// Get TRAMA 5 data from selected timeframe
trama5_close = get_tf_close(trama5_timeframe)
trama5_current = enable_trama5_cloud ? trama_calc(trama5_close, trama5_length) : na
trama5_1 = trama5_current
trama5_2 = enable_trama5_cloud ? trama5_current[trama5_delay] : na

// ===== ATR POSITION SIZING =====

// Calculate True Range (Turtle method)
tr = math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1]))

// Calculate ATR using SMA (Turtle method)
atr = ta.sma(tr, atr_length)

// Normalize ATR to percentage of close price
n_atr = (atr / close)

// Calculate percent of equity to risk
poe = n_atr * 100

// Calculate position size in contracts
position_qty = use_atr_sizing ? (strategy.equity * (poe / 100)) / close : 1
add_qty = position_qty / 2

// ===== PLOTTING =====

// Plot THMA Cloud
hma1_plot = plot(enable_hma_cloud ? hma1 : na, "THMA", color=color.new(color.green, 0), linewidth=2)
hma2_plot = plot(enable_hma_cloud ? hma2 : na, "THMA[2]", color=color.new(color.red, 0), linewidth=2)
fill(hma1_plot, hma2_plot, color=enable_hma_cloud and hma1 > hma2 ? color.new(color.green, 80) : color.new(color.red, 80), title="THMA Cloud")

// Plot TRAMA Cloud
trama1_plot = plot(enable_trama_cloud ? trama1 : na, "TRAMA Fast", color=color.new(color.blue, 0), linewidth=2)
trama2_plot = plot(enable_trama_cloud ? trama2 : na, "TRAMA Slow", color=color.new(color.orange, 0), linewidth=2)
fill(trama1_plot, trama2_plot, color=enable_trama_cloud and trama1 > trama2 ? color.new(color.blue, 80) : color.new(color.orange, 80), title="TRAMA Cloud")

// Plot TRAMA 2 Cloud
trama2_1_plot = plot(enable_trama2_cloud ? trama2_1 : na, "TRAMA 2 Fast", color=color.new(color.purple, 0), linewidth=2)
trama2_2_plot = plot(enable_trama2_cloud ? trama2_2 : na, "TRAMA 2 Slow", color=color.new(color.yellow, 0), linewidth=2)
fill(trama2_1_plot, trama2_2_plot, color=enable_trama2_cloud and trama2_1 > trama2_2 ? color.new(color.purple, 80) : color.new(color.yellow, 80), title="TRAMA 2 Cloud")

// Plot TRAMA 3 Cloud
trama3_1_plot = plot(enable_trama3_cloud ? trama3_1 : na, "TRAMA 3 Fast", color=color.new(color.aqua, 0), linewidth=2)
trama3_2_plot = plot(enable_trama3_cloud ? trama3_2 : na, "TRAMA 3 Slow", color=color.new(color.maroon, 0), linewidth=2)
fill(trama3_1_plot, trama3_2_plot, color=enable_trama3_cloud and trama3_1 > trama3_2 ? color.new(color.aqua, 80) : color.new(color.maroon, 80), title="TRAMA 3 Cloud")

// Plot TRAMA 4 Cloud
trama4_1_plot = plot(enable_trama4_cloud ? trama4_1 : na, "TRAMA 4 Fast", color=color.new(color.lime, 0), linewidth=2)
trama4_2_plot = plot(enable_trama4_cloud ? trama4_2 : na, "TRAMA 4 Slow", color=color.new(color.fuchsia, 0), linewidth=2)
fill(trama4_1_plot, trama4_2_plot, color=enable_trama4_cloud and trama4_1 > trama4_2 ? color.new(color.lime, 80) : color.new(color.fuchsia, 80), title="TRAMA 4 Cloud")

// Plot TRAMA 5 Cloud
trama5_1_plot = plot(enable_trama5_cloud ? trama5_1 : na, "TRAMA 5 Fast", color=color.new(color.navy, 0), linewidth=2)
trama5_2_plot = plot(enable_trama5_cloud ? trama5_2 : na, "TRAMA 5 Slow", color=color.new(color.olive, 0), linewidth=2)
fill(trama5_1_plot, trama5_2_plot, color=enable_trama5_cloud and trama5_1 > trama5_2 ? color.new(color.navy, 80) : color.new(color.olive, 80), title="TRAMA 5 Cloud")

// ===== STRATEGY LOGIC =====

// Track position entry levels for pyramiding
var float last_add_price = na
var float last_add_atr = na

// Entry: Price crosses above ANY fast (current) line
entry_signal = ta.crossover(close, hma1) or
               ta.crossover(close, trama1) or
               ta.crossover(close, trama2_1) or
               ta.crossover(close, trama3_1) or
               ta.crossover(close, trama4_1) or
               ta.crossover(close, trama5_1)

// Exit: Price crosses below ANY slow (delayed) line
exit_signal = ta.crossunder(close, hma2) or
              ta.crossunder(close, trama2) or
              ta.crossunder(close, trama2_2) or
              ta.crossunder(close, trama3_2) or
              ta.crossunder(close, trama4_2) or
              ta.crossunder(close, trama5_2)

// Check if price has moved enough to add to position
bool add_signal = false
if strategy.position_size > 0 and not na(last_add_price) and not na(last_add_atr)
    price_move = close - last_add_price
    atr_threshold = last_add_atr * atr_add_multiple
    add_signal := price_move >= atr_threshold

// Execute initial entry
if entry_signal and strategy.position_size == 0
    strategy.entry("Long", strategy.long, qty=position_qty)
    last_add_price := close
    last_add_atr := atr

// Add to position at 0.5 ATR intervals
if add_signal
    strategy.entry("Long", strategy.long, qty=add_qty)
    last_add_price := close
    last_add_atr := atr

// Exit position
if exit_signal and strategy.position_size > 0
    strategy.close("Long")
    last_add_price := na
    last_add_atr := na

Overview

Only the Hull and first TRAMA clouds are on by default. It includes ATR-based position sizing that adds to a position after each set multiple of ATR, in the style of Turtle trading. Pyramiding allows up to ten entries and no stop loss was found.

Details

Published by

dwightspitz on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Enable THMA Cloudbooltrueenable_hma_cloud
THMA Lengthint50hma_length
THMA Delayint2hma_delay
THMA Timeframetimeframehma_timeframe
Enable TRAMA Cloudbooltrueenable_trama_cloud
TRAMA Lengthint20trama_length
TRAMA Delayint2trama_delay
TRAMA Timeframetimeframetrama_timeframe
Enable TRAMA 2 Cloudboolfalseenable_trama2_cloud
TRAMA 2 Lengthint50trama2_length
TRAMA 2 Delayint2trama2_delay
TRAMA 2 Timeframetimeframetrama2_timeframe
Show all 27 settings
SettingTypeDefaultVariable
Enable TRAMA 3 Cloudboolfalseenable_trama3_cloud
TRAMA 3 Lengthint100trama3_length
TRAMA 3 Delayint2trama3_delay
TRAMA 3 Timeframetimeframetrama3_timeframe
Enable TRAMA 4 Cloudboolfalseenable_trama4_cloud
TRAMA 4 Lengthint150trama4_length
TRAMA 4 Delayint2trama4_delay
TRAMA 4 Timeframetimeframetrama4_timeframe
Enable TRAMA 5 Cloudboolfalseenable_trama5_cloud
TRAMA 5 Lengthint200trama5_length
TRAMA 5 Delayint2trama5_delay
TRAMA 5 Timeframetimeframetrama5_timeframe
ATR Lengthint3920atr_length
Use ATR Position Sizingbooltrueuse_atr_sizing
ATR Add Multiplefloat0.5atr_add_multiple
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 2 days ago · 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 7 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

EMA Crossover Strategy

by TradersPost
228 stars

EMA Crossover Strategy plots a fast and a slow exponential moving average on the price chart. It treats a confirmed fast-over-slow cross as a long condition and a confirmed cross under as a short condition. Position size is a percentage of equity. Optional per

Strategy v6 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of EMA Crossover Strategy

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers