0bps

Strategy vault / Breakout

Dynamic Multi Timeframe Pivot Trend Breakthrough Strategy

This strategy is a dynamic trend breakthrough trading approach based on multi-timeframe pivots and the Relative Strength Index (RSI). By combining weekly-level price support and resistance levels with the RSI…

Author
ianzeng123
Complexity
Intermediate · 112 lines
Parameters
0
Backtest bar
1d · swing
Tested on
ETH/USDT · futures

IMG IMG

Overview

This strategy is a dynamic trend breakthrough trading approach based on multi-timeframe pivots and the Relative Strength Index (RSI). By combining weekly-level price support and resistance levels with the RSI indicator, the strategy aims to capture trend opportunities in financial markets while providing refined position management and risk control mechanisms.

Strategy Principles

The core principles of the strategy include the following key steps:

  1. Multi-Timeframe Price Pivot Calculation:
  • Calculate key support and resistance levels using weekly-level previous candle's close, high, and low prices
  • Compute typical support levels (S1, S2, S3) and resistance levels (R1, R2, R3)
  • Dynamically adjust support and resistance levels' sensitivity through a factor
  1. RSI Indicator Dynamic Optimization:
  • Calculate RSI with a 21-period length
  • Introduce Exponential Moving Average (EMA) to smooth RSI
  • Construct a composite indicator combining raw RSI and EMA smoothed values
  1. Trading Signal Generation:
  • Long Entry: Composite indicator crosses above 0
  • Long Exit: Highest price breaks R3 resistance level
  • Short Entry: Lowest price breaks S3 support level
  • Short Exit: Composite indicator crosses below 0

Strategy Advantages

  1. Multi-Timeframe Perspective: Effectively filter short-term market noise by introducing weekly-level data
  2. Flexible Position Management: Staged take-profit mechanism reduces single-trade risk
  3. Dynamic Indicator Construction: Combine RSI and EMA to improve signal accuracy
  4. Symmetric Long and Short Trading Logic: Provide flexible strategies for different market environments
  5. Controllable Risk: Built-in stop-loss and staged take-profit mechanisms

Strategy Risks

  1. Indicator Lag: RSI and price pivots may have latency issues
  2. Parameter Sensitivity: Strategy performance highly depends on parameter selection
  3. Transaction Cost Impact: Frequent trading may lead to high commission fees
  4. Extreme Market Conditions: Trend reversal and violent fluctuations may cause strategy failure

Strategy Optimization Directions

  1. Introduce machine learning algorithms to optimize parameter selection
  2. Add volume and volatility filtering mechanisms
  3. Combine more technical indicators for signal verification
  4. Develop dynamic stop-loss and take-profit algorithms
  5. Introduce more complex position sizing management models

Summary

The strategy builds a relatively robust trend breakthrough trading method through multi-timeframe and multi-indicator comprehensive analysis. Its core advantage lies in dynamically capturing market trends and fine-grained risk management. Future optimization spaces include algorithmic intelligence and iterative risk control model development.

Source Pine Script

/*backtest
start: 2024-03-31 00:00:00
end: 2025-03-29 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yuxishejiang

//@version=6
//@version=5
strategy(title="BTCMidline strategy optimization-V2", overlay=true, pyramiding=1, initial_capital=5000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0.075)

// Core Parameters
strat_dir_input = input.string(title="Strategy Direction", defval="long", options=["long", "short"])
strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)

// Indicator calculation
higherTF = input.timeframe("W", "Higher Timeframe")
pc = request.security(syminfo.tickerid, higherTF, close[1], barmerge.gaps_off, barmerge.lookahead_on)
ph = request.security(syminfo.tickerid, higherTF, high[1], barmerge.gaps_off, barmerge.lookahead_on)
pl = request.security(syminfo.tickerid, higherTF, low[1], barmerge.gaps_off, barmerge.lookahead_on)

PP = (ph + pl + pc) / 3
R1 = PP + (PP - pl)
S1 = PP - (ph - PP)
R2 = PP + (ph - pl)
S2 = PP - (ph - pl)
factor = input.int(2, "Factor")
R3 = ph + factor * (PP - pl)
S3 = pl - 2 * (ph - PP)

length = input.int(21, "RSI Length")
p = close
vrsi = ta.rsi(p, length)
pp_ema = ta.ema(vrsi, length)
d = (vrsi - pp_ema) * 5
cc = (vrsi + d + pp_ema) / 2

// Position management variables
var float entry_qty = na

// Trade execution logic
longEntry = ta.crossover(cc, 0)
longExit = ta.crossover(high, R3)  // Use real-time highest price judgment

shortEntry = ta.crossunder(low, S3)  // Change to UseS3support level
shortExit = ta.crossunder(cc, 0)     // Synchronously modify to cross below

if (longEntry)
    strategy.entry("Long", strategy.long)
    entry_qty := strategy.position_size

if (strategy.position_size > 0 and longExit)
    strategy.close("Long", comment="5MDivergence Exit")

if (shortEntry)
    strategy.entry("Short", strategy.short)
    entry_qty := strategy.position_size

if (strategy.position_size < 0 and shortExit)
    strategy.close("Short", comment="Short Exit")

// Take profit and stop loss module
per(pcnt) =>
    strategy.position_size != 0 ? math.round(math.abs(pcnt/100 * strategy.position_avg_price / syminfo.mintick)) : na

stoploss = input.float(15, "Stop Loss (%)", minval=0.01)
tp1 = input.float(3, "Take Profit 1 (%)", minval=0.01)
tp2 = input.float(5, "Take Profit 2 (%)", minval=0.01)
tp3 = input.float(7, "Take Profit 3 (%)", minval=0.01)
tp4 = input.float(10, "Take Profit 4 (%)", minval=0.01)

// Staged position closing logic
if strategy.position_size != 0
    qty_total = math.abs(entry_qty)
    qty1 = math.floor(qty_total * 0.25)
    qty2 = math.floor(qty_total * 0.25)
    qty3 = math.floor(qty_total * 0.25)
    qty4 = qty_total - (qty1 + qty2 + qty3)
    
    if strategy.position_size > 0
        strategy.exit("x1", qty=qty1, profit=per(tp1), loss=per(stoploss))
        strategy.exit("x2", qty=qty2, profit=per(tp2), loss=per(stoploss))
        strategy.exit("x3", qty=qty3, profit=per(tp3), loss=per(stoploss))
        strategy.exit("x4", qty=qty4, profit=per(tp4), loss=per(stoploss))
    else
        strategy.exit("x1", qty=qty1, profit=per(tp1), loss=per(stoploss))
        strategy.exit("x2", qty=qty2, profit=per(tp2), loss=per(stoploss))
        strategy.exit("x3", qty=qty3, profit=per(tp3), loss=per(stoploss))
        strategy.exit("x4", qty=qty4, profit=per(tp4), loss=per(stoploss))

// The visualization part remains unchanged
// Long entry visualization
if (longEntry)
    label.new(bar_index, low, "Long Entry", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.small)

// Long exit visualization
if (strategy.position_size > 0 and longExit)
    label.new(bar_index, high, "Long Exit", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)

// Short entry visualization
if (shortEntry)
    label.new(bar_index, high, "Short Entry", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)

// Short exit visualization
if (strategy.position_size < 0 and shortExit)
    label.new(bar_index, low, "Short Exit", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.small)

Published by ianzeng123 on the FMZ strategy square · last modified 2025-03-31. 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/Dynamic-Multi-Timeframe-Pivot-Trend-Breakthrough-Strategy.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