0bps

Strategy vault / Trend following

Trend Following Strategy Based on KST Indicator

Trend Following Strategy Using KST Indicator This article explains in detail a quantitative trend following strategy using the KST indicator. It generates trading signals by calculating the crossover between the KST…

Author
ChaoZhang
Complexity
Intermediate · 36 lines
Parameters
9
Backtest bar
3h · intraday
Tested on
BTC/USDT · futures

Trend Following Strategy Using KST Indicator

This article explains in detail a quantitative trend following strategy using the KST indicator. It generates trading signals by calculating the crossover between the KST line and signal line.

I. Strategy Logic

The main steps for signal generation are:

  1. Calculate values of multiple ROC indicators with different periods.

  2. Apply moving averages to the ROC values separately and take the sum to derive the KST line.

  3. Further smooth the KST line using moving average to get the signal line.

  4. A buy signal is generated when the KST line crosses above the signal line, and vice versa for sell signals.

  5. Appropriate position sizing can be selected.

By taking the sum of multiple ROC values, the KST line reflects both short-term and long-term price trends. Its crossover with the signal line can determine trend direction.

II. Advantages of the Strategy

The biggest advantage is the comprehensive indicator calculation, which incorporates trend information across timeframes.

Another advantage is the simple and intuitive indicator usage with a clear signal line.

Lastly, adjustable position sizing helps control overall risk exposure.

III. Potential Weaknesses

However, some issues exist:

Firstly, the indicator itself has some lag in reacting to price changes.

Secondly, reliance on just the KST makes it susceptible to reversals.

Also, extensive optimization is required to avoid overfitting.

IV. Summary

In summary, this article has explained a quantitative trend following strategy using KST crossover signals. It reflects price trends through the indicator for trade signals, but requires managing indicator lag and proper parameter tuning. Overall it provides a simple trend tracking approach.

Parameters

NameDefaultWhat it controls
v_input_int_110ROC Length #1
v_input_int_215ROC Length #2
v_input_int_320ROC Length #3
v_input_int_430ROC Length #4
v_input_int_510SMA Length #1
v_input_int_610SMA Length #2
v_input_int_710SMA Length #3
v_input_int_815SMA Length #4
v_input_int_99Signal Line Length

Source Pine Script

/*backtest
start: 2023-08-15 00:00:00
end: 2023-09-14 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
// strategy(title="KST Alert", shorttitle="KST Alert", format=format.price, precision=4)
roclen1 = input.int(10, minval=1, title = "ROC Length #1")
roclen2 = input.int(15, minval=1, title = "ROC Length #2")
roclen3 = input.int(20, minval=1, title = "ROC Length #3")
roclen4 = input.int(30, minval=1, title = "ROC Length #4")
smalen1 = input.int(10, minval=1, title = "SMA Length #1")
smalen2 = input.int(10, minval=1, title = "SMA Length #2")
smalen3 = input.int(10, minval=1, title = "SMA Length #3")
smalen4 = input.int(15, minval=1, title = "SMA Length #4")
siglen = input.int(9, minval=1, title = "Signal Line Length")
smaroc(roclen, smalen) => ta.sma(ta.roc(close, roclen), smalen)
kst = smaroc(roclen1, smalen1) + 2 * smaroc(roclen2, smalen2) + 3 * smaroc(roclen3, smalen3) + 4 * smaroc(roclen4, smalen4)
sig = ta.sma(kst, siglen)
plot(kst, color=#009688, title="KST")
plot(sig, color=#F44336, title="Signal")
hline(0, title="Zero", color = #787B86)
eL1=ta.crossover(kst,sig)
eS1=ta.crossunder(kst,sig)
ch = 0
t = year(time('D'))
ch := ta.change(t) != 0 ? 1 : 0
T1 = time(timeframe.period, "0915-1520")
session_open = na(t) ? false : true
newDay = ta.change(time("15m")) != 0
strategy.entry("Long1", strategy.long, when = eL1)
strategy.entry("Short1", strategy.short, when = eS1)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-15. 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.

in Claude Code, Cursor, Codex & 4 more
/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-KST-Indicator.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open