Strategy vault / Multi-timeframe
Multi Timeframe Stochastic Oscillator Swing Trading Strategy with Dynamic Take Profit and Stop Loss
This strategy is a multi-timeframe swing trading system based on the Stochastic Oscillator. It identifies trading opportunities by combining stochastic signals from current and higher timeframes, using dynamic…

Overview
This strategy is a multi-timeframe swing trading system based on the Stochastic Oscillator. It identifies trading opportunities by combining stochastic signals from current and higher timeframes, using dynamic take-profit and stop-loss levels for risk management. The strategy is designed for volatile markets, aiming to capture short-term price movements for profit.
Strategy Principles
The core logic is based on several key elements:
- Using Stochastic Oscillator confirmation on two timeframes (current and higher)
- Looking for crossover signals in overbought/oversold zones
- Buy conditions: K line crosses above D line in current timeframe with K<20; higher timeframe K<20 and K>D
- Sell conditions: K line crosses below D line in current timeframe with K>80; higher timeframe K>80 and K<D
- Dynamic take-profit and stop-loss system based on entry price, with adjustable multipliers
Strategy Advantages
- Multi-timeframe signal confirmation improves reliability and reduces false signals
- Trading in overbought/oversold zones increases probability of trend reversal
- Dynamic TP/SL system automatically adjusts to market volatility, enhancing money management flexibility
- Visual interface clearly displays trading signals and TP/SL levels for better understanding
- Adjustable parameters allow adaptation to different market conditions
Strategy Risks
- Frequent stop-losses may occur in highly volatile markets
- Dual timeframe confirmation might cause missed trading opportunities
- Fixed multiplier TP/SL may not suit all market conditions
- Potential early profit taking in strong trends
- Requires careful parameter optimization to balance reward and risk
Optimization Directions
- Implement adaptive TP/SL mechanism based on market volatility
- Add trend filter for adjusting trade direction in strong trends
- Incorporate volume indicators as confirmation signals
- Develop more sophisticated position sizing system
- Consider adding market sentiment indicators for entry timing optimization
Summary
This is a comprehensive trading system combining technical analysis and risk management. Through multi-timeframe signal confirmation and dynamic TP/SL, the strategy maintains stability while offering good profit potential. However, users need to optimize parameters according to their trading style and market conditions, always maintaining strict risk control.
Source Pine Script
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Swing Fairas Oil", overlay=true)
// Input parameters
kLength = input(14, title="Stochastic K Length")
dLength = input(3, title="Stochastic D Length")
smoothK = input(3, title="Smooth K")
tfHigher = input.timeframe("30", title="Higher Timeframe")
takeProfit = input(1.7, title="Take Profit Multiplier")
stopLoss = input(1.7, title="Stop Loss Multiplier")
// Calculate Stochastic Oscillator for current timeframe
k = ta.sma(ta.stoch(close, high, low, kLength), smoothK)
d = ta.sma(k, dLength)
// Calculate Stochastic Oscillator for higher timeframe
kHTF = request.security(syminfo.tickerid, tfHigher, ta.sma(ta.stoch(close, high, low, kLength), smoothK))
dHTF = request.security(syminfo.tickerid, tfHigher, ta.sma(kHTF, dLength))
// Buy and sell conditions (confirmation from two timeframes)
buyCondition = ta.crossover(k, d) and k < 20 and kHTF < 20 and kHTF > dHTF
sellCondition = ta.crossunder(k, d) and k > 80 and kHTF > 80 and kHTF < dHTF
// Define Take Profit and Stop Loss levels
longStopLoss = close * (1 - stopLoss / 100)
longTakeProfit = close * (1 + takeProfit / 100)
shortStopLoss = close * (1 + stopLoss / 100)
shortTakeProfit = close * (1 - takeProfit / 100)
// Execute Trades
if buyCondition
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", from_entry="Long", limit=longTakeProfit, stop=longStopLoss)
if sellCondition
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", from_entry="Short", limit=shortTakeProfit, stop=shortStopLoss)
// Plot buy/sell signals on candlestick chart
plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.labelup, size=size.small, title="Buy Signal")
plotshape(series=sellCondition, location=location.abovebar, color=color.red, style=shape.labeldown, size=size.small, title="Sell Signal")
// Highlight candles for buy and sell conditions
barcolor(buyCondition ? color.green : sellCondition ? color.red : na)
// Draw Take Profit and Stop Loss levels dynamically with labels
var float tpLevel = na
var float slLevel = na
if buyCondition
tpLevel := longTakeProfit
slLevel := longStopLoss
if sellCondition
tpLevel := shortTakeProfit
slLevel := shortStopLoss
Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-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/Multi-Timeframe-Stochastic-Oscillator-Swing-Trading-Strategy-with-Dynamic-Take-Profit-and-Stop-Loss.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
- Low Pyramid Risk Tracking StrategyPine Script · Multi-timeframe · 1d
- Multi Timeframe RSI SRSI Trading StrategyPine Script · Multi-timeframe · 1d
- Multi timeframe RSI and Moving Average Trading StrategyPine Script · Multi-timeframe · 1h
- Aggregated Multi timeframe MACD RSI CCI StochRSI MA Linear Trading StrategyPine Script · Multi-timeframe · 1m
- Long and Short Opening Strategy Based on Multi Timeframe Moving Average and MACDPine Script · Multi-timeframe · 1h
- Parabolic SAR Stoch and Security Indicator Based Multi Timeframe Quantitative Trading StrategyPine Script · Multi-timeframe · 1d