Free lesson · Charts & patterns
Quantitative recognition I: build a causal candle feature table
Open interactive lessonPractice calculationsExplore labs
Start with the idea
Start with four numbers describing one completed candle. Add context only after you can reproduce each feature by hand.
Symbols, units & horizon
- x_t: four dimensionless model inputs for completed bar t
- O_t,H_t,L_t,C_t: open, high, low and close in matching price units
- V_t: volume in traded units
- ATR_(t−1): strictly prior positive average true range in price units
- V̄_(t−1): strictly prior positive mean volume in matching traded units
- t: fixed chosen bar interval
- min: smaller value
When and why to use this
Use the table as an interpretable baseline and as a context branch beside a sequence encoder. Monitor changes in feature distributions before interpreting a change in model scores.
- Feature: a number supplied to a model. Target: the future outcome the model will learn to predict. Keep them in separate columns.
- Use signed body fraction to retain direction. Lower-wick fraction describes geometry; range divided by prior ATR describes size relative to recent movement.
- Use volume divided by a prior volume average to describe relative activity. Intraday volume needs a time-of-day baseline; opening volume and lunchtime volume are not directly comparable.
- Add separate, trailing context columns: trend slope, distance to a confirmed level, spread, realized volatility and session position. Standardize inside each training window.
- A feature row for bar t becomes available after that bar closes. Freeze the historical universe, adjustments and feature timestamps.
- For a next-open trade, build the label from the actual next entry price to the specified exit, including costs. Do not use the signal close as an assumed fill.
- Compare a rule detector, regularized logistic regression and boosted trees on identical rows. Ablate whole feature groups; many indicators are redundant transformations of the same prices.
Quantitative recognition I: build a causal candle feature table
- Compute the range before dividing: H−L=104−100=4.
- Signed body=(103−102)/4=.25. Lower wick=(102−100)/4=.5.
- With prior ATR=2, relative range=4/2=2. With volume=1,500 and prior mean=1,000, relative volume=1.5.
O=102,H=104,L=100,C=103,V=1,500, prior ATR=2 and prior mean volume=1,000 produce [.25,.5,2,1.5]. No model has been fitted to this synthetic row.
Use the rule
- Build one row per permitted decision timestamp.
- Fit preprocessing and model parameters on training rows only.
- Report incremental net outcomes against the same strategy without candle features.
Before moving on
Produce a feature dictionary with units, availability time, missing-value rule and an ablation plan.
Python implementation
Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.
def candle_features(o,h,l,c,volume,prior_atr,prior_mean_volume):
if not l<=min(o,c)<=max(o,c)<=h or h==l or min(prior_atr,prior_mean_volume)<=0 or volume<0:
raise ValueError("Valid OHLC and positive prior scales required")
span=h-l
return ((c-o)/span,(min(o,c)-l)/span,span/prior_atr,volume/prior_mean_volume)
print(candle_features(102,104,100,103,1500,2,1000))Continue learning
Candles, Structures & Pattern Research — all lessons- First principles: what a candle actually records
- Doji, hammer, shooting star and long-body bars
- Engulfing, inside bars and multi-candle sequences
- Trends, ranges, breakouts and chart structures
- Indicators as arithmetic: ATR, moving averages, RSI and bands
- Known strategy families: from chart idea to complete rules
- Pattern recognition: rules, features, shapelets and image models
- Quantitative recognition I: build a causal candle feature table
- Quantitative recognition II: shapelets and constrained dynamic time warping
- Quantitative recognition III: causal encoders and contrastive learning
- Quantitative recognition IV: GAF images, CNNs, transformers and visual-model audits
- Quantitative recognition V: calibrate, abstain and test the complete strategy
- Research review: what the evidence does and does not establish
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations