Turtle Breakout EMA Cross Strategy
This strategy uses two EMA lines of different periods to identify trend reversals through their crossovers as entry and exit signals. The strategy is simple and easy to implement.

Overview
This strategy uses two EMA lines of different periods to identify trend reversals through their crossovers as entry and exit signals. The strategy is simple and easy to implement.
Strategy Logic
The strategy calculates two EMA lines using ta.ema, one with length 10 for short term and one with length 20 for long term trend. It identifies EMA crossovers and crossunders using ta.crossover and ta.crossunder to determine entry and exit points. When the short EMA crosses over the long EMA, it goes long. When the short EMA crosses under the long EMA, it goes short. This way the EMA crossovers are used to capture turning points in the trend.
The strategy also uses a variable lastCrossTime to record the time of the last crossover to avoid repeated signals. On each valid crossover, it closes all current positions first, then opens a new position in the direction of the crossover. After opening the position, take profit and stop loss are set to exit.
Advantages
The strategy logic is simple and clear, easy to understand and implement.
Using EMA crossovers to identify trend reversal points is a commonly used effective technical indicator strategy.
Adopting EMAs of different periods helps improve sensitivity to short term moves while still catching big trends.
Take profit and stop loss helps control the risk and reward of each trade.
The lastCrossTime variable filters duplicate signals and avoids unnecessary trades.
Risks
EMA crossovers can generate false signals, with some whipsaw risk.
Fixed TP and SL may fail to adapt to changing market conditions. Dynamic levels should be used.
Systems relying solely on EMA crossover can suffer losses in ranging markets.
Trading costs like spread are not considered which impacts actual performance.
The strategy works better in trending rather than ranging markets.
Improvements can be made via optimizing TP/SL, adding filters, combining other indicators etc. Strict risk control and avoiding large single trade loss is essential for live trading.
Enhancement
Test and optimize EMA periods to find better combinations.
Add other indicators like KDJ, MACD etc. to improve signal quality and avoid whipsaws.
Use dynamic take profit and stop loss, such as trailing stop along the trend.
Consider trading volume to confirm the signals.
Incorporate price action patterns like breakouts to strengthen signals.
Account for trading costs like spread and optimize TP/SL levels accordingly.
Conclusion
The strategy identifies trend reversals using EMA crossovers in a simple and straightforward way. TP/SL are used to control risks and rewards. It is easy to implement but EMA crossovers have whipsaw risks. Further optimizations can be done by tuning parameters, adding filters and combining other indicators to improve robustness. It performs better in trending rather than ranging markets. Strict risk management and optimal TP/SL sizing is crucial for live trading. Overall it serves as a basic trend following system and is a good starting point for algorithmic trading education.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 10 | Length EMA Short |
| v_input_int_2 | 20 | Length EMA Long |
| v_input_int_3 | true | Lot Size |
| v_input_int_4 | 600 | Take Profit Level |
| v_input_int_5 | 200 | Stop Loss Level |
Source Pine Script
/*backtest
start: 2023-10-30 00:00:00
end: 2023-11-06 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy('XXXquang', overlay=true)
// Sử dụng hàm input.int() và input.float() để tạo các trường nhập liệu với giới hạn giá trị
length1 = input.int(10, title="Length EMA Short", minval=1)
length2 = input.int(20, title="Length EMA Long", minval=1)
lotSize = input.int(1, title="Lot Size", minval=1)
takeProfitLevel = input.int(600, title="Take Profit Level", minval=1)
stopLossLevel = input.int(200, title="Stop Loss Level", minval=1)
ema1 = ta.ema(close, length1)
ema2 = ta.ema(close, length2)
var float lastCrossTime = na
if ta.crossover(ema1, ema2)
if na(lastCrossTime)
strategy.close_all()
strategy.entry('Buy Order', strategy.long, qty=lotSize)
strategy.exit('Exit Buy', 'Buy Order', profit=takeProfitLevel / syminfo.pointvalue, loss=stopLossLevel / syminfo.pointvalue)
lastCrossTime := timenow
if ta.crossunder(ema1, ema2)
if na(lastCrossTime)
strategy.close_all()
strategy.entry('Sell Order', strategy.short, qty=lotSize)
strategy.exit('Exit Sell', 'Sell Order', profit=takeProfitLevel / syminfo.pointvalue, loss=stopLossLevel / syminfo.pointvalue)
lastCrossTime := timenow
plot(ema1, title='EMA Short', color=color.new(color.blue, 0), linewidth=2)
plot(ema2, title='EMA Long', color=color.new(color.red, 0), linewidth=2)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-07. 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-Breakout-EMA-Cross-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
- Bull Market Tracking SystemPine Script · Breakout · 1h
- Dual Breakout Volatility Channel StrategyPine Script · Breakout · 1h
- Dual Moving Average Breakthrough StrategyPine Script · Breakout · 1d
- EMA MACD Quantitative Strategy With Dual Track Running and Leading the Market IndexPine Script · Breakout · 1d
- Kana Candle Breakout Strategy Based on Moving Average and Support ResistancePine Script · Breakout · 1h
- MA Trendline Breakthrough StrategyPine Script · Breakout · 1d