0bps

Strategy vault / Mean reversion

V20Shift Exit Strategy v20

This strategy enters and exits trades at shifted prices to follow trends.

Author
ChaoZhang
Complexity
Intermediate · 44 lines
Parameters
11
Backtest bar
4d · position
Tested on
BTC/USDT · futures

Overview

This strategy enters and exits trades at shifted prices to follow trends.

How it Works

  1. Calculate shifted prices based on previous close's percentage.

  2. Downward shifted price is buy line, upward shifted price is sell line.

  3. Enter long when price hits buy line.

  4. Exit when price hits sell line.

Advantages

  • Auto trailing stop loss/profit take without manual intervention
  • Customizable shift percentage for parameter optimization
  • Long only reduces trade frequency
  • Can limit trading time range

Risks

  • Unable to effectively determine trend end
  • Time lag, may miss quick reversals

Optimization Directions

  • Test different shift percentage parameters
  • Optimize incremental setting of parameters
  • Incorporate dynamic shifts based on trend
  • Consider pyramiding on new highs

Conclusion

The strategy achieves auto trailing profit takes via shifted entry/exit levels. Further improvements through parameter optimization and logic enhancements can improve performance. But whipsaw risks need to be managed. Overall a simple and practical approach for trend following trading.

Parameters

NameDefaultWhat it controls
v_input_1-10Buy, src-%
v_input_2falseSell, src+%
v_input_3_low0Source for buy: low | high | close | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_4_ohlc40Source for sell: ohlc4 | high | low | open | hl2 | hlc3 | hlcc4 | close
v_input_5trueoffset
v_input_61900From Year
v_input_72100To Year
v_input_8trueFrom Month
v_input_912To Month
v_input_10trueFrom day
v_input_1131To day

Source Pine Script

/*backtest
start: 2022-09-14 00:00:00
end: 2023-09-20 00:00:00
period: 4d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2019

//@version=3
strategy(title = "Noro's ShiftEx Strategy v2.0", shorttitle = "ShiftEx 2.0", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)

//Settings
buy = input(-10.0, title = "Buy, src-%")
sell = input(0.0, title = "Sell, src+%")
buysrc = input(low, title = "Source for buy")
sellsrc = input(ohlc4, title = "Source for sell")
offset = input(true)
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//Levels
bar = close > open ? 1 : close < open ? -1 : 0
mult = 1 / syminfo.mintick
lb = bar == -1 ? buysrc + ((buysrc / 100) * (buy * 1)) : buysrc + ((buysrc / 100) * (buy * 2))
levelbuy = round(lb * mult) / mult
ls = sellsrc + ((sellsrc / 100) * sell)
levelsell = round(ls * mult) / mult

//Lines
os = offset ? 1 : 0
plot(levelbuy, offset = os, linewidth = 2, color = lime, title = "Buy")
plot(levelsell, offset = os, linewidth = 2, color = blue, title = "Sell")

//Trading
if low[1] > 0
    strategy.entry("long", strategy.long, limit = levelbuy, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    strategy.entry("close", strategy.short, 0, limit = levelsell, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

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.

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/V20Shift-Exit-Strategy-v20.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