Strategy vault / Trend following
Stochastics Crossover Trading Strategy
This strategy uses stochastics crossover between K and D lines to generate trading signals, a typical stochastics trading strategy.
Overview
This strategy uses stochastics crossover between K and D lines to generate trading signals, a typical stochastics trading strategy.
Strategy Logic
Calculate stochastics K and D lines over a given period.
K line crossover above D line generates buy signals.
K line crossover below D line generates sell signals.
Can set backtest date range to test strategy effectiveness.
Simple and clear rules trading stochastics crossover.
Advantages
Stochastics sensitive to overbought and oversold levels.
K and D lines form easy trading signals.
Backtest verifies strategy performance.
Stochastics easy to compute and implement.
Concise code easy for further development.
Risks
Crossovers may generate false signals.
No stop loss or take profit in place.
Fails to differentiate trends and ranges.
Backtest carries look-ahead bias.
Real trading performance may differ from backtest.
Enhancement
Test parameters to find optimum values.
Add trend filter for additional validation.
Build in stop loss and take profit mechanisms.
Incorporate other factors for signal confirmation.
Handle backtest data to eliminate biases.
Paper trade to optimize parameters for live trading.
Conclusion
This strategy trades simple stochastics crossovers, easy to implement but requires refinements for stability. Enhancing it via parameter tuning, risk controls etc can transform it into a robust quant trading system.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 35 | K |
| v_input_2 | 21 | D |
| v_input_3 | 21 | Smooth |
| v_input_4 | 2020 | Start Year |
| v_input_5 | true | Start Month |
| v_input_6 | true | Start Day |
| v_input_7 | 2030 | End Year |
| v_input_8 | 12 | End Month |
| v_input_9 | 31 | End Day |
Source Pine Script
/*backtest
start: 2023-08-20 00:00:00
end: 2023-09-19 00:00:00
period: 2h
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/
// © utanico
//@version=4
strategy(title="Stochastic", overlay=true, shorttitle="Stoch")
periodK = input(35, title="K", minval=1)
periodD = input(21, title="D", minval=1)
smoothK = input(21, title="Smooth", minval=1)
startYear = input(type=input.integer, title = "Start Year", defval = 2020)
startMonth = input(type=input.integer, title = "Start Month", defval = 1)
startDay = input(type=input.integer, title = "Start Day", defval = 1)
endYear = input(type=input.integer, title = "End Year", defval = 2030)
endMonth = input(type=input.integer, title = "End Month", defval = 12)
endDay = input(type=input.integer, title = "End Day", defval = 31)
//Start date and time
test_start = timestamp(startYear, startMonth, startDay, 00, 00)
//End date time
test_end = timestamp(endYear, endMonth, endDay, 00, 00)
//テストPeriodのSpecify
is_test = true
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
if (is_test)
if (k > d)
strategy.entry("Stoch_LE", strategy.long, comment="Stoch_LE")
//if (strategy.opentrades > 0 and k < d)
//strategy.close("Stoch_LE",comment="CloseLONG")
if (k < d)
strategy.entry("Stoch_SE", strategy.short, comment="Stoch_SE")
//if (strategy.opentrades < 0 and k > d)
//strategy.close("Stoch_SE",comment="CloseShort")Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-20. 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/Stochastics-Crossover-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 Stochastic RSI Dual Line CrossoverPine Script · Trend following · 4h
- Dual Moving Average Crossover Strategy with Stop Loss and Take ProfitPine Script · Trend following · 4h
- EMA AROON ASHPine Script · Trend following · 3m
- EMA SMA Multi Indicator Comprehensive Trend Following StrategyPine Script · Trend following · 1h
- EMA200 and Stochastic RSI StrategyPine Script · Trend following · 1h
- Gaussian Channel Trend Following with Stochastic RSI Trading StrategyPine Script · Trend following · 1d