Strategy · Pine Script v6 · On the chart

TurtleStrategy_Crypto

by OktayBogazkaya

This strategy trades long breakouts of the highest high over a user-set period.

View on GitHub

GitHub stars6on the repository
Pine versionv6current
Lines of code77
Settings4inputs
LicenceMIT
Last update1 year ago25 Feb 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

77 lines of Pine Script v6 from turtle_strategy_pinescript.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

turtle_strategy_pinescript.txt
// How to add the Pine Script Code to TradingView Chart?
// 1. Open TradingView chart
// 2. Click "Pine Editor" at the bottom
// 3. Copy the code below and paste it in Pine Editor
// 4. Click "Save" in Pine Editor
// 5. Click "Add to Chart" in Pine Editor
// Your indicator will now be displayed on the chart including buy and sell signals

//@version=6
strategy("TurtleStrategy_Crypto", overlay=true, initial_capital=100000)

// Input parameters
periodHigh = input.int(10, "Breakout Period High", minval=1)
atrPeriod = input.int(14, "ATR Period", minval=1)
atrMultiplier = input.float(1, "ATR Multiplier", minval=0.1)
riskPct = input.float(2.0, "Risk Percentage", minval=0.1, maxval=100) / 100
start_date = timestamp("2023-01-01")  // Default start date
end_date = timestamp("2024-12-31")    // Default end date

// Calculate indicators
highestPrice = ta.highest(high, periodHigh)
lowestPrice = ta.lowest(low, periodHigh)
atr = ta.atr(atrPeriod)

// Variables for position management
var float stopPrice = na
var float entryPrice = na
var float highestPriceInTrade = na

// Calculate position size based on risk
calcPositionSize() =>
    dollarVolatility = atr * atrMultiplier
    dollarRisk = strategy.equity * riskPct
    math.floor(dollarRisk / dollarVolatility)

// Date range filter
inDateRange = time >= start_date and time <= end_date

// Entry conditions
isLongEntry = (close > highestPrice[1]) and strategy.position_size == 0 and inDateRange

// Exit conditions
isLongExit = (close < stopPrice or close < lowestPrice[1]) and strategy.position_size > 0 and inDateRange

// Update trailing stop
if strategy.position_size > 0
    highestPriceInTrade := math.max(highestPriceInTrade, close)
    stopPrice := highestPriceInTrade - (atr * atrMultiplier)

// Entry and exit execution
if isLongEntry
    posSize = calcPositionSize()
    if posSize > 0
        strategy.entry("Long", strategy.long, posSize)
        entryPrice := close
        highestPriceInTrade := close
        stopPrice := close - (atr * atrMultiplier)
        alert("Buy, Ticker:" + syminfo.ticker + 
              ", Close: " + str.tostring(close) + 
              ", Position Size: " + str.tostring(posSize))

if isLongExit
    strategy.close("Long")
    highestPriceInTrade := na
    stopPrice := na
    entryPrice := na
    alert("Sell, Ticker:" + syminfo.ticker + 
          ", Close: " + str.tostring(close) + 
          ", Position Size: " + str.tostring(strategy.position_size))

plot(highestPrice, "High Channel", color = color.white)
plot(lowestPrice, "Low Channel", color = color.white)
plot(stopPrice, "Stop Price", color = color.yellow, style = plot.style_cross)

// Plot entry/exit signals
plotshape(isLongEntry ? low : na, "Entry", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(isLongExit ? high : na, "Exit", shape.triangledown, location.abovebar, color.red, size=size.small)

Overview

TurtleStrategy_Crypto enters when the close is above that prior high and the position is flat, then sizes the order from account equity, a risk percentage, and ATR times a multiplier. It exits when the close falls below a trailing ATR stop or below the prior lowest low. High and low channels and the stop plot on the price chart. Short trades are not implemented, and the date window is fixed in code.

Details

Published by

OktayBogazkaya on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Breakout, Volatility & bands

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingpinescripttechnical-analysistrading-strategiesturtle-tradingtradingview-script

Settings

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

SettingTypeDefaultVariable
Breakout Period Highint10periodHigh
ATR Periodint14atrPeriod
ATR Multiplierfloat1atrMultiplier
Risk Percentagefloat2.0riskPct
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

257 stars

This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
106 stars

This strategy runs on the price chart and enters long when a fast simple moving average crosses above a slow one, and short on the opposite cross, while closing the other side. Entries also need ATR above a filter, a pullback check, a minimum candle-body chang

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 9:22 5 MIN 15 MIN BANKNIFTY

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统
16 stars

This trend-following strategy adapts classic Donchian breakout channels according to market volatility regimes. It calculates an ATR percentile rank across a rolling lookback period, shifting dynamically between tighter breakout channels with smaller stops dur

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 1: Adaptive Volatility

This strategy executes breakout trades using two Donchian Channels alongside an optional 200-period EMA trend filter. Entries trigger when the price sets a new highest high or lowest low over the primary Donchian Channel period. Exits are managed via a shorter

Strategy v5 BreakoutTrend
Updated 1 year ago · None stated GitHub repository of Ruckard Walcrypto DoubleDonchian B002

Breakout Strategy

by JoelPasapera
11 stars

This strategy implements a channel breakout system directly on the main price chart. It calculates highest highs and lowest lows over configurable entry and exit periods using historical candles. A long entry triggers when the close breaks above the entry chan

Strategy v6 BreakoutTrend
Updated 5 months ago · Apache-2.0 GitHub repository of Breakout 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