TrendFollow
TrendFollow is a built-in TypeScript strategy from @tradejs/strategies.
It researches continuation-style trend setups, using a trailing stop line and strategy-specific deterministic guardrails.
Entry Logic
- Replays candles through
createTrendFollowEngine(...). - Reads
runtimeState.signalandruntimeState.snapshot. - Skips until a bullish or bearish trend signal exists.
- Selects
LONGorSHORTside config from signal direction. - Uses
signal.trailStopas the stop-loss reference. - Computes target from
TRENDFOLLOW_TARGET_R_MULT. - Sizes quantity from
MAX_LOSS_VALUE / riskDistance, withFEE_PERCENTbuffer. - Returns
entrywith trend-follow figures andtrendFollowContext.
Entry codes:
TRENDFOLLOW_BULL_TRENDTRENDFOLLOW_BEAR_TREND
Exits
When a position exists:
TRENDFOLLOW_TRAIL_STOP_EXITwhenTRENDFOLLOW_EXIT_ON_TRAIL_STOP=trueand price crosses the active trailing stop.TRENDFOLLOW_OPPOSITE_SIGNAL_EXITwhenTRENDFOLLOW_EXIT_ON_OPPOSITE_SIGNAL=trueand the engine emits an opposite trend signal.- otherwise
POSITION_EXISTS.
Config Parameters
Trend model:
TRENDFOLLOW_PIVOT_LENGTHTRENDFOLLOW_MIN_BARS_BETWEEN_SIGNALSTRENDFOLLOW_ATR_LENGTHTRENDFOLLOW_ATR_MULTTRENDFOLLOW_SIGNAL_OFFSET_ATRTRENDFOLLOW_TARGET_R_MULTTRENDFOLLOW_EXIT_ON_TRAIL_STOPTRENDFOLLOW_EXIT_ON_OPPOSITE_SIGNALTRENDFOLLOW_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.trendFollowContext- trend and trailing-stop figures from
buildTrendFollowFigures(...) - stop at
signal.trailStop - one take-profit at the computed target
Common Skip Reasons
NO_TREND_FOLLOW_SIGNALPOSITION_EXISTSDEV_TRADE_COOLDOWNSTRATEGY_DISABLEDINVALID_STOPINVALID_QTYRISK_RATIO:<value>
Validation Notes
Trend-following experiments are very sensitive to stop distance, warmup length, and market regime. Treat guardrail behavior as implementation detail to validate with your own tickers and timeframes.
Related: