Strategy vault / Trend following
Candlestick Body Based Dual Thrust Strategy
This strategy uses the length of the candlestick body to determine the long and short direction. It calculates the average body length of the recent 30 candlesticks. When the bullish candle body length is greater…

Overview
This strategy uses the length of the candlestick body to determine the long and short direction. It calculates the average body length of the recent 30 candlesticks. When the bullish candle body length is greater than average, it goes long. When the bearish candle body length is greater than average, it goes short.
Strategy Logic
This strategy first calculates the candlestick body length body and the average body length of recent 30 candlesticks sbody.
When today's candlestick is bearish (bar==-1) and the body length is greater than average body length, it opens long position (up1).
When today's candlestick is bullish (bar==1) and the body length is greater than average body length, it opens short position (dn1).
After opening long, if today's candlestick is bullish (bar==1) and the current position is profitable, it closes long position.
After opening short, if today's candlestick is bearish (bar==-1) and the current position is profitable, it closes short position.
The strategy simply and effectively uses the candlestick body length to determine the market trend. The longer the body, the stronger the trend. So it uses body length as the criterion for long and short.
Advantage Analysis
The advantages of this strategy:
The logic is simple and clear, easy to understand and implement.
Using candlestick body length to determine trend, avoid noise interference.
Adopt dynamic average calculation, can adapt to market changes.
Set profitable exit condition to improve profitability.
Configurable parameters, adaptable to different market environments.
Risk Analysis
The risks of this strategy:
Long body does not necessarily represent strong trend, could be normal fluctuation.
Improper average body length time window may miss trading opportunities.
Black swan events may cause losses.
Holding positions for too long may amplify losses.
Solutions:
Combine with other indicators to determine trend, avoid wrong trades.
Test different parameter values, optimize average body length calculation.
Set stop loss to control single loss.
Optimize entry and exit logic to avoid holding too long.
Optimization Directions
The strategy can be optimized in the following aspects:
Combine MACD, RSI to determine trend, avoid wrong signals from normal fluctuations.
Test different average body length time window parameters to find optimal parameter set.
Add position sizing control logic, gradually reduce position size when incurring losses.
Set trailing stop loss or profit target to control single loss percentage.
Optimize entry and exit conditions to avoid ineffective trades. For example, wait for 3 consecutive long candlesticks before entering.
Avoid trading at certain periods or around important data release to control loss from volatility.
Conclusion
The strategy has clear and easy-to-understand logic of comparing candlestick body to its average length for entry timing. Large room for optimization from multiple dimensions to tailor it better for different market environments. Overall a simple and reliable introductory quant trading strategy suitable for novice traders to use and learn. Further combine more indicators and optimize to improve profitability and robustness.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | true | Long |
| v_input_2 | true | Short |
| v_input_3 | true | Use body |
| v_input_4 | 1900 | From Year |
| v_input_5 | 2100 | To Year |
| v_input_6 | true | From Month |
| v_input_7 | 12 | To Month |
| v_input_8 | true | From day |
| v_input_9 | 31 | To day |
Source Pine Script
/*backtest
start: 2023-10-16 00:00:00
end: 2023-11-15 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//Noro
//2018
//@version=3
strategy(title = "Noro's ColorBar Strategy v1.0", shorttitle = "ColorBar str v1.0", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100.0, pyramiding = 0)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
usebody = input(true, defval = true, title = "Use body")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")
//Signals
bar = close > open ? 1 : close < open ? - 1 : 0
body = abs(close - open)
sbody = ema(body, 30)
up1 = bar == -1 and (body > sbody or usebody == false)
dn1 = bar == 1 and (body > sbody or usebody == false)
plus = (close > strategy.position_avg_price and strategy.position_size > 0) or (close < strategy.position_avg_price and strategy.position_size < 0)
exit = ((strategy.position_size > 0 and bar == 1) or (strategy.position_size < 0 and bar == -1)) and plus
if up1
strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, 01, 00, 00) and time < timestamp(toyear, tomonth, 31, 00, 00)))
if dn1
strategy.entry("Short", strategy.short, needshort == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, 01, 00, 00) and time < timestamp(toyear, tomonth, 31, 00, 00)))
if time > timestamp(toyear, tomonth, 31, 00, 00) or exit
strategy.close_all()Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-16. 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/Candlestick-Body-Based-Dual-Thrust-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 ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Advanced Multi Indicator Multi Dimensional Trend Cross Quantitative StrategyPine Script · Trend following · 3h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dynamic Dual EMA Crossover Strategy with Adaptive Profit Loss ControlPine Script · Trend following · 1d
- EMA SMA Multi Indicator Comprehensive Trend Following StrategyPine Script · Trend following · 1h