Triangle Breakout Trend Following Strategy
This is a trend following strategy. It goes long when price breaks out of an ascending triangle formation, and closes position when fast EMA crosses below medium EMA. Stop loss and take profit are also set to control…
Overview
This is a trend following strategy. It goes long when price breaks out of an ascending triangle formation, and closes position when fast EMA crosses below medium EMA. Stop loss and take profit are also set to control risks.
Strategy Logic
Use fast EMA and medium EMA to determine trend direction. Fast EMA crossing above medium EMA is long signal.
Use highest and lowest prices of last N bars to determine if an ascending triangle is formed. Triangle formation gives long signal.
After entry, when fast EMA crosses below medium EMA, it indicates trend reversal and gives exit signal.
Set stop loss at certain percentage below entry price for stop loss exit.
Set take profit target at certain percentage above entry price for partial profit taking.
Use 200-day EMA to determine overall trend direction, only trade when trend is up.
Advantage Analysis
Triangle formation filters false breakout and improves entry accuracy.
Fast EMA vs medium EMA reasonably divides trend and consolidation to avoid whipsaws.
Reasonable stop loss and take profit settings control single trade loss.
Only trading in uptrend avoids choppy periods.
Risk Analysis
Too narrow triangle range may miss trends, while too wide range may increase unnecessary trades. Parameter N needs to be optimized.
Stop loss too close tends to get stopped out prematurely, while too wide fails to control loss. Evaluate and optimize parameter.
Improper partial take profit setting may lead to profit overflow. Evaluate proper ratio.
Wrong trend indicator parameters may lead to wrong position direction. Multi-product backtest optimization needed.
Improvement Directions
Optimize parameter N for triangle determination to find optimum value.
Test different EMA period combinations to improve trend accuracy.
Optimize stop loss and take profit parameters based on product characteristics.
Add other indicators like MACD pattern, Bollinger breakout etc to improve signal quality.
Add reopen mechanism to extend profit when trend continues.
Summary
The strategy is overall robust with triangle formation improving signal accuracy. Large parameter optimization space exists for further enhancement. Also try adding more auxiliary indicators or improving stop loss/take profit for greater efficacy. Overall this strategy has the potential to become a quality trend following strategy.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 9 | Number of Bars |
| v_input_2 | 13 | fast EMA |
| v_input_3 | 65 | slow EMA |
| v_input_4 | 5 | Stop Loss% |
Source Pine Script
/*backtest
start: 2023-08-20 00:00:00
end: 2023-09-19 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mohanee
//@version=4
strategy(title="TrianglePoint strategy", overlay=true,pyramiding=2, default_qty_value=3, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)
// variables BEGIN
numPeriods=input(9,title="Number of Bars")
fastEMA = input(13, title="fast EMA", minval=1)
slowEMA = input(65, title="slow EMA", minval=1)
stopLoss = input(title="Stop Loss%", defval=5, minval=1)
HH = highest(close[1],numPeriods)
LL = lowest(close[1],numPeriods)
tringlePoint = low > LL and high < HH
fastEMAval= ema(close, fastEMA)
slowEMAval= ema(close, slowEMA)
two100EMAval= ema(close, 200)
//plot emas
plot(fastEMAval, color = color.green, linewidth = 1, transp=0)
plot(slowEMAval, color = color.orange, linewidth = 1, transp=0)
plot(two100EMAval, color = color.purple, linewidth = 2, transp=0)
longCondition=fastEMAval>two100EMAval and tringlePoint
//plotshape(triP,style=shape.triangleup,text="Buy",color=color.green,location=location.belowbar)
//plotshape(longCondition,style=shape.triangleup,text="Buy",color=color.green,location=location.belowbar)
//Entry
strategy.entry(id="TBT LE", comment="TBT LE" , long=true, when= longCondition and strategy.position_size<1)
//Add
strategy.entry(id="TBT LE", comment="Add" , long=true, when= longCondition and strategy.position_size>=1 and close<strategy.position_avg_price)
//barcolor(strategy.position_size>=1 ? color.blue : na)
//Take profit
takeProfitVal= strategy.position_size>=1 ? (strategy.position_avg_price * (1+(stopLoss*0.01) )) : 0.00
//strategy.close(id="TBT LE", comment="Profit Exit", qty=strategy.position_size/2, when=close>=takeProfitVal and close<open and close<fastEMAval) //crossunder(close,fastEMAval)
barcolor(strategy.position_size>=1 ? (close>takeProfitVal? color.purple : color.blue): na)
//Exit
strategy.close(id="TBT LE", comment="TBT Exit", when=crossunder(fastEMAval,slowEMAval))
//stoploss
stopLossVal= strategy.position_size>=1 ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00
//stopLossVal= close> (strategy.position_avg_price * (1+(stopLoss*0.01) )) ? lowest(close,numPeriods) : (strategy.position_avg_price * (1-(stopLoss*0.01) ))
strategy.close(id="TBT LE", comment="SL Exit", when= close < stopLossVal)Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-20. 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/Triangle-Breakout-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
- Momentum Breakout Moving Average StrategyPine Script · Breakout · 1d
- Momentum Breakout Trading Strategy 440964Pine Script · Breakout · 5m
- Momentum Breakout Trading StrategyPine Script · Breakout · 4h
- Moving Average Crossover and Upper Rail Breakthrough Impulse StrategyPine Script · Breakout · 1m
- Multiple Moving Average Bollinger Bands StrategyPine Script · Breakout · 1d
- Quadruple Crossing StrategyPine Script · Breakout · 1h