KPL Swing Trading Strategy
This strategy trades based on the KPL Swing indicator, which is a simple trend following mechanical system. It goes long on close above 20-day high, and goes short on close below 20-day low to capture medium-long…
Overview
This strategy trades based on the KPL Swing indicator, which is a simple trend following mechanical system. It goes long on close above 20-day high, and goes short on close below 20-day low to capture medium-long term price swings.
Strategy Logic
- Calculate 20-day highest high and lowest low
- Go long when close breaks out above 20-day high
- Go short when close breaks down below 20-day low
- Calculate stop loss levels and set stop orders
Specifically, it first calculates 20-day range using highest high and lowest low. When close breaks out upward from 20-day high, go long. When close breaks down from 20-day low, go short. Stop loss levels are calculated after entry for both directions to limit losses.
Advantage Analysis
- Simple and intuitive logic, easy to grasp
- Has some trend following capacity
- Stop loss effectively controls risk
- No subjective price target guessing
- Less emotional trading, minimal external influence
Risk Analysis
- Lagging entry risks exist
- Fails to identify key levels in trends
- Whipsaws may cause being trapped
- Profit potential limited by 20-day breakout range
- Hard to determine optimal holding period
Risks can be managed via adjusting lookback period, adding trend filter, optimizing stop loss etc.
Optimization Directions
- Test different lookback periods
- Add MACD etc. to gauge momentum
- Optimize stop loss for trailing stop loss
- Evaluate holding period impact on profitability
- Study parameter preference across products
- Consider adding re-entry and pyramiding rules
Summary
This strategy trades trend swings based on KPL Swing indicator. Pros are simple operation and built-in stop loss; Cons are lags and profit constraints. Cons can be improved via parameter optimization, strategy combination while retaining pros. It helps traders master mechanical indicator-based trading.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 20 | no |
Source Pine Script
/*backtest
start: 2022-09-20 00:00:00
end: 2023-09-20 00:00:00
period: 2d
basePeriod: 1d
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/
// © ceyhun
//@version=4
strategy("KPL Swing Strategy", overlay=true)
no = input(20)
res = highest(high, no)
sup = lowest(low, no)
avd = iff(close > res[1], 1, iff(close < sup[1], -1, 0))
avn = valuewhen(avd != 0, avd, 1)
tsl = iff(avn == 1, sup, res)
sl = iff(close > tsl, highest(lowest(low, no / 2), no / 2), lowest(highest(high, no / 2), no / 2))
plot(tsl, color=#0000FF,title="KPL Swing")
plot(sl, color=color.white,title="Stoploss")
bgcolor(abs(close - tsl[1]) > close ? color.white : close < tsl ? color.red : color.green, 90, offset=0)
if crossover(close, tsl)
strategy.entry("Long", strategy.long, comment="Long")
if crossunder(close,tsl)
strategy.entry("Short", strategy.short, comment="Short")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-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/KPL-Swing-Trading-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