Turtle trend Following Strategy
The turtle-trend following strategy is a quantitative strategy that determines the trend direction based on moving averages and trades at trend reversal points. The strategy also combines candlestick patterns to…

Overview
The turtle-trend following strategy is a quantitative strategy that determines the trend direction based on moving averages and trades at trend reversal points. The strategy also combines candlestick patterns to determine signals and enter and stop loss at potential reversal points.
Strategy Principle
The strategy uses three EMA lines of different cycles to determine the trend direction. Specifically, the 15-day, 120-day, and 220-day EMA lines are calculated. When the 15-day line is higher than the 220-day line, the uptrend is determined. When the 15-day line is lower than the 220-day line, the downtrend is determined.
When in an uptrend, if the closing price is below the 220-day line, go short; when in a downtrend, if the closing price is above the 220-day line, go long.
At the same time, the strategy also combines candlestick patterns to confirm signals. When there is a bullish big gap candlestick or a bearish big gap candlestick, the position is closed to stop loss.
Advantage Analysis
The biggest advantage of this strategy is that it can follow the trend to operate, avoiding reverse operations without clear signals. By judging the trend with multiple moving averages, market noise can be effectively filtered to lock the main trend direction.
At the same time, the strategy will also enter at potential trend reversal points, which has very good risk-reward characteristics at this time. And combining candlesticks to stop loss can avoid too fragmented stop loss points.
Risk Analysis
The main risk of this strategy is that the trend determined by the moving average may lag behind the actual price movement. At this time, reverse operations against the trend may occur.
In addition, the candlestick patterns used in the strategy may also fail and cannot stop loss effectively. When there is abnormal market fluctuation, the stop loss point may be directly penetrated, resulting in greater losses.
To reduce the above risks, consider adjusting the cycle parameters of the moving average, or adjusting the proportional factor for determining the candlestick pattern to make the rules stricter. Of course, it also needs to be aware that technical analysis can never completely avoid market risk, and position size needs to be controlled.
Optimization Directions
The strategy can be optimized in the following aspects:
Optimize the cycle parameters of the moving average to find a more suitable combination of parameters to judge the trend
Test different types of moving average indicators, such as SMA, LWMA, etc., to find indicators that match your own style
Adjust or add candlestick judgment rules to make reversal signals clearer and more reliable
Add stop loss strategies, such as trailing stop loss, time stop loss, etc., to further control single loss
Combine other indicators, such as volatility indicators, trading volume, etc., to enrich the trading signals of the system
Summary
The turtle-trend following strategy is a very typical trend following strategy overall. Its method of judging the trend is simple and easy to implement, while also having certain risk control measures. This strategy is suitable for investors who have some understanding of trend trading and hope to obtain stable returns. If continuously optimized, it can also become a quantitative strategy with long-term competitive advantages.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_3 | 50 | Calculation period |
| v_input_bool_1 | true | (?Backtest range) Enable backtest time range limitation |
| v_input_1 | timestamp(1 Jan 2015) | Start time |
| v_input_2 | timestamp(1 Jan 2040) | End time |
| v_input_int_1 | 15 | (?Market average cost) Short-term market average cost |
| v_input_int_2 | 120 | Medium-term market average cost |
| v_input_int_3 | 220 | Long-term market average cost |
Source Pine Script
/*backtest
start: 2023-12-14 00:00:00
end: 2023-12-21 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// © Aayonga
//@version=5
strategy('Sailing adventure searching for legends', overlay=true)
useDateFilter=input.bool(true,title = "Enable backtest time range limitation", group = "Backtest range")
backtesStarDate=input(timestamp("1 Jan 2015"),title = "Start time")
backtestEndDate=input(timestamp("1 Jan 2040"),title = "End time")
inTradeWindow= true
A = input(50, 'Calculation period')
shallowsea = ta.highest(A)
deepsea= ta.lowest(A)
//Trend formation conditions
Length1 = input.int(15, title='Short-term market average cost', minval=1, group='Market average cost')
Length2 = input.int(120, title='Medium-term market average cost', minval=1, group='Market average cost')
Length3 = input.int(220, title='Long-term market average cost', minval=1, group='Market average cost')
SMA1 = ta.ema(close, Length1)
SMA2 = ta.sma(close, Length2)
SMA3 = ta.sma(close, Length3)
//Bullish trend
longTrend=SMA1>SMA3 and open >SMA3
shortTrend=SMA1<SMA3
bullPinBar = ((close > open) and ((open - low) > 0.66* (high - low))) or ((close < open) and ((close - low) > 0.9 * (high - low)))
bearPinBar = ((close > open) and ((high - close) > 0.75 * (high - low))) or ((close < open) and ((high - open) >0.9 * (high - low)))
if close > shallowsea[5] and shortTrend and inTradeWindow
strategy.entry('⛵?', strategy.short)
if close < deepsea[5] and longTrend and inTradeWindow
strategy.entry('?', strategy.long)
if bullPinBar and inTradeWindow
strategy.close('⛵?',comment = '?')
if bearPinBar and inTradeWindow
strategy.close('?',comment = '?')
plot(shallowsea,style=plot.style_area, color=color.new(#71bfef, 0))
plot(deepsea, style=plot.style_area,color=color.new(#298bd1, 0))
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-22. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Turtle-trend-Following-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h
- BB Breakout StrategyPine Script · Breakout · 1d
- BMSB Breakout Strategy BMSBPine Script · Breakout · 1h
- Bollinger Band T3 Moving Average StrategyPine Script · Breakout · 10m
- Bollinger Bands Dual track Breakthrough StrategyPine Script · Breakout · 30m
- Bollinger Breakout StrategyPine Script · Breakout · 30m