Long Breakthrough Strategy Based on K Line Construction
This strategy realizes long position breakout trading on the 4-hour line of Tesla by setting simple K-line pattern judgment rules. The strategy has the advantages of simple implementation, clear logic, easy to…

Overview
This strategy realizes long position breakout trading on the 4-hour line of Tesla by setting simple K-line pattern judgment rules. The strategy has the advantages of simple implementation, clear logic, easy to understand, etc.
Strategy Principle
The core judgment logic of the strategy is based on the following 4 K-line pattern rules:
- The lowest price of the current K-line is lower than the opening price
- The lowest price of the current K-line is lower than the lowest price of the previous K-line
- The closing price of the current K-line is higher than the opening price
- The closing price of the current K-line is higher than the opening price and closing price of the previous K-line
When all 4 rules are met at the same time, a long position opening operation is performed.
In addition, the strategy also sets stop loss and take profit to close positions when price triggers stop loss or take profit conditions.
Advantage Analysis
The strategy has the following advantages:
- The K-line judgment rules used are very simple and straightforward, easy to understand, and easy to practice.
- It is completely based on the judgment of price entities without the use of overly complex technical indicators, and the backtest results are straightforward.
- The code implementation is small in size, runs efficiently, and is easy to optimize and improve.
- Stop loss and take profit can be flexibly set by adjusting parameters to control risks.
Risk Analysis
The main risks to note are:
- Fixed quantity is used for opening positions without considering position sizing, which may pose risks of overtrading.
- No filters are set which may generate too many invalid trades in range-bound markets.
- Insufficient backtest data may bias the judgment of the strategy performance.
The following methods can be adopted to mitigate risks:
- Incorporate position sizing model to dynamically adjust trade size based on capital size.
- Add trade filters to avoid disorderly opening of trades in choppy market conditions.
- Collect more historical data to expand backtest duration and improve result reliability.
Optimization Directions
Potential optimization directions for the strategy include:
- Incorporate position sizing module to determine trade size based on capital utilization ratio.
- Design stop loss and take profit trailing mechanisms for flexible exits.
- Add trade filters to avoid invalid trades.
- Auto-optimize parameters using machine learning methods.
- Support spread trading across multiple products.
Conclusion
This strategy realizes long breakthrough trading using simple K-line pattern rules. Although there is some room left for improvement, from the perspective of simplicity and directness, it is a very suitable long position strategy for beginners to understand and use. With continuous optimizations, the strategy performance can be further enhanced.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | true | Start Date |
| v_input_int_2 | true | Start Month |
| v_input_int_3 | 2017 | Start Year |
| v_input_int_4 | 8 | End Date |
| v_input_int_5 | 3 | End Month |
| v_input_int_6 | 2022 | End Year |
| v_input_1 | 4 | TakeProfit_long |
| v_input_2 | 4 | StopLoss_long |
Source Pine Script
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
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/
// © TheQuantScience
//@version=5
strategy("SimpleBarPattern_LongOnly", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, currency = currency.EUR, initial_capital = 1000, commission_type = strategy.commission.percent, commission_value = 0.03)
// Make input options that configure backtest date range
startDate = input.int(title="Start Date",
defval=1, minval=1, maxval=31)
startMonth = input.int(title="Start Month",
defval=1, minval=1, maxval=12)
startYear = input.int(title="Start Year",
defval=2017, minval=1800, maxval=2100)
endDate = input.int(title="End Date",
defval=8, minval=1, maxval=31)
endMonth = input.int(title="End Month",
defval=3, minval=1, maxval=12)
endYear = input.int(title="End Year",
defval=2022, minval=1800, maxval=2100)
// Look if the close time of the current bar
// Falls inside the date range
inDateRange = true
// Setting Conditions
ConditionA = low < open
ConditionB = low < low[1]
ConditionC = close > open
ConditionD = close > open[1] and close > close[1]
FirstCondition = ConditionA and ConditionB
SecondCondition = ConditionC and ConditionD
IsLong = FirstCondition and SecondCondition
TakeProfit_long = input(4.00)
StopLoss_long = input(4.00)
Profit = TakeProfit_long*close/100/syminfo.mintick
Loss = StopLoss_long*close/100/syminfo.mintick
EntryCondition = IsLong and inDateRange
// Trade Entry&Exit Condition
if EntryCondition and strategy.opentrades == 0
strategy.entry(id = 'Open_Long', direction = strategy.long)
strategy.exit(id = "Close_Long", from_entry = 'Open_Long', profit = Profit, loss = Loss)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-05. 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/Long-Breakthrough-Strategy-Based-on-K-Line-Construction.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