Buy Strategy Based on Close Price Breakthrough
The core idea of this strategy is to buy when the closing price of the stock is higher than the opening price of the day. When the buy condition is met, the strategy will go long at the close of that candlestick at…

Overview
The core idea of this strategy is to buy when the closing price of the stock is higher than the opening price of the day. When the buy condition is met, the strategy will go long at the close of that candlestick at the closing price. Stop loss price and take profit price will then be set. When the price reaches these two prices, the position will be closed.
Strategy Principle
If the closing price of the daily candlestick is higher than the opening price, it means that the stock price rose on that day. This is a buy signal. The breakthrough of the closing price from the opening price indicates that the buying power is quite strong and the stock price is likely to continue rising.
Therefore, the trading signal for this strategy is: Daily Candlestick Close Price > Daily Candlestick Open Price. When this condition is met, buy at the closing price at the close of that candlestick and hold daily.
This strategy uses two parameters:
Entry Price: The buying price, the default is 0, which means buying at the closing price
Take Profit Parameter: Take profit parameter, the take profit price formula is: Entry Price * (1 + Take Profit Parameter), the default value is 0.5%, equivalent to 0.5% of the entry price
The specific trading process is as follows:
- Wait for candlestick to close and check if close price > open price of the day
- When the condition is met, buy at the closing price
- After opening a position, set stop loss and take profit price
- When the price rises to take profit price, close position for profit
- When the price falls to the lowest point of the next candlestick, close position for stop loss
- Repeat steps 1-5 every day
Advantage Analysis
This strategy has the following advantages:
- The idea is simple and easy to understand and implement
- It only requires the open and close prices of candlestick for trade signal judgment, with small data requirements
- The risk of drawdown is small, using stop loss and take profit mechanism to control losses
Risk Analysis
There are also some risks with this strategy:
- There may be multiple buy opportunities during the day, but the strategy only buys once at close, possibly missing some opportunities
- Price may callback after close, increasing the probability of stop loss trigger
The risks can be reduced by:
- After buy signal triggered, track the highest price of the day and use AdjustAmount functions to dynamically adjust position
- Delay setting stop loss and take profit price for a period after close to avoid stop loss trigger immediately
Optimization Directions
This strategy can be optimized in the following aspects:
- Add volume confirmation, for example add volume or market heat indicators as confirmation for buy signal
- Use dynamic stop loss and take profit after buying, adjust stop loss and take profit price in real time
- Set parameters specifically for individual stocks, use machine learning methods to automatically optimize the parameters
- Add position management mechanism, adjust position size to avoid drawdown risk
Conclusion
This strategy generates buy signals based on close price breakthrough. The idea is simple with small drawdown risk. By adding confirmation indicators, dynamic stop loss/take profit, parameter optimization etc., the stability and profitability of the strategy can be further improved. Overall speaking, this strategy is suitable for investors who are interested in opening price breakthrough strategies to use and optimize, and has very good practicality.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_float_1 | false | Entry Price |
Source Pine Script
/*backtest
start: 2024-02-19 00:00:00
end: 2024-02-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Buy on Close Strategy", overlay=true)
// Входные параметры
var float entry_price = na
if (na(entry_price))
entry_price := input.float(title="Entry Price", defval=0)
// Функция для расчета Take Profit
calc_take_profit(price) =>
price * 1.005 // 0.5% от суммы сделки
// Проверяем условие для открытия позиции на покупку
buy_condition = close > open
// Переменная для отслеживания открытой позиции
var bool open_position = na
// Реализация стратегии
if (buy_condition)
// Открываем сделку на покупку
strategy.entry("Buy", strategy.long)
open_position := true
// Закрываем позицию по Take Profit или при закрытии свечи
if (open_position)
// Рассчитываем уровень Take Profit
take_profit_level = calc_take_profit(entry_price)
// Закрываем сделку по Take Profit
strategy.exit("Take Profit", "Buy", limit=take_profit_level)
// Закрываем сделку при закрытии свечи
if (close < open)
strategy.close("Close Candle", "Buy")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-21. 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/Buy-Strategy-Based-on-Close-Price-Breakthrough.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
- 5 Day Moving Average Channel Breakout Strategy Combined With Mileage ConceptPine Script · Breakout · 1d
- ATR Trailing Stops StrategyPine Script · Breakout · 1h
- ATR Trend Breakout StrategyPine Script · Breakout · 1d
- Adaptive Bollinger Breakout with Moving Average Quantitative Strategy SystemPine Script · Breakout · 1h
- Adaptive Channel Breakout StrategyPine Script · Breakout · 1d
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h