TrendShift
TrendShift is a built-in TypeScript strategy from @tradejs/strategies.
It researches trend transition setups by detecting bullish and bearish flips in a dynamic trend band.
Entry Logic
- Replays candles through
createTrendShiftEngine(...). - Reads
runtimeState.signalandruntimeState.snapshot. - Skips until a bullish or bearish flip exists.
- Applies volatility and strategy guardrails.
- Selects
LONGorSHORTside config from signal direction. - Places the stop beyond the current band with ATR and percent buffers.
- Computes target from
TRENDSHIFT_TARGET_R_MULT. - Sizes quantity from
MAX_LOSS_VALUE / riskDistance, withFEE_PERCENTbuffer. - Returns
entrywith trend-shift figures andtrendShiftContext.
Entry codes:
TRENDSHIFT_BULLISH_FLIPTRENDSHIFT_BEARISH_FLIP
Exits
When a position exists:
TRENDSHIFT_OPPOSITE_FLIP_EXITwhenTRENDSHIFT_EXIT_ON_OPPOSITE_FLIP=trueand the engine emits the opposite flip.- otherwise
POSITION_EXISTS.
Config Parameters
Trend-band model:
TRENDSHIFT_MULTIPLICATIVE_FACTORTRENDSHIFT_SLOPETRENDSHIFT_ATR_LENGTHTRENDSHIFT_WIDTH_PCTTRENDSHIFT_CONFIRM_FLIP_WITH_CLOSETRENDSHIFT_MIN_FLIP_DISTANCE_ATRTRENDSHIFT_STOP_ATR_BUFFER_MULTTRENDSHIFT_STOP_BUFFER_PCTTRENDSHIFT_TARGET_R_MULTTRENDSHIFT_EXIT_ON_OPPOSITE_FLIPTRENDSHIFT_MAX_FIGURE_POINTS
Shared groups:
- runtime:
ENV,INTERVAL,MAKE_ORDERS,BACKTEST_PRICE_MODE - AI/ML:
AI_ENABLED,AI_MODE,MIN_AI_QUALITY,ML_ENABLED,ML_THRESHOLD - risk:
FEE_PERCENT,MAX_LOSS_VALUE,LONG.*,SHORT.* - shared indicators: MA, OBV, ATR, BB, MACD fields
Signal Payload
The strategy stores:
additionalIndicators.trendShiftContext- band, flip, stop, and target figures from
buildTrendShiftFigures(...) orderPlan.stopLossPrice- one take-profit at the computed target
Common Skip Reasons
WAIT_DATANO_SIGNALPOSITION_EXISTSVERY_VOLATILITY- guardrail skip code from
getTrendShiftGuardrailSkipCode(...) DEV_TRADE_COOLDOWNSTRATEGY_DISABLEDINVALID_STOPINVALID_QTYRISK_RATIO:<value>
Validation Notes
Revalidate after changing market context, timeframe, or risk settings. Trend-transition systems are vulnerable to overfitting because small band and confirmation changes can move flips across candles.
Related: