| Title: | Candlestick Pattern Detection and Stock Screening |
|---|---|
| Description: | Detects classical candlestick patterns and structure-based chart patterns from OHLCV time series and provides reusable stock-screening workflows. Built-in detectors include single- and multi-candle patterns, trend structures such as double bottoms and ascending triangles, and a configurable "golden pit" recovery setup. Includes a unified API to run pattern scans across one or many symbols. |
| Authors: | po su [aut, cre] |
| Maintainer: | po su <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-28 08:17:20 UTC |
| Source: | https://github.com/statlearner123/kliner |
Returns supported pattern identifiers, Chinese names, or both.
available_patterns(language = c("id", "cn", "both"))available_patterns(language = c("id", "cn", "both"))
language |
Output language: |
A character vector of supported pattern names.
available_patterns() available_patterns("cn")available_patterns() available_patterns("cn")
Produces reproducible synthetic OHLCV data for examples and tests.
demo_ohlcv(n = 120, seed = 123)demo_ohlcv(n = 120, seed = 123)
n |
Number of rows to generate. |
seed |
Random seed. |
A data frame with date, open, high, low, close, volume.
d <- demo_ohlcv(60, seed = 99) head(d, 3)d <- demo_ohlcv(60, seed = 99) head(d, 3)
Detects one built-in pattern from OHLCV data.
detect_pattern(data, pattern, ...)detect_pattern(data, pattern, ...)
data |
A data frame with at least |
pattern |
One value from |
... |
Additional parameters passed to the selected detector. |
A logical vector of length nrow(data). TRUE marks rows where the
pattern is detected.
d <- demo_ohlcv(120) hit <- detect_pattern(d, "double_bottom") tail(hit, 3)d <- demo_ohlcv(120) hit <- detect_pattern(d, "double_bottom") tail(hit, 3)
Returns the full 68-pattern catalog grouped by the official menu categories.
pattern_catalog()pattern_catalog()
A data frame with pattern_id, pattern_cn, and category.
tbl <- pattern_catalog() nrow(tbl)tbl <- pattern_catalog() nrow(tbl)
Draws candlesticks with optional pattern markers for visual verification.
plot_kline_patterns( data, pattern = NULL, detections = NULL, main = NULL, max_labels = 10, file = NULL )plot_kline_patterns( data, pattern = NULL, detections = NULL, main = NULL, max_labels = 10, file = NULL )
data |
OHLCV data frame. |
pattern |
Optional pattern identifier or Chinese name. |
detections |
Optional logical vector from |
main |
Plot title. |
max_labels |
Maximum number of labels to draw. |
file |
Optional PNG file path. If supplied, the plot is saved to disk. |
Invisibly returns detection indices.
d <- demo_ohlcv(140, seed = 1) plot_kline_patterns(d, pattern = "doji", max_labels = 5)d <- demo_ohlcv(140, seed = 1) plot_kline_patterns(d, pattern = "doji", max_labels = 5)
Simulates several symbols, runs pattern screening, and writes chart images with pattern labels.
run_simulation_demo( symbols = c("AAA", "BBB", "CCC"), patterns = c("double_bottom", "golden_pit", "ascending_triangle"), n = 220, seed = 123, output_dir = tempdir() )run_simulation_demo( symbols = c("AAA", "BBB", "CCC"), patterns = c("double_bottom", "golden_pit", "ascending_triangle"), n = 220, seed = 123, output_dir = tempdir() )
symbols |
Character vector of symbols. |
patterns |
Patterns to screen. |
n |
Number of rows per symbol. |
seed |
Random seed. |
output_dir |
Output directory for PNG charts. |
A list with data, screen, and plot_files.
out <- run_simulation_demo( symbols = c("AAA", "BBB", "CCC"), patterns = c("double_bottom", "golden_pit"), n = 180 ) out$screenout <- run_simulation_demo( symbols = c("AAA", "BBB", "CCC"), patterns = c("double_bottom", "golden_pit"), n = 180 ) out$screen
Runs several detectors and reports whether each one is present on the latest candle.
scan_patterns(data, patterns = available_patterns(), ...)scan_patterns(data, patterns = available_patterns(), ...)
data |
A data frame with OHLCV columns. |
patterns |
Character vector of pattern names. |
... |
Additional parameters passed to each detector. |
A data frame with columns pattern, detected_latest.
d <- demo_ohlcv(120) scan_patterns(d, patterns = c("doji", "hammer", "golden_pit"))d <- demo_ohlcv(120) scan_patterns(d, patterns = c("doji", "hammer", "golden_pit"))
Applies one detector to many symbols.
screen_symbols(data_list, pattern, latest_only = TRUE, ...)screen_symbols(data_list, pattern, latest_only = TRUE, ...)
data_list |
Named list of OHLCV data frames. |
pattern |
Pattern identifier from |
latest_only |
If |
... |
Additional parameters passed to |
A data frame with detected symbols and context columns.
d1 <- demo_ohlcv(130, seed = 1) d2 <- demo_ohlcv(130, seed = 2) screen_symbols( list(SYMA = d1, SYMB = d2), pattern = "doji", latest_only = FALSE )d1 <- demo_ohlcv(130, seed = 1) d2 <- demo_ohlcv(130, seed = 2) screen_symbols( list(SYMA = d1, SYMB = d2), pattern = "doji", latest_only = FALSE )
Generates synthetic OHLCV data for several symbols and injects representative chart structures so pattern-screening workflows can be tested end-to-end.
simulate_symbols(symbols = c("AAA", "BBB", "CCC"), n = 220, seed = 123)simulate_symbols(symbols = c("AAA", "BBB", "CCC"), n = 220, seed = 123)
symbols |
Character vector of symbol names. |
n |
Number of rows per symbol. |
seed |
Random seed. |
A named list of OHLCV data frames.
sim <- simulate_symbols(c("AAA", "BBB"), n = 180, seed = 7) names(sim)sim <- simulate_symbols(c("AAA", "BBB"), n = 180, seed = 7) names(sim)