Strategy vault / Trend following
Trend Following Strategy Based on Candlestick Direction
This strategy generates long or short signals based on the relationship between the closing price and opening price of candlesticks to determine the current trend direction. Specifically, if the closing price is…

Overview
This strategy generates long or short signals based on the relationship between the closing price and opening price of candlesticks to determine the current trend direction. Specifically, if the closing price is higher than the opening price, a long signal is generated. If the closing price is lower than the opening price, a short signal is generated.
Strategy Logic
The strategy mainly relies on the following two conditions to generate trading signals:
Entry signal logic: If the closing price is higher than the opening price (close > open) and it has reached the opening hour, a long signal is generated. If the closing price is lower than the opening price (close < open) and it has reached the opening hour, a short signal is generated.
Exit conditions: Contrary to entry signals, if already long, the loss condition is closing price below opening price plus ATR value, profit condition is closing price higher than opening price plus ATR multiplied by profit ratio. Vice versa if already short.
With this design, this strategy leverages the directional information from candlesticks to determine trend direction and timely follows the trend. Also, the stop loss and take profit standards dynamically adapt based on ATR, avoiding issues with fixed values.
Advantages
The biggest advantage of this strategy is the strong trend following capability utilizing candlestick direction. Entry signals are simple and clear, combined with opening hour condition to avoid overnight risks. Stop loss and take profit standards change dynamically to auto adjust position sizing.
Overall, this strategy has quick reaction and strong tracking ability, suitable for catching trends on middle timeframes like 1H, 4H.
Risks
Main risks of this strategy include:
High trading frequency, easily affected by transaction costs and slippage. Can optimize by adjusting profit ratio.
Wrong signals may happen if candlestick divergence occurs. Can filter with other indicators.
ATR parameter settings affect stop loss/take profit performance. ATR length and profit ratio need market adjustment.
Opening hour setting also impacts signal quality. Different markets need different opening hour.
Optimization
Aspects that this strategy can further optimize on:
Add filters like moving averages to handle wrong signals from price fluctuations.
Incorporate position sizing to control single bet size based on volatility.
Utilize machine learning to dynamically optimize stop loss/take profit parameters to adapt to the market.
Judge market sentiment using indicators to manage overall position.
Conclusion
In summary, this strategy has quick reaction and effectively catches trends. It determines direction and generates signals simply based on relationship between candlestick closing and opening prices. Also, dynamic ATR is used for stop loss/take profit standards to adjust position sizing based on volatility. Huge potential to further optimize by adding filters and fine tuning parameters.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 9 | Start Hour for Entries |
| v_input_2 | true | Activate Long |
| v_input_3 | true | Activate Short |
| v_input_4 | 1.5 | Take Profit Ratio |
Source Pine Script
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Go with Trend Strategy", overlay=true)
// Input settings
startHour = input(9, title="Start Hour for Entries")
activateLong = input(true, title="Activate Long")
activateShort = input(true, title="Activate Short")
takeProfitRatio = input(1.5, title="Take Profit Ratio")
// Calculate ATR
atrLength = 14 // You can change this value as needed
atrValue = ta.atr(atrLength)
// Calculate entry conditions
enterLong = close > open and hour >= startHour
enterShort = close < open and hour >= startHour
// Strategy logic
if (activateLong and enterLong)
strategy.entry("Long", strategy.long)
if (activateShort and enterShort)
strategy.entry("Short", strategy.short)
// Stop loss and take profit conditions
strategy.exit("Exit Long", from_entry="Long", loss=close - atrValue, profit=close + takeProfitRatio * atrValue)
strategy.exit("Exit Short", from_entry="Short", loss=close + atrValue, profit=close - takeProfitRatio * atrValue)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-19. 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/Trend-Following-Strategy-Based-on-Candlestick-Direction.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
- ATR Dynamic Profit Target and Stop Loss StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- ATR and T3 Moving Average StrategyPine Script · Trend following · 5m
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Adaptive Risk Management Strategy Based on Dynamic ATR and Moving Average CrossoverPine Script · Trend following · 2h