Feature Engineering in Trading: Turning Data into Insights

Feature engineering in trading means turning raw observations into inputs that a rule or model can use: a percentage return, distance from a moving average, relative volume, or the time since an earnings release. A useful feature has a clear definition, is available when the decision is made, and improves results on data that did not shape its design.
Start with a market hypothesis and a few understandable inputs. More indicators and a more complex model do not automatically produce a stronger strategy. On LuxAlgo’s native charts, Quant, our coding agent, can help turn specific price-and-volume rules into indicators and backtestable strategies. Broader machine-learning research requires its own data, training, and evaluation workflow.
Feature Engineering Methods at a Glance
| Feature family | Example | Main question |
|---|---|---|
| Price and trend | Lagged return; distance from a 20-period SMA | Does recent direction or deviation carry information? |
| Volume and volatility | Relative volume; ATR divided by price | Does activity or uncertainty change the setup? |
| Time and events | Session; time since a public announcement | Does the effect depend on when it occurs? |
| Text and relationships | News sentiment; sector-relative return | Does outside context add something prices miss? |
SVMs, CNNs, and LSTMs are model types, rather than feature families. None has a universal trading accuracy range or expected annual return.
Market Data Fundamentals
Choose Data That Matches the Question
OHLCV bars describe opening, high, low, and closing prices plus volume over an interval. They support many trend and volatility features. Level 1 quote data provides the best displayed bid and ask for its stated coverage. Level 2 adds displayed depth beyond those prices; it does not necessarily identify the traders behind orders.
For U.S. equities, consolidated feeds and individual-exchange feeds cover different activity. Do not compare their volume as if it were identical. Historical order-book features require historical depth data, not a candle-based liquidity indicator. Executed volume at price is also different from resting orders waiting to trade.
LuxAlgo’s data documentation identifies the feeds behind its native charts. Footprint data is available for supported crypto markets and U.S. equities, with U.S. equity coverage from Cboe EDGX. Forex, commodities, and CME futures currently provide candles rather than footprint data. Confirm the provider, session, timeframe, plan access, and available history before designing a feature.
Set Measurable Quality Rules
There is no universal “98% accurate” or “under 100 ms” requirement. A daily earnings feature and a quote-sensitive intraday feature have different timing needs. Define acceptable missing observations, delivery delay, and calculation time for your decision schedule.
- Standardize timestamp offsets, session calendars, units, and symbol identifiers.
- Check duplicates, missing bars, stale quotes, impossible prices, and corporate-action adjustments.
- Keep original inputs and version the cleaning rules so a result can be reproduced.
- Record when information became available. A report’s fiscal period-end is not its publication time.
- Retain delisted securities and historical universe membership when the research question requires them.
News, filings, PDFs, and social posts introduce extraction errors, revisions, and timestamp ambiguity. Inspect a sample manually before treating an automated text pipeline as reliable.
Build Basic Features You Can Explain
Time Series and Moving Averages
Lagged returns describe earlier price changes. Rolling statistics summarize a trailing window. A simple moving average gives equal weight to its observations; an exponential moving average emphasizes recent data; a weighted moving average applies a specified weighting scheme. Record both the lookback and whether the current completed bar is included.
| Feature | Illustrative calculation | Interpretation |
|---|---|---|
| One-period return | 102 ÷ 100 − 1 = 2% | Price rose 2% from the previous close |
| Distance from SMA | Close 102 ÷ SMA 100 − 1 = 2% | Close is 2% above the chosen average |
| Normalized ATR | ATR 2 ÷ close 100 = 2% | Recent true-range measure relative to price |
| Relative volume | 1.5 million ÷ 1 million = 1.5 | Current completed-bar volume is 1.5 times the preceding 20-bar average |
These are separate hypothetical observations, not a profitable system. A feature requiring the closing price is only finalized at the close. Model an executable decision afterward instead of assuming that the final value was known earlier.
Technical Indicators as Inputs
MACD describes the relationship between moving averages; RSI summarizes the balance of recent gains and losses; Bollinger Bands place price in a rolling volatility context. Use their values, slopes, or distances as precisely defined inputs. Adding MACD to a neural network does not establish that the combination works.
OBV accumulates signed volume according to close-to-close direction. Chaikin Money Flow combines the close’s position within the bar with volume. The Klinger Oscillator applies a price-and-volume calculation to assess changes in volume force. These are proxies derived from market observations, not direct identification of institutional buying or selling.
A volatility contraction pattern can be described with narrowing ranges, changing volume, and a defined breakout threshold. Write down how many contractions count and when the pattern becomes knowable. Test the definition instead of assigning a generic success rate or promising a particular rally size.
Advanced Features and Machine Learning
Separate Inputs, Models, and Targets
A feature is information supplied to a model. A target is what the model is trained to estimate, such as the next five-bar return. An SVM may classify outcomes, a CNN may process structured arrays, and an LSTM may model sequences. Architecture alone does not determine trading value.
Text workflows can use named entity recognition to connect news with companies, classification to label reports, or topic modeling to group themes. Combine these with market features only after matching publication times and resolving duplicate or revised stories. A sentiment score calculated from tomorrow’s news cannot inform today’s trade.
Reduce Redundancy Without Leaking Information
Several momentum indicators may encode much of the same movement. Compare correlations, remove redundant candidates, or explore principal component analysis (PCA). PCA compresses variation; it does not specifically maximize future trading profit. Sampling and ensemble methods also require their own controlled evaluation.
Fit normalization, imputation, PCA, and feature selection using training data only, then apply the fitted transformation to validation data. Scikit-learn’s leakage guidance explains how pipelines help keep those operations inside the appropriate training split.
Be careful with noise reduction. PyKalman distinguishes filtering from smoothing: smoothing can incorporate future measurements. A smooth historical curve can therefore contain information unavailable at the original decision time. Even a causal filter needs parameters estimated without future data.
Include Risk and Trading Friction
Risk features might describe beta to a benchmark, volatility estimates such as GARCH forecasts, sector concentration, spreads, or trading volume. Clustering can reveal related exposures but does not replace position limits. Value at Risk can use historical, parametric, or simulation methods; it is a model-dependent loss quantile, not a maximum possible loss.
Use these inputs to ask concrete questions: Does the signal survive wider spreads? Does it mostly load on one market direction? Can the intended size trade without dominating available liquidity? High classification accuracy cannot answer those questions by itself.
Test Chart-Based Features with LuxAlgo
For an initial experiment, compare a trend rule with and without a relative-volume condition. Hold the market, dates, execution assumptions, position size, and exit logic constant. This isolates the effect of the added condition more clearly than changing several rules together.
- Specify the experiment. Choose a provider and symbol, interval, regular or extended session, trailing windows, decision timing, and missing-data behavior.
- Ask Quant for explicit logic. For example: “Create a long-only strategy using completed bars. Enter after the 20 EMA crosses above the 50 EMA. Add a switch requiring volume above 1.5 times the average volume of the preceding 20 bars, excluding the signal bar. Exit after the opposite EMA cross. Do not open another position while already long.” This is a test specification, not a recommendation.
- Review and run. Follow Making strategies: inspect Code, check the generated conditions, and run the script. Confirm that decision and fill timing match the experiment.
- Control the simulation. In strategy settings, use Inputs for parameters and Properties for capital, size, commission, slippage, and other simulation assumptions. Compare results and inspect individual trades.
- Save deliberately. Star the runs you want to retain and record which feature changed. Do not assume every attempted variation is automatically saved.
This workflow tests chart-based strategy logic. It does not automatically train an external SVM, CNN, or LSTM, perform every validation procedure, or establish a live brokerage execution pipeline. A script running successfully is different from a feature demonstrating predictive value.
TradingView remains another environment for Pine Script® chart strategies. Chart scripts, market-data access, broker connections, and execution automation are separate capabilities; do not assume a generic “TradingView API” connects all of them for an arbitrary research project.
Validate Features Before Trusting Them
Use chronological development and validation periods. With overlapping forward-return targets, separate the periods enough to prevent training labels from extending into the validation interval. Scikit-learn’s time-series validation guidance explains why ordinary shuffled splits can be inappropriate. A time-ordered split still needs to match the label horizon and data dependencies.
Compare each feature against a simple baseline and remove it again to see whether the benefit survives. This is often called an ablation test. Keep a record of every candidate tried: repeatedly selecting the best result on the same holdout turns that holdout into part of development.
Suppose 60 of 100 labels are “up.” Always predicting “up” scores 60% accuracy without learning anything. A 65% score needs comparison with that baseline, class-specific errors, and an untouched sample. Trading profitability additionally depends on payoff sizes, timing, turnover, and costs.
- Prediction quality: error measures for regression; precision, recall, and class balance for classification; probability calibration where relevant.
- Economic usefulness: net profit, average trade after costs, turnover, drawdown, and the distribution of outcomes.
- Risk adjustment: Sharpe ratio or annualized-return-to-drawdown measures, with calculation conventions and test length stated.
- Stability: results across time windows, market conditions, and nearby parameter choices.
There is no universal Sharpe, profit-factor, or drawdown threshold that validates every strategy. A short sample with few trades can look excellent by chance. Synthetic scenarios can supplement stress testing, but they do not replace evaluation on unseen market observations.
Implement and Monitor the Feature Pipeline
Use batch processing for scheduled historical calculations, streaming for inputs needed as events arrive, or a hybrid approach that periodically rebuilds history and updates incrementally. Choose based on the decision deadline, recovery needs, and measured workload. A faster processing framework does not correct a feature with the wrong timestamp.
Python tools such as Bytewax can support streaming workflows. Its repository now describes the project as community-maintained after the original team stepped back in May 2025, so assess maintenance and support needs. Benchmark the actual pipeline instead of assuming a fixed speed advantage. Preserve consistent feature definitions across research and live observation. Log input versions, calculation failures, missing values, and delivery delays.
Monitor feature distributions and realized performance separately. A shift may reflect a data fault, a changed market, or a stale model. Review the cause before retraining; define a retraining schedule and evaluation rules in advance. A divergence indicator or cumulative-volume-delta chart does not automatically detect model drift.
Operational controls matter too. The SEC reported that Knight Capital lost more than $460 million in the August 2012 trading incident, involving defective deployment and inadequate controls. That is a deployment and risk-management lesson, rather than evidence that a particular feature-engineering method failed.
Useful Libraries and Learning Resources
- NumPy and pandas: numerical operations, tabular preparation, and explicitly timed rolling calculations.
- TA-Lib: standard technical-indicator calculations.
- Featuretools: automated feature construction from temporal and relational tables.
- tsfresh: time-series feature extraction and relevance evaluation.
- Feature-engine: preprocessing and feature-engineering transformers.
- Zipline-reloaded: event-driven Python backtesting; the original Quantopian hosted platform closed in 2020.
- Alphalens-reloaded: factor-return, information-coefficient, and turnover analysis.
Video: Algorithmic Trading and Machine Learning with Python
This freeCodeCamp course provides an extended Python research walkthrough, including features, indicators, and portfolio work. It is a separate learning environment from LuxAlgo. Check current package versions and data access when reproducing its older examples, and apply the timestamp and validation checks above.
Begin with one feature you can calculate by hand, a clear availability time, and a baseline. Add complexity only when it contributes repeatable evidence after costs. For chart-based ideas, use Quant to build the rules, inspect the implementation, and compare saved runs on LuxAlgo’s native charts.
Read next