Break even Price Strategy
The main idea of this strategy is to plot the entry price and breakeven price after opening a position, to visually display the price level where a breakout above the entry price would result in profit. This can help…

Overview
The main idea of this strategy is to plot the entry price and breakeven price after opening a position, to visually display the price level where a breakout above the entry price would result in profit. This can help traders better manage positions and realize profits.
Strategy Logic
The code enters long when SMA crossover happens and enters short on SMA crossunder. It then calculates the entry price and breakeven price after fees. The breakeven price is calculated as: for long, breakeven price = entry price * (1 + fees); for short, breakeven price = entry price * (1 - fees). Finally, it plots the entry price line and breakeven price line, filling the area between them.
This way, once the price breaks through the entry price line, it means the trade is now profitable. Traders can use the breakeven line to set take profit or stop loss levels to lock in profits.
The key components of the code are:
- Entry condition checks
- Calculation of entry and breakeven prices
- Plotting the entry and breakeven price lines
- Filling color between the two lines
With simple condition checks for entry, breakeven price calculation, and plotting of auxiliary lines, the break-even price strategy is implemented.
Advantage Analysis
The advantages of this strategy include:
Intuitive display of profit/loss, can quickly judge if price has reached profit target.
Can use breakeven line to set take profit/stop loss levels to avoid increasing losses.
Simple and easy to understand code, easy to implement and adjust.
Can be incorporated into own trading strategies, using breakeven line to manage positions.
Easy to modify fee parameters for different exchanges and products.
Can optimize entry by adjusting SMA periods.
Risk Analysis
The risks of this strategy include:
SMA has lagging nature, may miss price changes.
Breakeven line cannot completely avoid losses.
No exit mechanism, traders need to monitor P/L themselves.
Incorrect fee settings may cause wrong breakeven calculation.
Slippage is not considered.
No stop loss, may lead to large losses.
The solutions are:
Consider more sensitive indicators like MACD.
Add trend indicator to avoid counter trend trades.
Add take profit and stop loss logic for automatic exits.
Set accurate fees based on actual exchange.
Add fixed slippage for optimal entries and exits.
Add trailing stop loss to limit max loss.
Improvement Areas
Some ways to optimize the strategy:
Replace SMA with more advanced indicators like MACD or KDJ.
Add trend filter to avoid counter trend trades.
Optimize SMA periods for better entry precision.
Add take profit and stop loss logic for automatic exits.
Set slippage for backtest and live trading.
Optimize fee settings to match reality.
Add trailing stop loss to limit max loss.
Run strategy on multiple timeframes for diversification.
Incorporate volume changes to improve entry.
Use machine learning to optimize parameters.
Conclusion
This strategy intuitively displays the breakeven price level where a breakout can result in profits. It is a simple and practical auxiliary strategy with advantages like simple code and easy implementation. But risks need to be addressed too. We can optimize it from many aspects to make it more robust and profitable. Overall it provides a great reference example worth studying and applying.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 0.25 | Price Change in % |
Source Pine Script
/*backtest
start: 2022-11-15 00:00:00
end: 2023-11-15 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// © NikitaDoronin
//@version=4
strategy("Plot Break-even Price", overlay=true)
/// Break-even calculation
ep = 0.0
ep := na(ep[1]) ? na : ep[1]
p = 0.0
p := na(p[1]) ? na : p[1]
/// Fees Input
fee_inp = input(0.25, title='Price Change in %', step=0.1)/100
/// Your Strategy calculation
longCondition = crossover(sma(close, 14), sma(close, 28))
shortCondition = crossunder(sma(close, 14), sma(close, 28))
/// Stategy Entry
if (longCondition)
ep := close
p := close * (1 + fee_inp)
strategy.entry("My Long Entry Id", strategy.long)
if (shortCondition)
ep := close
p := close * (1 - fee_inp)
strategy.entry("My Short Entry Id", strategy.short)
/// Plot Break-even Price
p1 = plot(ep, color = color.red, transp = 85)
p2 = plot(p, color = color.green)
fill(p1, p2, color = color.red, transp = 85)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/Break-even-Price-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 Trading Strategy Based on ADX IndicatorPine Script · Breakout · 1d
- Average Line Breakthrough StrategyPine Script · Breakout · 1d
- Bollinger Bands Dynamic Breakout StrategyPine Script · Breakout · 1h
- Bull Flag Breakout StrategyPine Script · Breakout · 1h
- Bull Market Tracking SystemPine Script · Breakout · 1h
- Cross boundary Dynamic Range Quantitative Trading Strategy Based on Bollinger BandsPine Script · Breakout · 3h