diff --git a/docs/stock-market-csv-data.md b/docs/stock-market-csv-data.md index 23c20a7..0b19904 100644 --- a/docs/stock-market-csv-data.md +++ b/docs/stock-market-csv-data.md @@ -18,8 +18,9 @@ one-call way to use it. | OHLC / price charts (8) | StockCandlestickChart, StockOHLCBarChart, StockLineChart, StockAreaChart, StockHeikinAshi, StockRenko, StockHollowCandles, StockBaselineChart | `load_csv(path, error)` | | Volume / flow indicators (7) | StockVolumeBars, StockVolumeCandles, StockVolumeProfile, StockAccumulationDistribution, StockMoneyFlowChart, StockOBVChart, StockVWAP | `load_csv(path, error)` | | Comparative plotting (8) | StockOverlayChart, StockMultiSymbolChart, StockIndexedComparison, StockRelativePerformance, StockRatioChart, StockSpreadChart, StockCorrelationView, StockSectorComparison | `add_series_csv(path, name, error)` | +| Indicators (250) | All `Ind*` widgets (IndSMA, IndRSI, IndMACD, IndBollingerBands, …) | `load_csv(path, error)` — recomputes the indicator lines from the file | -Two groups are **not** covered, on purpose: +One group is **not** covered, on purpose: - **Drawing / annotation tools (14)** — StockTrendline, StockFibRetracement, StockFibExtension, StockPitchfork, StockParallelChannel, StockRectangle, @@ -30,12 +31,6 @@ Two groups are **not** covered, on purpose: (their `set_series`), which you can replace with `set_series(xframe::load_ohlcv_csv(path, err))`, but they have no `load_csv` of their own because there is no series to plot. -- **The 250 `Ind*` indicator widgets** take a series only through their - constructor — they have no `set_series` at all. Pass a loaded series - there (see [Indicators](#indicators-constructor-only) below). Adding a - `set_series` to all 250 is a separate job: each one recomputes its own - lines from the series in its constructor, so there is no single generic - setter to add. ## The CSV format @@ -90,6 +85,11 @@ all reproducible, no network: `StockHeikinAshi` rebuilds its Heikin-Ashi candles and `StockRenko` rebuilds its bricks from whatever series is set; `StockBaselineChart` resets its baseline to the first bar's close. +- **Indicators (250):** constructor default + `xframe::make_seeded_series(250)` — 250 bars, same generator as the OHLC + group. Each widget recomputes its own lines from that series in the + constructor (see [Indicators](#indicators-load_csv--set_series) below); + loading a CSV replaces the series and recomputes the lines. - **Comparative widgets (8):** the constructor seeds two or three named series — `SYM-A` (`make_seeded_series(60, 42)`), `SYM-B` (seed 7), `SYM-C` (seed 99) — so the multi-line / comparison rendering is visible @@ -116,7 +116,8 @@ if (!w.load_csv("aapl_30d.csv", err)) { } ``` -`load_csv` is the same shape on all 15 single-series widgets +`load_csv` is the same shape on all 15 single-series widgets — and on +all 250 `Ind*` indicators (see [Indicators](#indicators-load_csv--set_series)): (`StockCandlestickChart`, `StockOHLCBarChart`, `StockLineChart`, `StockAreaChart`, `StockHeikinAshi`, `StockRenko`, `StockHollowCandles`, `StockBaselineChart`, `StockVolumeBars`, `StockVolumeCandles`, @@ -184,22 +185,62 @@ candles for `StockHeikinAshi`, bricks for `StockRenko` (30 CSV bars build 25 bricks at the default brick size), and the longest series length for the comparative widgets. -## Indicators (constructor only) +## Indicators (`load_csv` / `set_series`) -The 250 `Ind*` widgets have no `set_series`; give them the loaded series -at construction: +All 250 `Ind*` widgets take CSV data the same way the single-series +charts do — `load_csv`, `set_series`, `clear_series`, `series()` — with +one difference: an indicator does not plot the bars themselves, it plots +lines *computed from* the bars (SMA, RSI, Bollinger bands, …), so setting +a series recomputes those lines from the new bars. ```cpp #include "IndSMA.h" + +IndSMA w(display, screen, window, gc, &styles, 20, 20, 760, 520); +std::string err; +if (!w.load_csv("aapl_30d.csv", err)) { + std::fprintf(stderr, "cannot load CSV: %s\n", err.c_str()); + // The old series is untouched: the widget keeps drawing what it had. +} else { + w.draw(); // now plots the SMA of the CSV closes; view resets +} +``` + +How it works, per widget: + +- The constructor still computes the lines once, from the constructor + series (default: the seeded template, 250 bars). `set_series` stores + the new series, resets the view (`reset_view()`, where the widget has + one), and recomputes the lines with the widget's own formula and its + stored parameters (period, multiplier, fast/slow, …) — the parameters + that used to be constructor-only are now stored as members, so a + reloaded series uses the same settings the widget was built with. +- `load_csv` loads the file with `xframe::load_ohlcv_csv` and, on + success, calls `set_series`. On failure it returns `false` and leaves + the series — and the lines — unchanged. +- `clear_series()` empties the series (and the lines); the widget draws + its empty frame. The seeded template is only the constructor default — + `clear_series` does not restore it. To get the template back, call + `set_series(xframe::make_seeded_series(250))`. +- Passing a loaded series to the constructor still works, exactly as + before: + +```cpp std::string err; auto series = xframe::load_ohlcv_csv("aapl_30d.csv", err); IndSMA w(display, screen, window, gc, &styles, 20, 20, 760, 520, series); w.draw(); ``` -The indicator is computed from the series in the constructor, so a series -loaded from CSV plots exactly like the seeded template one — only the -values differ. +Two things to know: + +- **Line colours reset on recompute.** `set_line_color(i, c)` tints are + part of the rebuilt lines, so a `set_series` / `load_csv` restores the + widget's default line colours. Re-apply tints after loading if you + customised them. +- **Warm-up bars stay NaN.** A 30-row CSV into a period-20 indicator + leaves the first 19 line values NaN, exactly as the template series + does — only the values differ, never the shape of the computation. ## The designer's own CSV support (different thing) @@ -249,3 +290,14 @@ nanoseconds), plus the plain `date,open,high,low,close,volume` layout. and checks the CSV shot is non-blank, differs from the template shot (the plot follows the file), reports 30 items, and that a missing file exits without touching the series. Result: **23/23 widgets PASS**. +- `widgets/tests/ind_csv_harness.cpp` + `widgets/tests/test_ind_csv.py` + — the same treatment for all 250 `Ind*` indicators: per-widget harness + (template dump → `load_csv` 30-row fixture → `set_series` 1170-row + Massive fixture → failed load leaves the series untouched → + `clear_series` empties lines and draws clean) plus template-vs-CSV + screenshots for a 39-widget sample and a rebuild of all 250 demo + mains. Result: **250/250 harnesses build, 250/250 numeric PASS, + 39/39 screenshots PASS, 250/250 demo mains build**. (One generator bug + found en route: a `signal` parameter colliding with a result-struct + field was rewritten to `result.signal_` in IndMACD — fixed, and the + generator now skips identifiers after `.` / `->`.) diff --git a/widgets/components/IndADX/IndADX.h b/widgets/components/IndADX/IndADX.h index 96682a9..761c8ac 100644 --- a/widgets/components/IndADX/IndADX.h +++ b/widgets/components/IndADX/IndADX.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_adx(series_, period_)); + line_names_.push_back("ADX(14)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndADX(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_adx(series, period_)); - line_names_.push_back("ADX(14)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndADX() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndADXR/IndADXR.h b/widgets/components/IndADXR/IndADXR.h index a915a96..4b3ef4b 100644 --- a/widgets/components/IndADXR/IndADXR.h +++ b/widgets/components/IndADXR/IndADXR.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_adxr(series_, period_)); + line_names_.push_back("ADXR(14)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndADXR(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_adxr(series, period_)); - line_names_.push_back("ADXR(14)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndADXR() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndALMA/IndALMA.h b/widgets/components/IndALMA/IndALMA.h index dbeb00b..22db40f 100644 --- a/widgets/components/IndALMA/IndALMA.h +++ b/widgets/components/IndALMA/IndALMA.h @@ -234,6 +234,19 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_alma(series_closes(series_), period_, offset_, sigma_)); + line_names_.push_back("ALMA(9)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndALMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 9, double offset = 0.85, double sigma = 6.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), @@ -241,12 +254,25 @@ public: period_ = period; offset_ = offset; sigma_ = sigma; - - lines_.push_back(ind_alma(series_closes(series), period_, offset_, sigma_)); - line_names_.push_back("ALMA(9)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndALMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndAPO/IndAPO.h b/widgets/components/IndAPO/IndAPO.h index 5fec050..395ed29 100644 --- a/widgets/components/IndAPO/IndAPO.h +++ b/widgets/components/IndAPO/IndAPO.h @@ -198,6 +198,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int fast_ = 12; + int slow_ = 26; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_apo(xframe::series_closes(series_), fast_, slow_); + lines_.push_back(result); + line_names_.push_back("APO"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndAPO(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int fast = 12, int slow = 26) @@ -214,13 +232,30 @@ public: name_ = "IndAPO"; text_ = "APO"; series_ = series; - std::vector result = xframe::ind_apo(xframe::series_closes(series), fast, slow); - lines_.push_back(result); - line_names_.push_back("APO"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + fast_ = fast; + slow_ = slow; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndAPO() {} diff --git a/widgets/components/IndATR/IndATR.h b/widgets/components/IndATR/IndATR.h index c161678..2f50954 100644 --- a/widgets/components/IndATR/IndATR.h +++ b/widgets/components/IndATR/IndATR.h @@ -143,6 +143,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_atr(series_, period_); + lines_.push_back(Line{"ATR", Srgb{200, 120, 0}, result}); + } + public: std::function on_view_change; IndATR(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -151,9 +160,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_atr(series, period); - lines_.push_back(Line{"ATR", Srgb{200, 120, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndATR() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndAcceleratorOscillator/IndAcceleratorOscillator.h b/widgets/components/IndAcceleratorOscillator/IndAcceleratorOscillator.h index 9380203..4b41be4 100644 --- a/widgets/components/IndAcceleratorOscillator/IndAcceleratorOscillator.h +++ b/widgets/components/IndAcceleratorOscillator/IndAcceleratorOscillator.h @@ -204,6 +204,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int fast_ = 5; + int slow_ = 34; + int smooth_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_accelerator_oscillator(series_, fast_, slow_, smooth_); + lines_.push_back(result); + line_names_.push_back("AcceleratorOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndAcceleratorOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int fast = 5, int slow = 34, int smooth = 5) @@ -220,13 +239,31 @@ public: name_ = "IndAcceleratorOscillator"; text_ = "AcceleratorOscillator"; series_ = series; - std::vector result = xframe::ind_accelerator_oscillator(series, fast, slow, smooth); - lines_.push_back(result); - line_names_.push_back("AcceleratorOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + fast_ = fast; + slow_ = slow; + smooth_ = smooth; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndAcceleratorOscillator() {} diff --git a/widgets/components/IndAccumulationDistributionLine/IndAccumulationDistributionLine.h b/widgets/components/IndAccumulationDistributionLine/IndAccumulationDistributionLine.h index 1d61621..9e5e3eb 100644 --- a/widgets/components/IndAccumulationDistributionLine/IndAccumulationDistributionLine.h +++ b/widgets/components/IndAccumulationDistributionLine/IndAccumulationDistributionLine.h @@ -152,6 +152,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_accumulation_distribution_line(series_, period_); + lines_.push_back(Line{"ADL", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndAccumulationDistributionLine(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -160,9 +169,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_accumulation_distribution_line(series, period); - lines_.push_back(Line{"ADL", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndAccumulationDistributionLine() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndAccumulativeSwingIndex/IndAccumulativeSwingIndex.h b/widgets/components/IndAccumulativeSwingIndex/IndAccumulativeSwingIndex.h index 0cadf6b..1bd991b 100644 --- a/widgets/components/IndAccumulativeSwingIndex/IndAccumulativeSwingIndex.h +++ b/widgets/components/IndAccumulativeSwingIndex/IndAccumulativeSwingIndex.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_accumulative_swing_index(series_, limitMove_)); + line_names_.push_back("ASI(1)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndAccumulativeSwingIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), double limitMove = 1.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { limitMove_ = limitMove; - - lines_.push_back(ind_accumulative_swing_index(series, limitMove_)); - line_names_.push_back("ASI(1)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndAccumulativeSwingIndex() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndAdaptiveCyberCycle/IndAdaptiveCyberCycle.h b/widgets/components/IndAdaptiveCyberCycle/IndAdaptiveCyberCycle.h index 5b59f61..f2939bf 100644 --- a/widgets/components/IndAdaptiveCyberCycle/IndAdaptiveCyberCycle.h +++ b/widgets/components/IndAdaptiveCyberCycle/IndAdaptiveCyberCycle.h @@ -221,6 +221,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_adaptive_cyber_cycle(xframe::series_closes(series_), dummy_); + lines_.push_back(result); + line_names_.push_back("AdaptiveCyberCycle"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndAdaptiveCyberCycle(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -237,13 +254,29 @@ public: name_ = "IndAdaptiveCyberCycle"; text_ = "AdaptiveCyberCycle"; series_ = series; - std::vector result = xframe::ind_adaptive_cyber_cycle(xframe::series_closes(series), dummy); - lines_.push_back(result); - line_names_.push_back("AdaptiveCyberCycle"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndAdaptiveCyberCycle() {} diff --git a/widgets/components/IndAdaptiveRSI/IndAdaptiveRSI.h b/widgets/components/IndAdaptiveRSI/IndAdaptiveRSI.h index 07cfd2b..e5eb4d5 100644 --- a/widgets/components/IndAdaptiveRSI/IndAdaptiveRSI.h +++ b/widgets/components/IndAdaptiveRSI/IndAdaptiveRSI.h @@ -222,6 +222,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_adaptive_rsi(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("AdaptiveRSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndAdaptiveRSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -238,13 +255,29 @@ public: name_ = "IndAdaptiveRSI"; text_ = "AdaptiveRSI"; series_ = series; - std::vector result = xframe::ind_adaptive_rsi(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("AdaptiveRSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndAdaptiveRSI() {} diff --git a/widgets/components/IndAlligatorJaw/IndAlligatorJaw.h b/widgets/components/IndAlligatorJaw/IndAlligatorJaw.h index c117031..c807406 100644 --- a/widgets/components/IndAlligatorJaw/IndAlligatorJaw.h +++ b/widgets/components/IndAlligatorJaw/IndAlligatorJaw.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_alligator_jaw(series_closes(series_), period_, shift_)); + line_names_.push_back("Jaw(13,8)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndAlligatorJaw(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 13, int shift = 8) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; shift_ = shift; - - lines_.push_back(ind_alligator_jaw(series_closes(series), period_, shift_)); - line_names_.push_back("Jaw(13,8)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndAlligatorJaw() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndAlligatorLips/IndAlligatorLips.h b/widgets/components/IndAlligatorLips/IndAlligatorLips.h index 803c74a..0f0eacc 100644 --- a/widgets/components/IndAlligatorLips/IndAlligatorLips.h +++ b/widgets/components/IndAlligatorLips/IndAlligatorLips.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_alligator_lips(series_closes(series_), period_, shift_)); + line_names_.push_back("Lips(5,3)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndAlligatorLips(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 5, int shift = 3) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; shift_ = shift; - - lines_.push_back(ind_alligator_lips(series_closes(series), period_, shift_)); - line_names_.push_back("Lips(5,3)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndAlligatorLips() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndAlligatorTeeth/IndAlligatorTeeth.h b/widgets/components/IndAlligatorTeeth/IndAlligatorTeeth.h index f773767..e79023c 100644 --- a/widgets/components/IndAlligatorTeeth/IndAlligatorTeeth.h +++ b/widgets/components/IndAlligatorTeeth/IndAlligatorTeeth.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_alligator_teeth(series_closes(series_), period_, shift_)); + line_names_.push_back("Teeth(8,5)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndAlligatorTeeth(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 8, int shift = 5) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; shift_ = shift; - - lines_.push_back(ind_alligator_teeth(series_closes(series), period_, shift_)); - line_names_.push_back("Teeth(8,5)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndAlligatorTeeth() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndAnchoredVWAP/IndAnchoredVWAP.h b/widgets/components/IndAnchoredVWAP/IndAnchoredVWAP.h index 10acccd..da27794 100644 --- a/widgets/components/IndAnchoredVWAP/IndAnchoredVWAP.h +++ b/widgets/components/IndAnchoredVWAP/IndAnchoredVWAP.h @@ -152,6 +152,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_anchored_vwap(series_, period_); + lines_.push_back(Line{"AnchoredVWAP", Srgb{200, 120, 0}, result}); + } + public: std::function on_view_change; IndAnchoredVWAP(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -160,9 +169,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_anchored_vwap(series, period); - lines_.push_back(Line{"AnchoredVWAP", Srgb{200, 120, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndAnchoredVWAP() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndAroonDown/IndAroonDown.h b/widgets/components/IndAroonDown/IndAroonDown.h index 2ff56f4..afa04c1 100644 --- a/widgets/components/IndAroonDown/IndAroonDown.h +++ b/widgets/components/IndAroonDown/IndAroonDown.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_aroon_down(series_, period_)); + line_names_.push_back("AroonDown(14)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndAroonDown(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_aroon_down(series, period_)); - line_names_.push_back("AroonDown(14)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndAroonDown() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndAroonOscillator/IndAroonOscillator.h b/widgets/components/IndAroonOscillator/IndAroonOscillator.h index 1ea2562..660dfbb 100644 --- a/widgets/components/IndAroonOscillator/IndAroonOscillator.h +++ b/widgets/components/IndAroonOscillator/IndAroonOscillator.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_aroon_osc(series_, period_)); + line_names_.push_back("AroonOsc(14)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndAroonOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_aroon_osc(series, period_)); - line_names_.push_back("AroonOsc(14)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndAroonOscillator() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndAroonUp/IndAroonUp.h b/widgets/components/IndAroonUp/IndAroonUp.h index c9be30e..873f10f 100644 --- a/widgets/components/IndAroonUp/IndAroonUp.h +++ b/widgets/components/IndAroonUp/IndAroonUp.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_aroon_up(series_, period_)); + line_names_.push_back("AroonUp(14)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndAroonUp(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_aroon_up(series, period_)); - line_names_.push_back("AroonUp(14)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndAroonUp() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndAutocorrelation/IndAutocorrelation.h b/widgets/components/IndAutocorrelation/IndAutocorrelation.h index b00164c..f5fbf7e 100644 --- a/widgets/components/IndAutocorrelation/IndAutocorrelation.h +++ b/widgets/components/IndAutocorrelation/IndAutocorrelation.h @@ -156,6 +156,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_autocorrelation(series_, period_); + lines_.push_back(Line{"Autocorr", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndAutocorrelation(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,9 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_autocorrelation(series, period); - lines_.push_back(Line{"Autocorr", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndAutocorrelation() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndAwesomeOscillator/IndAwesomeOscillator.h b/widgets/components/IndAwesomeOscillator/IndAwesomeOscillator.h index ea02da1..462beff 100644 --- a/widgets/components/IndAwesomeOscillator/IndAwesomeOscillator.h +++ b/widgets/components/IndAwesomeOscillator/IndAwesomeOscillator.h @@ -201,6 +201,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int fast_ = 5; + int slow_ = 34; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_awesome_oscillator(series_, fast_, slow_); + lines_.push_back(result); + line_names_.push_back("AwesomeOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndAwesomeOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int fast = 5, int slow = 34) @@ -217,13 +235,30 @@ public: name_ = "IndAwesomeOscillator"; text_ = "AwesomeOscillator"; series_ = series; - std::vector result = xframe::ind_awesome_oscillator(series, fast, slow); - lines_.push_back(result); - line_names_.push_back("AwesomeOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + fast_ = fast; + slow_ = slow; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndAwesomeOscillator() {} diff --git a/widgets/components/IndBalanceOfPower/IndBalanceOfPower.h b/widgets/components/IndBalanceOfPower/IndBalanceOfPower.h index 617ba2a..2aeb3b2 100644 --- a/widgets/components/IndBalanceOfPower/IndBalanceOfPower.h +++ b/widgets/components/IndBalanceOfPower/IndBalanceOfPower.h @@ -198,6 +198,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_balance_of_power(series_, period_); + lines_.push_back(result); + line_names_.push_back("BalanceOfPower"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndBalanceOfPower(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -214,13 +231,29 @@ public: name_ = "IndBalanceOfPower"; text_ = "BalanceOfPower"; series_ = series; - std::vector result = xframe::ind_balance_of_power(series, period); - lines_.push_back(result); - line_names_.push_back("BalanceOfPower"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndBalanceOfPower() {} diff --git a/widgets/components/IndBearPower/IndBearPower.h b/widgets/components/IndBearPower/IndBearPower.h index 39ea850..7eb7d9d 100644 --- a/widgets/components/IndBearPower/IndBearPower.h +++ b/widgets/components/IndBearPower/IndBearPower.h @@ -199,6 +199,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 13; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_bear_power(series_, period_); + lines_.push_back(result); + line_names_.push_back("BearPower"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndBearPower(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 13) @@ -215,13 +232,29 @@ public: name_ = "IndBearPower"; text_ = "BearPower"; series_ = series; - std::vector result = xframe::ind_bear_power(series, period); - lines_.push_back(result); - line_names_.push_back("BearPower"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndBearPower() {} diff --git a/widgets/components/IndBollingerBands/IndBollingerBands.h b/widgets/components/IndBollingerBands/IndBollingerBands.h index 0ed59bc..7dd0f41 100644 --- a/widgets/components/IndBollingerBands/IndBollingerBands.h +++ b/widgets/components/IndBollingerBands/IndBollingerBands.h @@ -155,6 +155,17 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_bollinger_bands(series_, period_, mult_); + lines_.push_back(Line{"Upper", Srgb{200, 30, 30}, result.upper}); + lines_.push_back(Line{"Middle", Srgb{0, 100, 200}, result.middle}); + lines_.push_back(Line{"Lower", Srgb{200, 30, 30}, result.lower}); + } + public: std::function on_view_change; IndBollingerBands(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -163,11 +174,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_bollinger_bands(series, period, mult); - lines_.push_back(Line{"Upper", Srgb{200, 30, 30}, result.upper}); - lines_.push_back(Line{"Middle", Srgb{0, 100, 200}, result.middle}); - lines_.push_back(Line{"Lower", Srgb{200, 30, 30}, result.lower}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndBollingerBands() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndBollingerBandwidth/IndBollingerBandwidth.h b/widgets/components/IndBollingerBandwidth/IndBollingerBandwidth.h index 3611e29..b51a2a1 100644 --- a/widgets/components/IndBollingerBandwidth/IndBollingerBandwidth.h +++ b/widgets/components/IndBollingerBandwidth/IndBollingerBandwidth.h @@ -149,6 +149,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_bollinger_bandwidth(series_, period_, mult_); + lines_.push_back(Line{"Bandwidth", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndBollingerBandwidth(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -157,9 +166,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_bollinger_bandwidth(series, period, mult); - lines_.push_back(Line{"Bandwidth", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndBollingerBandwidth() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndBollingerPercentB/IndBollingerPercentB.h b/widgets/components/IndBollingerPercentB/IndBollingerPercentB.h index c58655d..4463823 100644 --- a/widgets/components/IndBollingerPercentB/IndBollingerPercentB.h +++ b/widgets/components/IndBollingerPercentB/IndBollingerPercentB.h @@ -152,6 +152,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_bollinger_percent_b(series_, period_, mult_); + lines_.push_back(Line{"%B", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndBollingerPercentB(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -160,9 +169,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_bollinger_percent_b(series, period, mult); - lines_.push_back(Line{"%B", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndBollingerPercentB() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndBullPower/IndBullPower.h b/widgets/components/IndBullPower/IndBullPower.h index 6737a83..356ea7d 100644 --- a/widgets/components/IndBullPower/IndBullPower.h +++ b/widgets/components/IndBullPower/IndBullPower.h @@ -199,6 +199,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 13; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_bull_power(series_, period_); + lines_.push_back(result); + line_names_.push_back("BullPower"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndBullPower(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 13) @@ -215,13 +232,29 @@ public: name_ = "IndBullPower"; text_ = "BullPower"; series_ = series; - std::vector result = xframe::ind_bull_power(series, period); - lines_.push_back(result); - line_names_.push_back("BullPower"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndBullPower() {} diff --git a/widgets/components/IndCCI/IndCCI.h b/widgets/components/IndCCI/IndCCI.h index f67cd8e..0844cb4 100644 --- a/widgets/components/IndCCI/IndCCI.h +++ b/widgets/components/IndCCI/IndCCI.h @@ -208,6 +208,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 20; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_cci(series_, period_); + lines_.push_back(result); + line_names_.push_back("CCI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndCCI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) @@ -224,13 +241,29 @@ public: name_ = "IndCCI"; text_ = "CCI"; series_ = series; - std::vector result = xframe::ind_cci(series, period); - lines_.push_back(result); - line_names_.push_back("CCI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCCI() {} diff --git a/widgets/components/IndCamarillaPivotPoints/IndCamarillaPivotPoints.h b/widgets/components/IndCamarillaPivotPoints/IndCamarillaPivotPoints.h index db69aaf..6a585d6 100644 --- a/widgets/components/IndCamarillaPivotPoints/IndCamarillaPivotPoints.h +++ b/widgets/components/IndCamarillaPivotPoints/IndCamarillaPivotPoints.h @@ -156,6 +156,17 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_camarilla_pivot_points(series_, period_); + lines_.push_back(Line{"Pivot", Srgb{0, 100, 200}, result.pivot}); + lines_.push_back(Line{"R1", Srgb{200, 30, 30}, result.r1}); + lines_.push_back(Line{"S1", Srgb{0, 150, 0}, result.s1}); + } + public: std::function on_view_change; IndCamarillaPivotPoints(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,11 +175,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_camarilla_pivot_points(series, period); - lines_.push_back(Line{"Pivot", Srgb{0, 100, 200}, result.pivot}); - lines_.push_back(Line{"R1", Srgb{200, 30, 30}, result.r1}); - lines_.push_back(Line{"S1", Srgb{0, 150, 0}, result.s1}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCamarillaPivotPoints() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndCenterOfGravity/IndCenterOfGravity.h b/widgets/components/IndCenterOfGravity/IndCenterOfGravity.h index b52410d..eb2a223 100644 --- a/widgets/components/IndCenterOfGravity/IndCenterOfGravity.h +++ b/widgets/components/IndCenterOfGravity/IndCenterOfGravity.h @@ -205,6 +205,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_center_of_gravity(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("CenterOfGravity"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndCenterOfGravity(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) @@ -221,13 +238,29 @@ public: name_ = "IndCenterOfGravity"; text_ = "CenterOfGravity"; series_ = series; - std::vector result = xframe::ind_center_of_gravity(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("CenterOfGravity"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCenterOfGravity() {} diff --git a/widgets/components/IndChaikinMoneyFlow/IndChaikinMoneyFlow.h b/widgets/components/IndChaikinMoneyFlow/IndChaikinMoneyFlow.h index 3e2c093..da541e4 100644 --- a/widgets/components/IndChaikinMoneyFlow/IndChaikinMoneyFlow.h +++ b/widgets/components/IndChaikinMoneyFlow/IndChaikinMoneyFlow.h @@ -153,6 +153,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_chaikin_money_flow(series_, period_); + lines_.push_back(Line{"CMF", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndChaikinMoneyFlow(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -161,9 +170,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_chaikin_money_flow(series, period); - lines_.push_back(Line{"CMF", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndChaikinMoneyFlow() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndChaikinOscillator/IndChaikinOscillator.h b/widgets/components/IndChaikinOscillator/IndChaikinOscillator.h index bc2a2f5..dac08d3 100644 --- a/widgets/components/IndChaikinOscillator/IndChaikinOscillator.h +++ b/widgets/components/IndChaikinOscillator/IndChaikinOscillator.h @@ -155,6 +155,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_chaikin_oscillator(series_, period_); + lines_.push_back(Line{"ChaikinOsc", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndChaikinOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -163,9 +172,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_chaikin_oscillator(series, period); - lines_.push_back(Line{"ChaikinOsc", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndChaikinOscillator() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndChaikinVolatility/IndChaikinVolatility.h b/widgets/components/IndChaikinVolatility/IndChaikinVolatility.h index d0ecf13..5cca1ed 100644 --- a/widgets/components/IndChaikinVolatility/IndChaikinVolatility.h +++ b/widgets/components/IndChaikinVolatility/IndChaikinVolatility.h @@ -150,6 +150,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_chaikin_volatility(series_, period_); + lines_.push_back(Line{"ChaikinVol", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndChaikinVolatility(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -158,9 +167,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_chaikin_volatility(series, period); - lines_.push_back(Line{"ChaikinVol", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndChaikinVolatility() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndChandeForecastOscillator/IndChandeForecastOscillator.h b/widgets/components/IndChandeForecastOscillator/IndChandeForecastOscillator.h index 459d4a1..e6947a6 100644 --- a/widgets/components/IndChandeForecastOscillator/IndChandeForecastOscillator.h +++ b/widgets/components/IndChandeForecastOscillator/IndChandeForecastOscillator.h @@ -200,6 +200,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_chande_forecast_oscillator(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("ChandeForecastOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndChandeForecastOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 5) @@ -216,13 +233,29 @@ public: name_ = "IndChandeForecastOscillator"; text_ = "ChandeForecastOscillator"; series_ = series; - std::vector result = xframe::ind_chande_forecast_oscillator(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("ChandeForecastOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndChandeForecastOscillator() {} diff --git a/widgets/components/IndChandeKrollStop/IndChandeKrollStop.h b/widgets/components/IndChandeKrollStop/IndChandeKrollStop.h index f22d935..1e74ca1 100644 --- a/widgets/components/IndChandeKrollStop/IndChandeKrollStop.h +++ b/widgets/components/IndChandeKrollStop/IndChandeKrollStop.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_chande_kroll_stop(series_, period_, mult_)); + line_names_.push_back("ChandeKrollStop(10,1)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndChandeKrollStop(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10, double mult = 1.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; mult_ = mult; - - lines_.push_back(ind_chande_kroll_stop(series, period_, mult_)); - line_names_.push_back("ChandeKrollStop(10,1)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndChandeKrollStop() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndChandeMomentumOscillator/IndChandeMomentumOscillator.h b/widgets/components/IndChandeMomentumOscillator/IndChandeMomentumOscillator.h index 8a223c4..26b9008 100644 --- a/widgets/components/IndChandeMomentumOscillator/IndChandeMomentumOscillator.h +++ b/widgets/components/IndChandeMomentumOscillator/IndChandeMomentumOscillator.h @@ -204,6 +204,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 20; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_chande_momentum_oscillator(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("ChandeMomentumOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndChandeMomentumOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) @@ -220,13 +237,29 @@ public: name_ = "IndChandeMomentumOscillator"; text_ = "ChandeMomentumOscillator"; series_ = series; - std::vector result = xframe::ind_chande_momentum_oscillator(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("ChandeMomentumOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndChandeMomentumOscillator() {} diff --git a/widgets/components/IndChandelierExit/IndChandelierExit.h b/widgets/components/IndChandelierExit/IndChandelierExit.h index 81130f3..d9dc997 100644 --- a/widgets/components/IndChandelierExit/IndChandelierExit.h +++ b/widgets/components/IndChandelierExit/IndChandelierExit.h @@ -155,6 +155,16 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_chandelier_exit(series_, period_, mult_); + lines_.push_back(Line{"Long Exit", Srgb{0, 150, 0}, result.long_exit}); + lines_.push_back(Line{"Short Exit", Srgb{200, 30, 30}, result.short_exit}); + } + public: std::function on_view_change; IndChandelierExit(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -163,10 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_chandelier_exit(series, period, mult); - lines_.push_back(Line{"Long Exit", Srgb{0, 150, 0}, result.long_exit}); - lines_.push_back(Line{"Short Exit", Srgb{200, 30, 30}, result.short_exit}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndChandelierExit() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndChandelierExitLong/IndChandelierExitLong.h b/widgets/components/IndChandelierExitLong/IndChandelierExitLong.h index b418b6e..cf696ea 100644 --- a/widgets/components/IndChandelierExitLong/IndChandelierExitLong.h +++ b/widgets/components/IndChandelierExitLong/IndChandelierExitLong.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_chandelier_long(series_, period_, mult_)); + line_names_.push_back("ChandelierLong(22,3)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndChandelierExitLong(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 22, double mult = 3.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; mult_ = mult; - - lines_.push_back(ind_chandelier_long(series, period_, mult_)); - line_names_.push_back("ChandelierLong(22,3)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndChandelierExitLong() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndChandelierExitShort/IndChandelierExitShort.h b/widgets/components/IndChandelierExitShort/IndChandelierExitShort.h index 72129c2..8a2373a 100644 --- a/widgets/components/IndChandelierExitShort/IndChandelierExitShort.h +++ b/widgets/components/IndChandelierExitShort/IndChandelierExitShort.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_chandelier_short(series_, period_, mult_)); + line_names_.push_back("ChandelierShort(22,3)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndChandelierExitShort(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 22, double mult = 3.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; mult_ = mult; - - lines_.push_back(ind_chandelier_short(series, period_, mult_)); - line_names_.push_back("ChandelierShort(22,3)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndChandelierExitShort() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndChikouSpan/IndChikouSpan.h b/widgets/components/IndChikouSpan/IndChikouSpan.h index 4eb6b0e..9bc41e4 100644 --- a/widgets/components/IndChikouSpan/IndChikouSpan.h +++ b/widgets/components/IndChikouSpan/IndChikouSpan.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_chikou_span(series_closes(series_), period_)); + line_names_.push_back("ChikouSpan(26)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndChikouSpan(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 26) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_chikou_span(series_closes(series), period_)); - line_names_.push_back("ChikouSpan(26)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndChikouSpan() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndChoppinessIndex/IndChoppinessIndex.h b/widgets/components/IndChoppinessIndex/IndChoppinessIndex.h index 677e707..c0f1da4 100644 --- a/widgets/components/IndChoppinessIndex/IndChoppinessIndex.h +++ b/widgets/components/IndChoppinessIndex/IndChoppinessIndex.h @@ -210,6 +210,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_choppiness_index(series_, period_); + lines_.push_back(result); + line_names_.push_back("ChoppinessIndex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndChoppinessIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -226,13 +243,29 @@ public: name_ = "IndChoppinessIndex"; text_ = "ChoppinessIndex"; series_ = series; - std::vector result = xframe::ind_choppiness_index(series, period); - lines_.push_back(result); - line_names_.push_back("ChoppinessIndex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndChoppinessIndex() {} diff --git a/widgets/components/IndCloseVolatility/IndCloseVolatility.h b/widgets/components/IndCloseVolatility/IndCloseVolatility.h index 7656855..7b9ce01 100644 --- a/widgets/components/IndCloseVolatility/IndCloseVolatility.h +++ b/widgets/components/IndCloseVolatility/IndCloseVolatility.h @@ -148,6 +148,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_close_volatility(series_, period_); + lines_.push_back(Line{"CloseVol", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndCloseVolatility(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -156,9 +165,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_close_volatility(series, period); - lines_.push_back(Line{"CloseVol", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCloseVolatility() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndConnorsRSI/IndConnorsRSI.h b/widgets/components/IndConnorsRSI/IndConnorsRSI.h index 309051c..6a3d35f 100644 --- a/widgets/components/IndConnorsRSI/IndConnorsRSI.h +++ b/widgets/components/IndConnorsRSI/IndConnorsRSI.h @@ -215,6 +215,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_connors_rsi(series_, period_); + lines_.push_back(result); + line_names_.push_back("ConnorsRSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndConnorsRSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 3) @@ -231,13 +248,29 @@ public: name_ = "IndConnorsRSI"; text_ = "ConnorsRSI"; series_ = series; - std::vector result = xframe::ind_connors_rsi(series, period); - lines_.push_back(result); - line_names_.push_back("ConnorsRSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndConnorsRSI() {} diff --git a/widgets/components/IndCoppockCurve/IndCoppockCurve.h b/widgets/components/IndCoppockCurve/IndCoppockCurve.h index 523c318..a068ed8 100644 --- a/widgets/components/IndCoppockCurve/IndCoppockCurve.h +++ b/widgets/components/IndCoppockCurve/IndCoppockCurve.h @@ -210,6 +210,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int roc1_ = 14; + int roc2_ = 11; + int wma_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_coppock_curve(xframe::series_closes(series_), roc1_, roc2_, wma_); + lines_.push_back(result); + line_names_.push_back("CoppockCurve"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndCoppockCurve(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int roc1 = 14, int roc2 = 11, int wma = 10) @@ -226,13 +245,31 @@ public: name_ = "IndCoppockCurve"; text_ = "CoppockCurve"; series_ = series; - std::vector result = xframe::ind_coppock_curve(xframe::series_closes(series), roc1, roc2, wma); - lines_.push_back(result); - line_names_.push_back("CoppockCurve"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + roc1_ = roc1; + roc2_ = roc2; + wma_ = wma; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCoppockCurve() {} diff --git a/widgets/components/IndCorrelation/IndCorrelation.h b/widgets/components/IndCorrelation/IndCorrelation.h index fa57c01..806b665 100644 --- a/widgets/components/IndCorrelation/IndCorrelation.h +++ b/widgets/components/IndCorrelation/IndCorrelation.h @@ -158,6 +158,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_correlation(series_, period_); + lines_.push_back(Line{"Correlation", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndCorrelation(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -166,9 +175,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_correlation(series, period); - lines_.push_back(Line{"Correlation", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCorrelation() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndCorrelationCoefficient/IndCorrelationCoefficient.h b/widgets/components/IndCorrelationCoefficient/IndCorrelationCoefficient.h index adb70c3..5c0f51d 100644 --- a/widgets/components/IndCorrelationCoefficient/IndCorrelationCoefficient.h +++ b/widgets/components/IndCorrelationCoefficient/IndCorrelationCoefficient.h @@ -207,6 +207,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_correlation_coefficient(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("CorrelationCoefficient"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndCorrelationCoefficient(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -223,13 +240,29 @@ public: name_ = "IndCorrelationCoefficient"; text_ = "CorrelationCoefficient"; series_ = series; - std::vector result = xframe::ind_correlation_coefficient(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("CorrelationCoefficient"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCorrelationCoefficient() {} diff --git a/widgets/components/IndCovariance/IndCovariance.h b/widgets/components/IndCovariance/IndCovariance.h index d0ac1e0..5485cdd 100644 --- a/widgets/components/IndCovariance/IndCovariance.h +++ b/widgets/components/IndCovariance/IndCovariance.h @@ -154,6 +154,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_covariance(series_, period_); + lines_.push_back(Line{"Covariance", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndCovariance(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -162,9 +171,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_covariance(series, period); - lines_.push_back(Line{"Covariance", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCovariance() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndCumulativeVolumeDelta/IndCumulativeVolumeDelta.h b/widgets/components/IndCumulativeVolumeDelta/IndCumulativeVolumeDelta.h index cc3b6f3..661d7d8 100644 --- a/widgets/components/IndCumulativeVolumeDelta/IndCumulativeVolumeDelta.h +++ b/widgets/components/IndCumulativeVolumeDelta/IndCumulativeVolumeDelta.h @@ -152,6 +152,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_cumulative_volume_delta(series_, period_); + lines_.push_back(Line{"CumVolDelta", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndCumulativeVolumeDelta(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -160,9 +169,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_cumulative_volume_delta(series, period); - lines_.push_back(Line{"CumVolDelta", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCumulativeVolumeDelta() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndCutlerRSI/IndCutlerRSI.h b/widgets/components/IndCutlerRSI/IndCutlerRSI.h index ca8acca..b3b27a4 100644 --- a/widgets/components/IndCutlerRSI/IndCutlerRSI.h +++ b/widgets/components/IndCutlerRSI/IndCutlerRSI.h @@ -206,6 +206,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_cutler_rsi(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("CutlerRSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndCutlerRSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -222,13 +239,29 @@ public: name_ = "IndCutlerRSI"; text_ = "CutlerRSI"; series_ = series; - std::vector result = xframe::ind_cutler_rsi(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("CutlerRSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCutlerRSI() {} diff --git a/widgets/components/IndCyberCycle/IndCyberCycle.h b/widgets/components/IndCyberCycle/IndCyberCycle.h index bf5cb2c..785aa79 100644 --- a/widgets/components/IndCyberCycle/IndCyberCycle.h +++ b/widgets/components/IndCyberCycle/IndCyberCycle.h @@ -207,6 +207,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_cyber_cycle(xframe::series_closes(series_), dummy_); + lines_.push_back(result); + line_names_.push_back("CyberCycle"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndCyberCycle(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -223,13 +240,29 @@ public: name_ = "IndCyberCycle"; text_ = "CyberCycle"; series_ = series; - std::vector result = xframe::ind_cyber_cycle(xframe::series_closes(series), dummy); - lines_.push_back(result); - line_names_.push_back("CyberCycle"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndCyberCycle() {} diff --git a/widgets/components/IndDEMA/IndDEMA.h b/widgets/components/IndDEMA/IndDEMA.h index 93c1e71..846df6e 100644 --- a/widgets/components/IndDEMA/IndDEMA.h +++ b/widgets/components/IndDEMA/IndDEMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_dema(series_closes(series_), period_)); + line_names_.push_back("DEMA(14)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndDEMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_dema(series_closes(series), period_)); - line_names_.push_back("DEMA(14)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndDEMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndDPO/IndDPO.h b/widgets/components/IndDPO/IndDPO.h index 84ba29f..c945073 100644 --- a/widgets/components/IndDPO/IndDPO.h +++ b/widgets/components/IndDPO/IndDPO.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_dpo(series_closes(series_), period_)); + line_names_.push_back("DPO(20)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndDPO(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_dpo(series_closes(series), period_)); - line_names_.push_back("DPO(20)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndDPO() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndDSS/IndDSS.h b/widgets/components/IndDSS/IndDSS.h index f0b6fe1..3905aeb 100644 --- a/widgets/components/IndDSS/IndDSS.h +++ b/widgets/components/IndDSS/IndDSS.h @@ -197,6 +197,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + int smooth_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_dss(series_, period_, smooth_); + lines_.push_back(result); + line_names_.push_back("DSS"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndDSS(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10, int smooth = 3) @@ -213,13 +231,30 @@ public: name_ = "IndDSS"; text_ = "DSS"; series_ = series; - std::vector result = xframe::ind_dss(series, period, smooth); - lines_.push_back(result); - line_names_.push_back("DSS"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + smooth_ = smooth; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDSS() {} diff --git a/widgets/components/IndDX/IndDX.h b/widgets/components/IndDX/IndDX.h index 324af0f..321d66d 100644 --- a/widgets/components/IndDX/IndDX.h +++ b/widgets/components/IndDX/IndDX.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_dx(series_, period_)); + line_names_.push_back("DX(14)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndDX(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_dx(series, period_)); - line_names_.push_back("DX(14)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndDX() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndDeMarker/IndDeMarker.h b/widgets/components/IndDeMarker/IndDeMarker.h index 2d4d81d..270efd0 100644 --- a/widgets/components/IndDeMarker/IndDeMarker.h +++ b/widgets/components/IndDeMarker/IndDeMarker.h @@ -209,6 +209,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_demarker(series_, period_); + lines_.push_back(result); + line_names_.push_back("DeMarker"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndDeMarker(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -225,13 +242,29 @@ public: name_ = "IndDeMarker"; text_ = "DeMarker"; series_ = series; - std::vector result = xframe::ind_demarker(series, period); - lines_.push_back(result); - line_names_.push_back("DeMarker"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDeMarker() {} diff --git a/widgets/components/IndDecycler/IndDecycler.h b/widgets/components/IndDecycler/IndDecycler.h index fad50af..1560080 100644 --- a/widgets/components/IndDecycler/IndDecycler.h +++ b/widgets/components/IndDecycler/IndDecycler.h @@ -202,6 +202,23 @@ private: int grid_divisions_ = 4; Srgb overlay_candle_color_ = Srgb{180, 180, 180}; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_decycler(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("Decycler"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndDecycler(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) @@ -218,13 +235,29 @@ public: name_ = "IndDecycler"; text_ = "Decycler"; series_ = series; - std::vector result = xframe::ind_decycler(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("Decycler"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDecycler() {} diff --git a/widgets/components/IndDemandIndex/IndDemandIndex.h b/widgets/components/IndDemandIndex/IndDemandIndex.h index 139d7bf..c505f8f 100644 --- a/widgets/components/IndDemandIndex/IndDemandIndex.h +++ b/widgets/components/IndDemandIndex/IndDemandIndex.h @@ -156,6 +156,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_demand_index(series_, period_); + lines_.push_back(Line{"DemandIndex", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndDemandIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,9 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_demand_index(series, period); - lines_.push_back(Line{"DemandIndex", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDemandIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndDetrendedPriceOscillator/IndDetrendedPriceOscillator.h b/widgets/components/IndDetrendedPriceOscillator/IndDetrendedPriceOscillator.h index 0a8636e..768b8f4 100644 --- a/widgets/components/IndDetrendedPriceOscillator/IndDetrendedPriceOscillator.h +++ b/widgets/components/IndDetrendedPriceOscillator/IndDetrendedPriceOscillator.h @@ -202,6 +202,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 20; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_detrended_price_oscillator(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("DetrendedPriceOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndDetrendedPriceOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) @@ -218,13 +235,29 @@ public: name_ = "IndDetrendedPriceOscillator"; text_ = "DetrendedPriceOscillator"; series_ = series; - std::vector result = xframe::ind_detrended_price_oscillator(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("DetrendedPriceOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDetrendedPriceOscillator() {} diff --git a/widgets/components/IndDisparityIndex/IndDisparityIndex.h b/widgets/components/IndDisparityIndex/IndDisparityIndex.h index ecda00e..2980086 100644 --- a/widgets/components/IndDisparityIndex/IndDisparityIndex.h +++ b/widgets/components/IndDisparityIndex/IndDisparityIndex.h @@ -198,6 +198,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 20; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_disparity_index(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("DisparityIndex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndDisparityIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) @@ -214,13 +231,29 @@ public: name_ = "IndDisparityIndex"; text_ = "DisparityIndex"; series_ = series; - std::vector result = xframe::ind_disparity_index(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("DisparityIndex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDisparityIndex() {} diff --git a/widgets/components/IndDominantCycle/IndDominantCycle.h b/widgets/components/IndDominantCycle/IndDominantCycle.h index dc75f87..8ddc321 100644 --- a/widgets/components/IndDominantCycle/IndDominantCycle.h +++ b/widgets/components/IndDominantCycle/IndDominantCycle.h @@ -214,6 +214,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_dominant_cycle(xframe::series_closes(series_), dummy_); + lines_.push_back(result); + line_names_.push_back("DominantCycle"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndDominantCycle(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -230,13 +247,29 @@ public: name_ = "IndDominantCycle"; text_ = "DominantCycle"; series_ = series; - std::vector result = xframe::ind_dominant_cycle(xframe::series_closes(series), dummy); - lines_.push_back(result); - line_names_.push_back("DominantCycle"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDominantCycle() {} diff --git a/widgets/components/IndDominantCyclePeriod/IndDominantCyclePeriod.h b/widgets/components/IndDominantCyclePeriod/IndDominantCyclePeriod.h index 799e1cf..6e6a445 100644 --- a/widgets/components/IndDominantCyclePeriod/IndDominantCyclePeriod.h +++ b/widgets/components/IndDominantCyclePeriod/IndDominantCyclePeriod.h @@ -157,6 +157,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_dominant_cycle_period(series_, period_); + lines_.push_back(Line{"CyclePeriod", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndDominantCyclePeriod(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -165,9 +174,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_dominant_cycle_period(series, period); - lines_.push_back(Line{"CyclePeriod", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDominantCyclePeriod() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndDonchianChannels/IndDonchianChannels.h b/widgets/components/IndDonchianChannels/IndDonchianChannels.h index a827f46..5ca2d4f 100644 --- a/widgets/components/IndDonchianChannels/IndDonchianChannels.h +++ b/widgets/components/IndDonchianChannels/IndDonchianChannels.h @@ -154,6 +154,17 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_donchian_channels(series_, period_); + lines_.push_back(Line{"Upper", Srgb{200, 30, 30}, result.upper}); + lines_.push_back(Line{"Middle", Srgb{0, 100, 200}, result.middle}); + lines_.push_back(Line{"Lower", Srgb{200, 30, 30}, result.lower}); + } + public: std::function on_view_change; IndDonchianChannels(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -162,11 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_donchian_channels(series, period); - lines_.push_back(Line{"Upper", Srgb{200, 30, 30}, result.upper}); - lines_.push_back(Line{"Middle", Srgb{0, 100, 200}, result.middle}); - lines_.push_back(Line{"Lower", Srgb{200, 30, 30}, result.lower}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDonchianChannels() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndDonchianLower/IndDonchianLower.h b/widgets/components/IndDonchianLower/IndDonchianLower.h index f391f58..b52b872 100644 --- a/widgets/components/IndDonchianLower/IndDonchianLower.h +++ b/widgets/components/IndDonchianLower/IndDonchianLower.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_donchian_lower(series_, period_)); + line_names_.push_back("DonchianLower(20)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndDonchianLower(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_donchian_lower(series, period_)); - line_names_.push_back("DonchianLower(20)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndDonchianLower() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndDonchianMiddle/IndDonchianMiddle.h b/widgets/components/IndDonchianMiddle/IndDonchianMiddle.h index 79922bb..90bfa59 100644 --- a/widgets/components/IndDonchianMiddle/IndDonchianMiddle.h +++ b/widgets/components/IndDonchianMiddle/IndDonchianMiddle.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_donchian_middle(series_, period_)); + line_names_.push_back("DonchianMiddle(20)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndDonchianMiddle(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_donchian_middle(series, period_)); - line_names_.push_back("DonchianMiddle(20)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndDonchianMiddle() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndDonchianUpper/IndDonchianUpper.h b/widgets/components/IndDonchianUpper/IndDonchianUpper.h index d9de77c..55f7d88 100644 --- a/widgets/components/IndDonchianUpper/IndDonchianUpper.h +++ b/widgets/components/IndDonchianUpper/IndDonchianUpper.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_donchian_upper(series_, period_)); + line_names_.push_back("DonchianUpper(20)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndDonchianUpper(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_donchian_upper(series, period_)); - line_names_.push_back("DonchianUpper(20)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndDonchianUpper() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndDoubleStochastic/IndDoubleStochastic.h b/widgets/components/IndDoubleStochastic/IndDoubleStochastic.h index ffd7f96..3003b43 100644 --- a/widgets/components/IndDoubleStochastic/IndDoubleStochastic.h +++ b/widgets/components/IndDoubleStochastic/IndDoubleStochastic.h @@ -199,6 +199,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + int short_period_ = 5; + int smooth_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_double_stochastic(series_, period_, short_period_, smooth_); + lines_.push_back(result); + line_names_.push_back("DoubleStochastic"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndDoubleStochastic(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14, int short_period = 5, int smooth = 3) @@ -215,13 +234,31 @@ public: name_ = "IndDoubleStochastic"; text_ = "DoubleStochastic"; series_ = series; - std::vector result = xframe::ind_double_stochastic(series, period, short_period, smooth); - lines_.push_back(result); - line_names_.push_back("DoubleStochastic"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + short_period_ = short_period; + smooth_ = smooth; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDoubleStochastic() {} diff --git a/widgets/components/IndDynamicMomentumIndex/IndDynamicMomentumIndex.h b/widgets/components/IndDynamicMomentumIndex/IndDynamicMomentumIndex.h index d03c45f..8ad44d4 100644 --- a/widgets/components/IndDynamicMomentumIndex/IndDynamicMomentumIndex.h +++ b/widgets/components/IndDynamicMomentumIndex/IndDynamicMomentumIndex.h @@ -219,6 +219,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_dynamic_momentum_index(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("DynamicMomentumIndex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndDynamicMomentumIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -235,13 +252,29 @@ public: name_ = "IndDynamicMomentumIndex"; text_ = "DynamicMomentumIndex"; series_ = series; - std::vector result = xframe::ind_dynamic_momentum_index(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("DynamicMomentumIndex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndDynamicMomentumIndex() {} diff --git a/widgets/components/IndEMA/IndEMA.h b/widgets/components/IndEMA/IndEMA.h index 530d00e..502ae15 100644 --- a/widgets/components/IndEMA/IndEMA.h +++ b/widgets/components/IndEMA/IndEMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_ema(series_closes(series_), period_)); + line_names_.push_back("EMA(14)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndEMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_ema(series_closes(series), period_)); - line_names_.push_back("EMA(14)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndEMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndEaseOfMovement/IndEaseOfMovement.h b/widgets/components/IndEaseOfMovement/IndEaseOfMovement.h index 426892c..b682e0c 100644 --- a/widgets/components/IndEaseOfMovement/IndEaseOfMovement.h +++ b/widgets/components/IndEaseOfMovement/IndEaseOfMovement.h @@ -150,6 +150,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_ease_of_movement(series_, period_); + lines_.push_back(Line{"EMV", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndEaseOfMovement(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -158,9 +167,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_ease_of_movement(series, period); - lines_.push_back(Line{"EMV", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndEaseOfMovement() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndEfficiencyRatio/IndEfficiencyRatio.h b/widgets/components/IndEfficiencyRatio/IndEfficiencyRatio.h index 9b138ab..ca57fe2 100644 --- a/widgets/components/IndEfficiencyRatio/IndEfficiencyRatio.h +++ b/widgets/components/IndEfficiencyRatio/IndEfficiencyRatio.h @@ -152,6 +152,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_efficiency_ratio(series_, period_); + lines_.push_back(Line{"EffRatio", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndEfficiencyRatio(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -160,9 +169,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_efficiency_ratio(series, period); - lines_.push_back(Line{"EffRatio", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndEfficiencyRatio() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndEhlersDecycler/IndEhlersDecycler.h b/widgets/components/IndEhlersDecycler/IndEhlersDecycler.h index 1a860b7..2bfc99c 100644 --- a/widgets/components/IndEhlersDecycler/IndEhlersDecycler.h +++ b/widgets/components/IndEhlersDecycler/IndEhlersDecycler.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_ehlers_decycler(series_closes(series_), period_)); + line_names_.push_back("EhlersDecycler(10)"); + line_colors_.push_back(Srgb{0, 150, 150}); + } + public: IndEhlersDecycler(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_ehlers_decycler(series_closes(series), period_)); - line_names_.push_back("EhlersDecycler(10)"); - line_colors_.push_back(Srgb{0, 150, 150}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndEhlersDecycler() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndEhlersSmoothedRSI/IndEhlersSmoothedRSI.h b/widgets/components/IndEhlersSmoothedRSI/IndEhlersSmoothedRSI.h index 8c5ae85..fc1c5d7 100644 --- a/widgets/components/IndEhlersSmoothedRSI/IndEhlersSmoothedRSI.h +++ b/widgets/components/IndEhlersSmoothedRSI/IndEhlersSmoothedRSI.h @@ -196,6 +196,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_ehlers_smoothed_rsi(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("EhlersSmoothedRSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndEhlersSmoothedRSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -212,13 +229,29 @@ public: name_ = "IndEhlersSmoothedRSI"; text_ = "EhlersSmoothedRSI"; series_ = series; - std::vector result = xframe::ind_ehlers_smoothed_rsi(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("EhlersSmoothedRSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndEhlersSmoothedRSI() {} diff --git a/widgets/components/IndEhlersSuperSmoother/IndEhlersSuperSmoother.h b/widgets/components/IndEhlersSuperSmoother/IndEhlersSuperSmoother.h index fe07951..0c90826 100644 --- a/widgets/components/IndEhlersSuperSmoother/IndEhlersSuperSmoother.h +++ b/widgets/components/IndEhlersSuperSmoother/IndEhlersSuperSmoother.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_ehlers_super_smoother(series_closes(series_), period_)); + line_names_.push_back("SuperSmoother(10)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndEhlersSuperSmoother(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_ehlers_super_smoother(series_closes(series), period_)); - line_names_.push_back("SuperSmoother(10)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndEhlersSuperSmoother() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndEhlersTrendline/IndEhlersTrendline.h b/widgets/components/IndEhlersTrendline/IndEhlersTrendline.h index 0a53a9d..bc43637 100644 --- a/widgets/components/IndEhlersTrendline/IndEhlersTrendline.h +++ b/widgets/components/IndEhlersTrendline/IndEhlersTrendline.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_ehlers_trendline(series_closes(series_), alpha_)); + line_names_.push_back("EhlersTrendline(0.07)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndEhlersTrendline(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), double alpha = 0.07) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { alpha_ = alpha; - - lines_.push_back(ind_ehlers_trendline(series_closes(series), alpha_)); - line_names_.push_back("EhlersTrendline(0.07)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndEhlersTrendline() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndElderForceIndex/IndElderForceIndex.h b/widgets/components/IndElderForceIndex/IndElderForceIndex.h index 5bea4a0..00e0621 100644 --- a/widgets/components/IndElderForceIndex/IndElderForceIndex.h +++ b/widgets/components/IndElderForceIndex/IndElderForceIndex.h @@ -198,6 +198,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 13; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_elder_force_index(series_, period_); + lines_.push_back(result); + line_names_.push_back("ElderForceIndex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndElderForceIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 13) @@ -214,13 +231,29 @@ public: name_ = "IndElderForceIndex"; text_ = "ElderForceIndex"; series_ = series; - std::vector result = xframe::ind_elder_force_index(series, period); - lines_.push_back(result); - line_names_.push_back("ElderForceIndex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndElderForceIndex() {} diff --git a/widgets/components/IndElderImpulse/IndElderImpulse.h b/widgets/components/IndElderImpulse/IndElderImpulse.h index c9baf65..44bd581 100644 --- a/widgets/components/IndElderImpulse/IndElderImpulse.h +++ b/widgets/components/IndElderImpulse/IndElderImpulse.h @@ -211,6 +211,25 @@ private: int grid_divisions_ = 4; Srgb overlay_candle_color_ = Srgb{180, 180, 180}; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int ema_period_ = 13; + int fast_ = 12; + int slow_ = 26; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_elder_impulse(series_, ema_period_, fast_, slow_); + lines_.push_back(result); + line_names_.push_back("ElderImpulse"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndElderImpulse(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int ema_period = 13, int fast = 12, int slow = 26) @@ -227,13 +246,31 @@ public: name_ = "IndElderImpulse"; text_ = "ElderImpulse"; series_ = series; - std::vector result = xframe::ind_elder_impulse(series, ema_period, fast, slow); - lines_.push_back(result); - line_names_.push_back("ElderImpulse"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + ema_period_ = ema_period; + fast_ = fast; + slow_ = slow; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndElderImpulse() {} diff --git a/widgets/components/IndElderRayBear/IndElderRayBear.h b/widgets/components/IndElderRayBear/IndElderRayBear.h index cb6629a..6017bcc 100644 --- a/widgets/components/IndElderRayBear/IndElderRayBear.h +++ b/widgets/components/IndElderRayBear/IndElderRayBear.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_elder_ray_bear(series_, period_)); + line_names_.push_back("BearPower(13)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndElderRayBear(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 13) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_elder_ray_bear(series, period_)); - line_names_.push_back("BearPower(13)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndElderRayBear() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndElderRayBull/IndElderRayBull.h b/widgets/components/IndElderRayBull/IndElderRayBull.h index da4cd0f..ceabf2b 100644 --- a/widgets/components/IndElderRayBull/IndElderRayBull.h +++ b/widgets/components/IndElderRayBull/IndElderRayBull.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_elder_ray_bull(series_, period_)); + line_names_.push_back("BullPower(13)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndElderRayBull(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 13) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_elder_ray_bull(series, period_)); - line_names_.push_back("BullPower(13)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndElderRayBull() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndElderSafeZone/IndElderSafeZone.h b/widgets/components/IndElderSafeZone/IndElderSafeZone.h index 84a1e7a..8cf1a4d 100644 --- a/widgets/components/IndElderSafeZone/IndElderSafeZone.h +++ b/widgets/components/IndElderSafeZone/IndElderSafeZone.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_elder_safe_zone(series_, period_, mult_)); + line_names_.push_back("ElderSafeZone(10,2)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndElderSafeZone(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10, double mult = 2.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; mult_ = mult; - - lines_.push_back(ind_elder_safe_zone(series, period_, mult_)); - line_names_.push_back("ElderSafeZone(10,2)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndElderSafeZone() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndErgodicOscillator/IndErgodicOscillator.h b/widgets/components/IndErgodicOscillator/IndErgodicOscillator.h index 0400b6a..c2e85a1 100644 --- a/widgets/components/IndErgodicOscillator/IndErgodicOscillator.h +++ b/widgets/components/IndErgodicOscillator/IndErgodicOscillator.h @@ -201,6 +201,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int long_period_ = 5; + int short_period_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_ergodic_oscillator(xframe::series_closes(series_), long_period_, short_period_); + lines_.push_back(result); + line_names_.push_back("ErgodicOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndErgodicOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int long_period = 5, int short_period = 3) @@ -217,13 +235,30 @@ public: name_ = "IndErgodicOscillator"; text_ = "ErgodicOscillator"; series_ = series; - std::vector result = xframe::ind_ergodic_oscillator(xframe::series_closes(series), long_period, short_period); - lines_.push_back(result); - line_names_.push_back("ErgodicOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + long_period_ = long_period; + short_period_ = short_period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndErgodicOscillator() {} diff --git a/widgets/components/IndEvenBetterSineWave/IndEvenBetterSineWave.h b/widgets/components/IndEvenBetterSineWave/IndEvenBetterSineWave.h index 138cb5f..30fe697 100644 --- a/widgets/components/IndEvenBetterSineWave/IndEvenBetterSineWave.h +++ b/widgets/components/IndEvenBetterSineWave/IndEvenBetterSineWave.h @@ -212,6 +212,27 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + int hp_period_ = 48; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + xframe::IndEvenBetterSineWaveResult result = xframe::ind_even_better_sinewave(xframe::series_closes(series_), period_, hp_period_); + lines_.push_back(result.sine); + line_names_.push_back("sine"); + line_colors_.push_back(Srgb{0, 100, 200}); + lines_.push_back(result.lead_sine); + line_names_.push_back("lead_sine"); + line_colors_.push_back(Srgb{200, 30, 30}); + + } + public: IndEvenBetterSineWave(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10, int hp_period = 48) @@ -228,16 +249,30 @@ public: name_ = "IndEvenBetterSineWave"; text_ = "EvenBetterSineWave"; series_ = series; - xframe::IndEvenBetterSineWaveResult result = xframe::ind_even_better_sinewave(xframe::series_closes(series), period, hp_period); - lines_.push_back(result.sine); - line_names_.push_back("sine"); - line_colors_.push_back(Srgb{0, 100, 200}); - lines_.push_back(result.lead_sine); - line_names_.push_back("lead_sine"); - line_colors_.push_back(Srgb{200, 30, 30}); - view_count_ = (double)item_count(); + period_ = period; + hp_period_ = hp_period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndEvenBetterSineWave() {} diff --git a/widgets/components/IndFAMA/IndFAMA.h b/widgets/components/IndFAMA/IndFAMA.h index acdded6..bfcb0bc 100644 --- a/widgets/components/IndFAMA/IndFAMA.h +++ b/widgets/components/IndFAMA/IndFAMA.h @@ -246,18 +246,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_fama(series_closes(series_), fastlimit_, slowlimit_)); + line_names_.push_back("FAMA(0.5,0.05)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndFAMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), double fastlimit = 0.5, double slowlimit = 0.05) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { fastlimit_ = fastlimit; slowlimit_ = slowlimit; - - lines_.push_back(ind_fama(series_closes(series), fastlimit_, slowlimit_)); - line_names_.push_back("FAMA(0.5,0.05)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndFAMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndFRAMA/IndFRAMA.h b/widgets/components/IndFRAMA/IndFRAMA.h index 8b57cd3..05ab682 100644 --- a/widgets/components/IndFRAMA/IndFRAMA.h +++ b/widgets/components/IndFRAMA/IndFRAMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_frama(series_closes(series_), period_)); + line_names_.push_back("FRAMA(16)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndFRAMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 16) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_frama(series_closes(series), period_)); - line_names_.push_back("FRAMA(16)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndFRAMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndFibonacciPivotPoints/IndFibonacciPivotPoints.h b/widgets/components/IndFibonacciPivotPoints/IndFibonacciPivotPoints.h index 6916faa..13aeca1 100644 --- a/widgets/components/IndFibonacciPivotPoints/IndFibonacciPivotPoints.h +++ b/widgets/components/IndFibonacciPivotPoints/IndFibonacciPivotPoints.h @@ -156,6 +156,17 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_fibonacci_pivot_points(series_, period_); + lines_.push_back(Line{"Pivot", Srgb{0, 100, 200}, result.pivot}); + lines_.push_back(Line{"R1", Srgb{200, 30, 30}, result.r1}); + lines_.push_back(Line{"S1", Srgb{0, 150, 0}, result.s1}); + } + public: std::function on_view_change; IndFibonacciPivotPoints(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,11 +175,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_fibonacci_pivot_points(series, period); - lines_.push_back(Line{"Pivot", Srgb{0, 100, 200}, result.pivot}); - lines_.push_back(Line{"R1", Srgb{200, 30, 30}, result.r1}); - lines_.push_back(Line{"S1", Srgb{0, 150, 0}, result.s1}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndFibonacciPivotPoints() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndFisherTransform/IndFisherTransform.h b/widgets/components/IndFisherTransform/IndFisherTransform.h index 0e0b73e..17c72c5 100644 --- a/widgets/components/IndFisherTransform/IndFisherTransform.h +++ b/widgets/components/IndFisherTransform/IndFisherTransform.h @@ -206,6 +206,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_fisher_transform(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("FisherTransform"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndFisherTransform(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) @@ -222,13 +239,29 @@ public: name_ = "IndFisherTransform"; text_ = "FisherTransform"; series_ = series; - std::vector result = xframe::ind_fisher_transform(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("FisherTransform"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndFisherTransform() {} diff --git a/widgets/components/IndFractalDimension/IndFractalDimension.h b/widgets/components/IndFractalDimension/IndFractalDimension.h index 40b8ac0..f2845c8 100644 --- a/widgets/components/IndFractalDimension/IndFractalDimension.h +++ b/widgets/components/IndFractalDimension/IndFractalDimension.h @@ -160,6 +160,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_fractal_dimension(series_, period_); + lines_.push_back(Line{"FractalDim", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndFractalDimension(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -168,9 +177,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_fractal_dimension(series, period); - lines_.push_back(Line{"FractalDim", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndFractalDimension() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndFractalDimensionIndex/IndFractalDimensionIndex.h b/widgets/components/IndFractalDimensionIndex/IndFractalDimensionIndex.h index aacafa4..6d0d23f 100644 --- a/widgets/components/IndFractalDimensionIndex/IndFractalDimensionIndex.h +++ b/widgets/components/IndFractalDimensionIndex/IndFractalDimensionIndex.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_fractal_dimension_index(series_closes(series_), period_)); + line_names_.push_back("FDI(30)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndFractalDimensionIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 30) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_fractal_dimension_index(series_closes(series), period_)); - line_names_.push_back("FDI(30)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndFractalDimensionIndex() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndFractalDown/IndFractalDown.h b/widgets/components/IndFractalDown/IndFractalDown.h index 8d1d894..fa74221 100644 --- a/widgets/components/IndFractalDown/IndFractalDown.h +++ b/widgets/components/IndFractalDown/IndFractalDown.h @@ -231,16 +231,41 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + lines_.push_back(ind_fractal_down(series_)); + line_names_.push_back("FractalDown"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndFractalDown(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250)) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { - - lines_.push_back(ind_fractal_down(series)); - line_names_.push_back("FractalDown"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndFractalDown() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndFractalUp/IndFractalUp.h b/widgets/components/IndFractalUp/IndFractalUp.h index a30cc75..408d020 100644 --- a/widgets/components/IndFractalUp/IndFractalUp.h +++ b/widgets/components/IndFractalUp/IndFractalUp.h @@ -231,16 +231,41 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + lines_.push_back(ind_fractal_up(series_)); + line_names_.push_back("FractalUp"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndFractalUp(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250)) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { - - lines_.push_back(ind_fractal_up(series)); - line_names_.push_back("FractalUp"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndFractalUp() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndGannHiLoActivator/IndGannHiLoActivator.h b/widgets/components/IndGannHiLoActivator/IndGannHiLoActivator.h index aa0cc17..55f9f1a 100644 --- a/widgets/components/IndGannHiLoActivator/IndGannHiLoActivator.h +++ b/widgets/components/IndGannHiLoActivator/IndGannHiLoActivator.h @@ -215,6 +215,23 @@ private: int grid_divisions_ = 4; Srgb overlay_candle_color_ = Srgb{180, 180, 180}; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_gann_hilo_activator(series_, period_); + lines_.push_back(result); + line_names_.push_back("GannHiLoActivator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndGannHiLoActivator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 3) @@ -231,13 +248,29 @@ public: name_ = "IndGannHiLoActivator"; text_ = "GannHiLoActivator"; series_ = series; - std::vector result = xframe::ind_gann_hilo_activator(series, period); - lines_.push_back(result); - line_names_.push_back("GannHiLoActivator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndGannHiLoActivator() {} diff --git a/widgets/components/IndGannSwingOscillator/IndGannSwingOscillator.h b/widgets/components/IndGannSwingOscillator/IndGannSwingOscillator.h index 760fae7..d6326d9 100644 --- a/widgets/components/IndGannSwingOscillator/IndGannSwingOscillator.h +++ b/widgets/components/IndGannSwingOscillator/IndGannSwingOscillator.h @@ -205,6 +205,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_gann_swing_oscillator(series_, dummy_); + lines_.push_back(result); + line_names_.push_back("GannSwingOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndGannSwingOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -221,13 +238,29 @@ public: name_ = "IndGannSwingOscillator"; text_ = "GannSwingOscillator"; series_ = series; - std::vector result = xframe::ind_gann_swing_oscillator(series, dummy); - lines_.push_back(result); - line_names_.push_back("GannSwingOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndGannSwingOscillator() {} diff --git a/widgets/components/IndGarmanKlassVolatility/IndGarmanKlassVolatility.h b/widgets/components/IndGarmanKlassVolatility/IndGarmanKlassVolatility.h index d656e72..2dcd1d2 100644 --- a/widgets/components/IndGarmanKlassVolatility/IndGarmanKlassVolatility.h +++ b/widgets/components/IndGarmanKlassVolatility/IndGarmanKlassVolatility.h @@ -156,6 +156,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_garman_klass_volatility(series_, period_); + lines_.push_back(Line{"GarmanKlass", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndGarmanKlassVolatility(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,9 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_garman_klass_volatility(series, period); - lines_.push_back(Line{"GarmanKlass", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndGarmanKlassVolatility() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndGatorOscillator/IndGatorOscillator.h b/widgets/components/IndGatorOscillator/IndGatorOscillator.h index f520d45..ff74733 100644 --- a/widgets/components/IndGatorOscillator/IndGatorOscillator.h +++ b/widgets/components/IndGatorOscillator/IndGatorOscillator.h @@ -232,14 +232,39 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + { auto gr = ind_gator(series_closes(series_)); lines_.push_back(gr.upper); line_names_.push_back("Gator+"); line_colors_.push_back(Srgb{0, 150, 0}); lines_.push_back(gr.lower); line_names_.push_back("Gator-"); line_colors_.push_back(Srgb{200, 30, 30}); } + } + public: IndGatorOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250)) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { - - { auto gr = ind_gator(series_closes(series)); lines_.push_back(gr.upper); line_names_.push_back("Gator+"); line_colors_.push_back(Srgb{0, 150, 0}); lines_.push_back(gr.lower); line_names_.push_back("Gator-"); line_colors_.push_back(Srgb{200, 30, 30}); } - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndGatorOscillator() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndGaussianMA/IndGaussianMA.h b/widgets/components/IndGaussianMA/IndGaussianMA.h index ea8eec4..757752a 100644 --- a/widgets/components/IndGaussianMA/IndGaussianMA.h +++ b/widgets/components/IndGaussianMA/IndGaussianMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_gaussian_ma(series_closes(series_), period_)); + line_names_.push_back("GaussianMA(14)"); + line_colors_.push_back(Srgb{150, 90, 30}); + } + public: IndGaussianMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_gaussian_ma(series_closes(series), period_)); - line_names_.push_back("GaussianMA(14)"); - line_colors_.push_back(Srgb{150, 90, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndGaussianMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndGopalakrishnanRangeIndex/IndGopalakrishnanRangeIndex.h b/widgets/components/IndGopalakrishnanRangeIndex/IndGopalakrishnanRangeIndex.h index a8e7135..675ce81 100644 --- a/widgets/components/IndGopalakrishnanRangeIndex/IndGopalakrishnanRangeIndex.h +++ b/widgets/components/IndGopalakrishnanRangeIndex/IndGopalakrishnanRangeIndex.h @@ -154,6 +154,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_gopalakrishnan_range_index(series_, period_); + lines_.push_back(Line{"GAPO", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndGopalakrishnanRangeIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -162,9 +171,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_gopalakrishnan_range_index(series, period); - lines_.push_back(Line{"GAPO", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndGopalakrishnanRangeIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndGuppyMMA/IndGuppyMMA.h b/widgets/components/IndGuppyMMA/IndGuppyMMA.h index 39b16e8..b2967dd 100644 --- a/widgets/components/IndGuppyMMA/IndGuppyMMA.h +++ b/widgets/components/IndGuppyMMA/IndGuppyMMA.h @@ -232,14 +232,39 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + { auto gr = ind_guppy_mma(series_closes(series_)); const int ps[12] = {3, 5, 8, 10, 12, 15, 30, 35, 40, 45, 50, 60}; const Srgb cols[12] = {Srgb{0, 100, 200}, Srgb{0, 150, 0}, Srgb{200, 30, 30}, Srgb{230, 126, 34}, Srgb{120, 60, 180}, Srgb{0, 150, 150}, Srgb{150, 90, 30}, Srgb{60, 60, 180}, Srgb{180, 60, 120}, Srgb{90, 140, 40}, Srgb{40, 120, 160}, Srgb{160, 40, 40}}; for (int k = 0; k < 12; ++k) { lines_.push_back(gr.lines[(size_t)k]); line_names_.push_back(std::string("EMA(") + std::to_string(ps[k]) + ")"); line_colors_.push_back(cols[k]); } } + } + public: IndGuppyMMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250)) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { - - { auto gr = ind_guppy_mma(series_closes(series)); const int ps[12] = {3, 5, 8, 10, 12, 15, 30, 35, 40, 45, 50, 60}; const Srgb cols[12] = {Srgb{0, 100, 200}, Srgb{0, 150, 0}, Srgb{200, 30, 30}, Srgb{230, 126, 34}, Srgb{120, 60, 180}, Srgb{0, 150, 150}, Srgb{150, 90, 30}, Srgb{60, 60, 180}, Srgb{180, 60, 120}, Srgb{90, 140, 40}, Srgb{40, 120, 160}, Srgb{160, 40, 40}}; for (int k = 0; k < 12; ++k) { lines_.push_back(gr.lines[(size_t)k]); line_names_.push_back(std::string("EMA(") + std::to_string(ps[k]) + ")"); line_colors_.push_back(cols[k]); } } - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndGuppyMMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndHMA/IndHMA.h b/widgets/components/IndHMA/IndHMA.h index 09bd370..723e48e 100644 --- a/widgets/components/IndHMA/IndHMA.h +++ b/widgets/components/IndHMA/IndHMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_hma(series_closes(series_), period_)); + line_names_.push_back("HMA(16)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndHMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 16) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_hma(series_closes(series), period_)); - line_names_.push_back("HMA(16)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndHMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndHalfTrend/IndHalfTrend.h b/widgets/components/IndHalfTrend/IndHalfTrend.h index c20424f..6538b7a 100644 --- a/widgets/components/IndHalfTrend/IndHalfTrend.h +++ b/widgets/components/IndHalfTrend/IndHalfTrend.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_half_trend(series_, amplitude_, channelDeviation_)); + line_names_.push_back("HalfTrend(2,2)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndHalfTrend(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int amplitude = 2, double channelDeviation = 2.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { amplitude_ = amplitude; channelDeviation_ = channelDeviation; - - lines_.push_back(ind_half_trend(series, amplitude_, channelDeviation_)); - line_names_.push_back("HalfTrend(2,2)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndHalfTrend() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndHighLowRange/IndHighLowRange.h b/widgets/components/IndHighLowRange/IndHighLowRange.h index 349e35f..cd18d1d 100644 --- a/widgets/components/IndHighLowRange/IndHighLowRange.h +++ b/widgets/components/IndHighLowRange/IndHighLowRange.h @@ -148,6 +148,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_high_low_range(series_, period_); + lines_.push_back(Line{"HLRange", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndHighLowRange(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -156,9 +165,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_high_low_range(series, period); - lines_.push_back(Line{"HLRange", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndHighLowRange() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndHistoricalVolatility/IndHistoricalVolatility.h b/widgets/components/IndHistoricalVolatility/IndHistoricalVolatility.h index 904be7a..1438ef3 100644 --- a/widgets/components/IndHistoricalVolatility/IndHistoricalVolatility.h +++ b/widgets/components/IndHistoricalVolatility/IndHistoricalVolatility.h @@ -148,6 +148,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_historical_volatility(series_, period_); + lines_.push_back(Line{"HistVol", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndHistoricalVolatility(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -156,9 +165,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_historical_volatility(series, period); - lines_.push_back(Line{"HistVol", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndHistoricalVolatility() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndHurstExponent/IndHurstExponent.h b/widgets/components/IndHurstExponent/IndHurstExponent.h index f92c270..5b59961 100644 --- a/widgets/components/IndHurstExponent/IndHurstExponent.h +++ b/widgets/components/IndHurstExponent/IndHurstExponent.h @@ -160,6 +160,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_hurst_exponent(series_, period_); + lines_.push_back(Line{"Hurst", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndHurstExponent(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -168,9 +177,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_hurst_exponent(series, period); - lines_.push_back(Line{"Hurst", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndHurstExponent() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndInertia/IndInertia.h b/widgets/components/IndInertia/IndInertia.h index 5bbf16e..7aa3d5b 100644 --- a/widgets/components/IndInertia/IndInertia.h +++ b/widgets/components/IndInertia/IndInertia.h @@ -196,6 +196,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 20; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_inertia(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("Inertia"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndInertia(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) @@ -212,13 +229,29 @@ public: name_ = "IndInertia"; text_ = "Inertia"; series_ = series; - std::vector result = xframe::ind_inertia(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("Inertia"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndInertia() {} diff --git a/widgets/components/IndIntradayIntensityIndex/IndIntradayIntensityIndex.h b/widgets/components/IndIntradayIntensityIndex/IndIntradayIntensityIndex.h index 2eea27c..c1578e3 100644 --- a/widgets/components/IndIntradayIntensityIndex/IndIntradayIntensityIndex.h +++ b/widgets/components/IndIntradayIntensityIndex/IndIntradayIntensityIndex.h @@ -155,6 +155,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_intraday_intensity_index(series_, period_); + lines_.push_back(Line{"IntradayIntensity", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndIntradayIntensityIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -163,9 +172,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_intraday_intensity_index(series, period); - lines_.push_back(Line{"IntradayIntensity", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndIntradayIntensityIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndIntradayMomentumIndex/IndIntradayMomentumIndex.h b/widgets/components/IndIntradayMomentumIndex/IndIntradayMomentumIndex.h index e5eeb1c..fe28a4d 100644 --- a/widgets/components/IndIntradayMomentumIndex/IndIntradayMomentumIndex.h +++ b/widgets/components/IndIntradayMomentumIndex/IndIntradayMomentumIndex.h @@ -204,6 +204,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_intraday_momentum_index(series_, period_); + lines_.push_back(result); + line_names_.push_back("IntradayMomentumIndex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndIntradayMomentumIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -220,13 +237,29 @@ public: name_ = "IndIntradayMomentumIndex"; text_ = "IntradayMomentumIndex"; series_ = series; - std::vector result = xframe::ind_intraday_momentum_index(series, period); - lines_.push_back(result); - line_names_.push_back("IntradayMomentumIndex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndIntradayMomentumIndex() {} diff --git a/widgets/components/IndInverseFisherTransform/IndInverseFisherTransform.h b/widgets/components/IndInverseFisherTransform/IndInverseFisherTransform.h index 5b4c1bb..f5e3f53 100644 --- a/widgets/components/IndInverseFisherTransform/IndInverseFisherTransform.h +++ b/widgets/components/IndInverseFisherTransform/IndInverseFisherTransform.h @@ -205,6 +205,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_inverse_fisher_transform(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("InverseFisherTransform"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndInverseFisherTransform(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -221,13 +238,29 @@ public: name_ = "IndInverseFisherTransform"; text_ = "InverseFisherTransform"; series_ = series; - std::vector result = xframe::ind_inverse_fisher_transform(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("InverseFisherTransform"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndInverseFisherTransform() {} diff --git a/widgets/components/IndJurikMovingAverage/IndJurikMovingAverage.h b/widgets/components/IndJurikMovingAverage/IndJurikMovingAverage.h index c4915e1..a8eb87e 100644 --- a/widgets/components/IndJurikMovingAverage/IndJurikMovingAverage.h +++ b/widgets/components/IndJurikMovingAverage/IndJurikMovingAverage.h @@ -196,6 +196,23 @@ private: int grid_divisions_ = 4; Srgb overlay_candle_color_ = Srgb{180, 180, 180}; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 20; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_jurik_moving_average(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("JurikMovingAverage"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndJurikMovingAverage(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) @@ -212,13 +229,29 @@ public: name_ = "IndJurikMovingAverage"; text_ = "JurikMovingAverage"; series_ = series; - std::vector result = xframe::ind_jurik_moving_average(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("JurikMovingAverage"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndJurikMovingAverage() {} diff --git a/widgets/components/IndJurikVelocity/IndJurikVelocity.h b/widgets/components/IndJurikVelocity/IndJurikVelocity.h index 62405d7..0563fee 100644 --- a/widgets/components/IndJurikVelocity/IndJurikVelocity.h +++ b/widgets/components/IndJurikVelocity/IndJurikVelocity.h @@ -197,6 +197,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_jurik_velocity(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("JurikVelocity"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndJurikVelocity(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -213,13 +230,29 @@ public: name_ = "IndJurikVelocity"; text_ = "JurikVelocity"; series_ = series; - std::vector result = xframe::ind_jurik_velocity(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("JurikVelocity"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndJurikVelocity() {} diff --git a/widgets/components/IndKAMA/IndKAMA.h b/widgets/components/IndKAMA/IndKAMA.h index 335f487..6f560b8 100644 --- a/widgets/components/IndKAMA/IndKAMA.h +++ b/widgets/components/IndKAMA/IndKAMA.h @@ -234,6 +234,19 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_kama(series_closes(series_), period_, fast_, slow_)); + line_names_.push_back("KAMA(10,2,30)"); + line_colors_.push_back(Srgb{150, 90, 30}); + } + public: IndKAMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10, int fast = 2, int slow = 30) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), @@ -241,12 +254,25 @@ public: period_ = period; fast_ = fast; slow_ = slow; - - lines_.push_back(ind_kama(series_closes(series), period_, fast_, slow_)); - line_names_.push_back("KAMA(10,2,30)"); - line_colors_.push_back(Srgb{150, 90, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndKAMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndKDJ/IndKDJ.h b/widgets/components/IndKDJ/IndKDJ.h index 510c209..d34d2b5 100644 --- a/widgets/components/IndKDJ/IndKDJ.h +++ b/widgets/components/IndKDJ/IndKDJ.h @@ -212,6 +212,30 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 9; + int smooth_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + xframe::IndKDJResult result = xframe::ind_kdj(series_, period_, smooth_); + lines_.push_back(result.k); + line_names_.push_back("k"); + line_colors_.push_back(Srgb{0, 100, 200}); + lines_.push_back(result.d); + line_names_.push_back("d"); + line_colors_.push_back(Srgb{200, 30, 30}); + lines_.push_back(result.j); + line_names_.push_back("j"); + line_colors_.push_back(Srgb{0, 150, 0}); + + } + public: IndKDJ(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 9, int smooth = 3) @@ -228,19 +252,30 @@ public: name_ = "IndKDJ"; text_ = "KDJ"; series_ = series; - xframe::IndKDJResult result = xframe::ind_kdj(series, period, smooth); - lines_.push_back(result.k); - line_names_.push_back("k"); - line_colors_.push_back(Srgb{0, 100, 200}); - lines_.push_back(result.d); - line_names_.push_back("d"); - line_colors_.push_back(Srgb{200, 30, 30}); - lines_.push_back(result.j); - line_names_.push_back("j"); - line_colors_.push_back(Srgb{0, 150, 0}); - view_count_ = (double)item_count(); + period_ = period; + smooth_ = smooth; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndKDJ() {} diff --git a/widgets/components/IndKST/IndKST.h b/widgets/components/IndKST/IndKST.h index 400c51e..7fbc7b6 100644 --- a/widgets/components/IndKST/IndKST.h +++ b/widgets/components/IndKST/IndKST.h @@ -206,6 +206,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_kst(xframe::series_closes(series_), dummy_); + lines_.push_back(result); + line_names_.push_back("KST"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndKST(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -222,13 +239,29 @@ public: name_ = "IndKST"; text_ = "KST"; series_ = series; - std::vector result = xframe::ind_kst(xframe::series_closes(series), dummy); - lines_.push_back(result); - line_names_.push_back("KST"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndKST() {} diff --git a/widgets/components/IndKairi/IndKairi.h b/widgets/components/IndKairi/IndKairi.h index 1d98552..7d50fef 100644 --- a/widgets/components/IndKairi/IndKairi.h +++ b/widgets/components/IndKairi/IndKairi.h @@ -198,6 +198,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 25; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_kairi(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("Kairi"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndKairi(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 25) @@ -214,13 +231,29 @@ public: name_ = "IndKairi"; text_ = "Kairi"; series_ = series; - std::vector result = xframe::ind_kairi(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("Kairi"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndKairi() {} diff --git a/widgets/components/IndKeltnerBandwidth/IndKeltnerBandwidth.h b/widgets/components/IndKeltnerBandwidth/IndKeltnerBandwidth.h index 47736c8..80d6410 100644 --- a/widgets/components/IndKeltnerBandwidth/IndKeltnerBandwidth.h +++ b/widgets/components/IndKeltnerBandwidth/IndKeltnerBandwidth.h @@ -149,6 +149,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_keltner_bandwidth(series_, period_, mult_); + lines_.push_back(Line{"KeltnerBW", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndKeltnerBandwidth(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -157,9 +166,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_keltner_bandwidth(series, period, mult); - lines_.push_back(Line{"KeltnerBW", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndKeltnerBandwidth() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndKeltnerChannels/IndKeltnerChannels.h b/widgets/components/IndKeltnerChannels/IndKeltnerChannels.h index 1eff4ac..b3ec714 100644 --- a/widgets/components/IndKeltnerChannels/IndKeltnerChannels.h +++ b/widgets/components/IndKeltnerChannels/IndKeltnerChannels.h @@ -155,6 +155,17 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_keltner_channels(series_, period_, mult_); + lines_.push_back(Line{"Upper", Srgb{200, 30, 30}, result.upper}); + lines_.push_back(Line{"Middle", Srgb{0, 100, 200}, result.middle}); + lines_.push_back(Line{"Lower", Srgb{200, 30, 30}, result.lower}); + } + public: std::function on_view_change; IndKeltnerChannels(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -163,11 +174,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_keltner_channels(series, period, mult); - lines_.push_back(Line{"Upper", Srgb{200, 30, 30}, result.upper}); - lines_.push_back(Line{"Middle", Srgb{0, 100, 200}, result.middle}); - lines_.push_back(Line{"Lower", Srgb{200, 30, 30}, result.lower}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndKeltnerChannels() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndKijunSen/IndKijunSen.h b/widgets/components/IndKijunSen/IndKijunSen.h index 8f0d451..cbc8ee9 100644 --- a/widgets/components/IndKijunSen/IndKijunSen.h +++ b/widgets/components/IndKijunSen/IndKijunSen.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_kijun_sen(series_, period_)); + line_names_.push_back("KijunSen(26)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndKijunSen(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 26) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_kijun_sen(series, period_)); - line_names_.push_back("KijunSen(26)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndKijunSen() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndKlingerVolumeOscillator/IndKlingerVolumeOscillator.h b/widgets/components/IndKlingerVolumeOscillator/IndKlingerVolumeOscillator.h index fbab650..288f4db 100644 --- a/widgets/components/IndKlingerVolumeOscillator/IndKlingerVolumeOscillator.h +++ b/widgets/components/IndKlingerVolumeOscillator/IndKlingerVolumeOscillator.h @@ -165,6 +165,16 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_klinger_volume_oscillator(series_, period_); + lines_.push_back(Line{"KVO", Srgb{0, 100, 200}, result.kvo}); + lines_.push_back(Line{"Signal", Srgb{200, 120, 0}, result.signal}); + } + public: std::function on_view_change; IndKlingerVolumeOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -173,10 +183,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_klinger_volume_oscillator(series, period); - lines_.push_back(Line{"KVO", Srgb{0, 100, 200}, result.kvo}); - lines_.push_back(Line{"Signal", Srgb{200, 120, 0}, result.signal}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndKlingerVolumeOscillator() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndKurtosis/IndKurtosis.h b/widgets/components/IndKurtosis/IndKurtosis.h index 71bed73..ee081e1 100644 --- a/widgets/components/IndKurtosis/IndKurtosis.h +++ b/widgets/components/IndKurtosis/IndKurtosis.h @@ -152,6 +152,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_kurtosis(series_, period_); + lines_.push_back(Line{"Kurtosis", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndKurtosis(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -160,9 +169,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_kurtosis(series, period); - lines_.push_back(Line{"Kurtosis", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndKurtosis() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndLSMA/IndLSMA.h b/widgets/components/IndLSMA/IndLSMA.h index 168d58d..6a360a5 100644 --- a/widgets/components/IndLSMA/IndLSMA.h +++ b/widgets/components/IndLSMA/IndLSMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_lsma(series_closes(series_), period_)); + line_names_.push_back("LSMA(14)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndLSMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_lsma(series_closes(series), period_)); - line_names_.push_back("LSMA(14)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndLSMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndLaguerreFilter/IndLaguerreFilter.h b/widgets/components/IndLaguerreFilter/IndLaguerreFilter.h index aab0adb..d081004 100644 --- a/widgets/components/IndLaguerreFilter/IndLaguerreFilter.h +++ b/widgets/components/IndLaguerreFilter/IndLaguerreFilter.h @@ -208,6 +208,23 @@ private: int grid_divisions_ = 4; Srgb overlay_candle_color_ = Srgb{180, 180, 180}; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + double gamma_ = 0.8; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_laguerre_filter(xframe::series_closes(series_), gamma_); + lines_.push_back(result); + line_names_.push_back("LaguerreFilter"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndLaguerreFilter(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), double gamma = 0.8) @@ -224,13 +241,29 @@ public: name_ = "IndLaguerreFilter"; text_ = "LaguerreFilter"; series_ = series; - std::vector result = xframe::ind_laguerre_filter(xframe::series_closes(series), gamma); - lines_.push_back(result); - line_names_.push_back("LaguerreFilter"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + gamma_ = gamma; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndLaguerreFilter() {} diff --git a/widgets/components/IndLaguerreRSI/IndLaguerreRSI.h b/widgets/components/IndLaguerreRSI/IndLaguerreRSI.h index 8f9e038..408c7ea 100644 --- a/widgets/components/IndLaguerreRSI/IndLaguerreRSI.h +++ b/widgets/components/IndLaguerreRSI/IndLaguerreRSI.h @@ -212,6 +212,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + double gamma_ = 0.8; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_laguerre_rsi(xframe::series_closes(series_), gamma_); + lines_.push_back(result); + line_names_.push_back("LaguerreRSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndLaguerreRSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), double gamma = 0.8) @@ -228,13 +245,29 @@ public: name_ = "IndLaguerreRSI"; text_ = "LaguerreRSI"; series_ = series; - std::vector result = xframe::ind_laguerre_rsi(xframe::series_closes(series), gamma); - lines_.push_back(result); - line_names_.push_back("LaguerreRSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + gamma_ = gamma; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndLaguerreRSI() {} diff --git a/widgets/components/IndLinReg/IndLinReg.h b/widgets/components/IndLinReg/IndLinReg.h index 5aaba04..34da1e2 100644 --- a/widgets/components/IndLinReg/IndLinReg.h +++ b/widgets/components/IndLinReg/IndLinReg.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_linreg(series_closes(series_), period_)); + line_names_.push_back("LinReg(14)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndLinReg(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_linreg(series_closes(series), period_)); - line_names_.push_back("LinReg(14)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndLinReg() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndLinRegAngle/IndLinRegAngle.h b/widgets/components/IndLinRegAngle/IndLinRegAngle.h index 2262de4..c334655 100644 --- a/widgets/components/IndLinRegAngle/IndLinRegAngle.h +++ b/widgets/components/IndLinRegAngle/IndLinRegAngle.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_linreg_angle(series_closes(series_), period_)); + line_names_.push_back("LinRegAngle(14)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndLinRegAngle(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_linreg_angle(series_closes(series), period_)); - line_names_.push_back("LinRegAngle(14)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndLinRegAngle() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndLinRegIntercept/IndLinRegIntercept.h b/widgets/components/IndLinRegIntercept/IndLinRegIntercept.h index cd5c2fe..6842ef7 100644 --- a/widgets/components/IndLinRegIntercept/IndLinRegIntercept.h +++ b/widgets/components/IndLinRegIntercept/IndLinRegIntercept.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_linreg_intercept(series_closes(series_), period_)); + line_names_.push_back("LinRegIntercept(14)"); + line_colors_.push_back(Srgb{0, 150, 150}); + } + public: IndLinRegIntercept(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_linreg_intercept(series_closes(series), period_)); - line_names_.push_back("LinRegIntercept(14)"); - line_colors_.push_back(Srgb{0, 150, 150}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndLinRegIntercept() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndLinRegSlope/IndLinRegSlope.h b/widgets/components/IndLinRegSlope/IndLinRegSlope.h index 86056b7..62d4e94 100644 --- a/widgets/components/IndLinRegSlope/IndLinRegSlope.h +++ b/widgets/components/IndLinRegSlope/IndLinRegSlope.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_linreg_slope(series_closes(series_), period_)); + line_names_.push_back("LinRegSlope(14)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndLinRegSlope(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_linreg_slope(series_closes(series), period_)); - line_names_.push_back("LinRegSlope(14)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndLinRegSlope() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndLinearRegressionForecast/IndLinearRegressionForecast.h b/widgets/components/IndLinearRegressionForecast/IndLinearRegressionForecast.h index 4a785cf..25de196 100644 --- a/widgets/components/IndLinearRegressionForecast/IndLinearRegressionForecast.h +++ b/widgets/components/IndLinearRegressionForecast/IndLinearRegressionForecast.h @@ -157,6 +157,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_linear_regression_forecast(series_, period_); + lines_.push_back(Line{"LRForecast", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndLinearRegressionForecast(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -165,9 +174,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_linear_regression_forecast(series, period); - lines_.push_back(Line{"LRForecast", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndLinearRegressionForecast() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndLinearRegressionIntercept/IndLinearRegressionIntercept.h b/widgets/components/IndLinearRegressionIntercept/IndLinearRegressionIntercept.h index 54fc6fe..10d0411 100644 --- a/widgets/components/IndLinearRegressionIntercept/IndLinearRegressionIntercept.h +++ b/widgets/components/IndLinearRegressionIntercept/IndLinearRegressionIntercept.h @@ -154,6 +154,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_linear_regression_intercept(series_, period_); + lines_.push_back(Line{"LRIntercept", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndLinearRegressionIntercept(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -162,9 +171,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_linear_regression_intercept(series, period); - lines_.push_back(Line{"LRIntercept", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndLinearRegressionIntercept() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndLinearRegressionOscillator/IndLinearRegressionOscillator.h b/widgets/components/IndLinearRegressionOscillator/IndLinearRegressionOscillator.h index 7807eaf..530ae9a 100644 --- a/widgets/components/IndLinearRegressionOscillator/IndLinearRegressionOscillator.h +++ b/widgets/components/IndLinearRegressionOscillator/IndLinearRegressionOscillator.h @@ -198,6 +198,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_linear_regression_oscillator(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("LinearRegressionOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndLinearRegressionOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -214,13 +231,29 @@ public: name_ = "IndLinearRegressionOscillator"; text_ = "LinearRegressionOscillator"; series_ = series; - std::vector result = xframe::ind_linear_regression_oscillator(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("LinearRegressionOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndLinearRegressionOscillator() {} diff --git a/widgets/components/IndLinearRegressionSlope/IndLinearRegressionSlope.h b/widgets/components/IndLinearRegressionSlope/IndLinearRegressionSlope.h index 7d38b2e..4013fcc 100644 --- a/widgets/components/IndLinearRegressionSlope/IndLinearRegressionSlope.h +++ b/widgets/components/IndLinearRegressionSlope/IndLinearRegressionSlope.h @@ -154,6 +154,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_linear_regression_slope(series_, period_); + lines_.push_back(Line{"LRSlope", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndLinearRegressionSlope(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -162,9 +171,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_linear_regression_slope(series, period); - lines_.push_back(Line{"LRSlope", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndLinearRegressionSlope() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndMACD/IndMACD.h b/widgets/components/IndMACD/IndMACD.h index ae16cb9..e7d2745 100644 --- a/widgets/components/IndMACD/IndMACD.h +++ b/widgets/components/IndMACD/IndMACD.h @@ -205,6 +205,31 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int fast_ = 12; + int slow_ = 26; + int signal_ = 9; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + xframe::IndMACDResult result = xframe::ind_macd(xframe::series_closes(series_), fast_, slow_, signal_); + lines_.push_back(result.macd); + line_names_.push_back("macd"); + line_colors_.push_back(Srgb{0, 100, 200}); + lines_.push_back(result.signal); + line_names_.push_back("signal"); + line_colors_.push_back(Srgb{200, 30, 30}); + lines_.push_back(result.histogram); + line_names_.push_back("histogram"); + line_colors_.push_back(Srgb{0, 150, 0}); + + } + public: IndMACD(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int fast = 12, int slow = 26, int signal = 9) @@ -221,19 +246,31 @@ public: name_ = "IndMACD"; text_ = "MACD"; series_ = series; - xframe::IndMACDResult result = xframe::ind_macd(xframe::series_closes(series), fast, slow, signal); - lines_.push_back(result.macd); - line_names_.push_back("macd"); - line_colors_.push_back(Srgb{0, 100, 200}); - lines_.push_back(result.signal); - line_names_.push_back("signal"); - line_colors_.push_back(Srgb{200, 30, 30}); - lines_.push_back(result.histogram); - line_names_.push_back("histogram"); - line_colors_.push_back(Srgb{0, 150, 0}); - view_count_ = (double)item_count(); + fast_ = fast; + slow_ = slow; + signal_ = signal; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndMACD() {} diff --git a/widgets/components/IndMACDHistogram/IndMACDHistogram.h b/widgets/components/IndMACDHistogram/IndMACDHistogram.h index fa7def1..ca2248a 100644 --- a/widgets/components/IndMACDHistogram/IndMACDHistogram.h +++ b/widgets/components/IndMACDHistogram/IndMACDHistogram.h @@ -201,6 +201,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int fast_ = 12; + int slow_ = 26; + int signal_ = 9; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_macd_histogram(xframe::series_closes(series_), fast_, slow_, signal_); + lines_.push_back(result); + line_names_.push_back("MACDHistogram"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndMACDHistogram(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int fast = 12, int slow = 26, int signal = 9) @@ -217,13 +236,31 @@ public: name_ = "IndMACDHistogram"; text_ = "MACDHistogram"; series_ = series; - std::vector result = xframe::ind_macd_histogram(xframe::series_closes(series), fast, slow, signal); - lines_.push_back(result); - line_names_.push_back("MACDHistogram"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + fast_ = fast; + slow_ = slow; + signal_ = signal; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndMACDHistogram() {} diff --git a/widgets/components/IndMACDofRSI/IndMACDofRSI.h b/widgets/components/IndMACDofRSI/IndMACDofRSI.h index f314a7e..1437e62 100644 --- a/widgets/components/IndMACDofRSI/IndMACDofRSI.h +++ b/widgets/components/IndMACDofRSI/IndMACDofRSI.h @@ -199,6 +199,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int rsi_period_ = 14; + int fast_ = 12; + int slow_ = 26; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_macd_of_rsi(xframe::series_closes(series_), rsi_period_, fast_, slow_); + lines_.push_back(result); + line_names_.push_back("MACDofRSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndMACDofRSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int rsi_period = 14, int fast = 12, int slow = 26) @@ -215,13 +234,31 @@ public: name_ = "IndMACDofRSI"; text_ = "MACDofRSI"; series_ = series; - std::vector result = xframe::ind_macd_of_rsi(xframe::series_closes(series), rsi_period, fast, slow); - lines_.push_back(result); - line_names_.push_back("MACDofRSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + rsi_period_ = rsi_period; + fast_ = fast; + slow_ = slow; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndMACDofRSI() {} diff --git a/widgets/components/IndMAEnvelopeLower/IndMAEnvelopeLower.h b/widgets/components/IndMAEnvelopeLower/IndMAEnvelopeLower.h index 8db3a8c..b05e3bb 100644 --- a/widgets/components/IndMAEnvelopeLower/IndMAEnvelopeLower.h +++ b/widgets/components/IndMAEnvelopeLower/IndMAEnvelopeLower.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_ma_envelope_lower(series_closes(series_), period_, pct_)); + line_names_.push_back("MAEnvLower(20,2.5)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndMAEnvelopeLower(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20, double pct = 2.5) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; pct_ = pct; - - lines_.push_back(ind_ma_envelope_lower(series_closes(series), period_, pct_)); - line_names_.push_back("MAEnvLower(20,2.5)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndMAEnvelopeLower() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndMAEnvelopeUpper/IndMAEnvelopeUpper.h b/widgets/components/IndMAEnvelopeUpper/IndMAEnvelopeUpper.h index c5e1163..4fade9a 100644 --- a/widgets/components/IndMAEnvelopeUpper/IndMAEnvelopeUpper.h +++ b/widgets/components/IndMAEnvelopeUpper/IndMAEnvelopeUpper.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_ma_envelope_upper(series_closes(series_), period_, pct_)); + line_names_.push_back("MAEnvUpper(20,2.5)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndMAEnvelopeUpper(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20, double pct = 2.5) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; pct_ = pct; - - lines_.push_back(ind_ma_envelope_upper(series_closes(series), period_, pct_)); - line_names_.push_back("MAEnvUpper(20,2.5)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndMAEnvelopeUpper() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndMAMA/IndMAMA.h b/widgets/components/IndMAMA/IndMAMA.h index ae45a3f..fcd8105 100644 --- a/widgets/components/IndMAMA/IndMAMA.h +++ b/widgets/components/IndMAMA/IndMAMA.h @@ -246,18 +246,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_mama(series_closes(series_), fastlimit_, slowlimit_)); + line_names_.push_back("MAMA(0.5,0.05)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndMAMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), double fastlimit = 0.5, double slowlimit = 0.05) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { fastlimit_ = fastlimit; slowlimit_ = slowlimit; - - lines_.push_back(ind_mama(series_closes(series), fastlimit_, slowlimit_)); - line_names_.push_back("MAMA(0.5,0.05)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndMAMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndMassIndex/IndMassIndex.h b/widgets/components/IndMassIndex/IndMassIndex.h index 156b936..a94f536 100644 --- a/widgets/components/IndMassIndex/IndMassIndex.h +++ b/widgets/components/IndMassIndex/IndMassIndex.h @@ -156,6 +156,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_mass_index(series_, period_); + lines_.push_back(Line{"MassIndex", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndMassIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,9 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_mass_index(series, period); - lines_.push_back(Line{"MassIndex", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndMassIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndMcGinley/IndMcGinley.h b/widgets/components/IndMcGinley/IndMcGinley.h index aa9525d..7c8ee4f 100644 --- a/widgets/components/IndMcGinley/IndMcGinley.h +++ b/widgets/components/IndMcGinley/IndMcGinley.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_mcginley(series_closes(series_), period_)); + line_names_.push_back("McGinley(14)"); + line_colors_.push_back(Srgb{0, 150, 150}); + } + public: IndMcGinley(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_mcginley(series_closes(series), period_)); - line_names_.push_back("McGinley(14)"); - line_colors_.push_back(Srgb{0, 150, 150}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndMcGinley() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndMedianMA/IndMedianMA.h b/widgets/components/IndMedianMA/IndMedianMA.h index 503d033..92f8ef2 100644 --- a/widgets/components/IndMedianMA/IndMedianMA.h +++ b/widgets/components/IndMedianMA/IndMedianMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_median_ma(series_closes(series_), period_)); + line_names_.push_back("MedianMA(14)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndMedianMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_median_ma(series_closes(series), period_)); - line_names_.push_back("MedianMA(14)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndMedianMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndMedianPrice/IndMedianPrice.h b/widgets/components/IndMedianPrice/IndMedianPrice.h index c2014ce..d721afe 100644 --- a/widgets/components/IndMedianPrice/IndMedianPrice.h +++ b/widgets/components/IndMedianPrice/IndMedianPrice.h @@ -151,6 +151,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_median_price(series_, period_); + lines_.push_back(Line{"Median", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndMedianPrice(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -159,9 +168,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_median_price(series, period); - lines_.push_back(Line{"Median", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndMedianPrice() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndMinusDI/IndMinusDI.h b/widgets/components/IndMinusDI/IndMinusDI.h index efee59b..1838d2e 100644 --- a/widgets/components/IndMinusDI/IndMinusDI.h +++ b/widgets/components/IndMinusDI/IndMinusDI.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_minus_di(series_, period_)); + line_names_.push_back("-DI(14)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndMinusDI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_minus_di(series, period_)); - line_names_.push_back("-DI(14)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndMinusDI() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndMomentum/IndMomentum.h b/widgets/components/IndMomentum/IndMomentum.h index 704782a..75a96e8 100644 --- a/widgets/components/IndMomentum/IndMomentum.h +++ b/widgets/components/IndMomentum/IndMomentum.h @@ -196,6 +196,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_momentum(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("Momentum"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndMomentum(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) @@ -212,13 +229,29 @@ public: name_ = "IndMomentum"; text_ = "Momentum"; series_ = series; - std::vector result = xframe::ind_momentum(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("Momentum"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndMomentum() {} diff --git a/widgets/components/IndMoneyFlowIndex/IndMoneyFlowIndex.h b/widgets/components/IndMoneyFlowIndex/IndMoneyFlowIndex.h index 90b240b..a502c5d 100644 --- a/widgets/components/IndMoneyFlowIndex/IndMoneyFlowIndex.h +++ b/widgets/components/IndMoneyFlowIndex/IndMoneyFlowIndex.h @@ -156,6 +156,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_money_flow_index(series_, period_); + lines_.push_back(Line{"MFI", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndMoneyFlowIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,9 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_money_flow_index(series, period); - lines_.push_back(Line{"MFI", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndMoneyFlowIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndMoneyFlowVolume/IndMoneyFlowVolume.h b/widgets/components/IndMoneyFlowVolume/IndMoneyFlowVolume.h index 38e3cc3..0478ff7 100644 --- a/widgets/components/IndMoneyFlowVolume/IndMoneyFlowVolume.h +++ b/widgets/components/IndMoneyFlowVolume/IndMoneyFlowVolume.h @@ -147,6 +147,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_money_flow_volume(series_, period_); + lines_.push_back(Line{"MFVolume", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndMoneyFlowVolume(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -155,9 +164,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_money_flow_volume(series, period); - lines_.push_back(Line{"MFVolume", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndMoneyFlowVolume() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndMovingAverageRibbon/IndMovingAverageRibbon.h b/widgets/components/IndMovingAverageRibbon/IndMovingAverageRibbon.h index 869ed26..9130302 100644 --- a/widgets/components/IndMovingAverageRibbon/IndMovingAverageRibbon.h +++ b/widgets/components/IndMovingAverageRibbon/IndMovingAverageRibbon.h @@ -232,14 +232,39 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + { auto rb = ind_ma_ribbon(series_closes(series_)); const int ps[6] = {5, 10, 20, 30, 50, 100}; const Srgb cols[6] = {Srgb{0, 100, 200}, Srgb{0, 150, 0}, Srgb{200, 30, 30}, Srgb{230, 126, 34}, Srgb{120, 60, 180}, Srgb{0, 150, 150}}; for (int k = 0; k < 6; ++k) { lines_.push_back(rb.lines[(size_t)k]); line_names_.push_back(std::string("SMA(") + std::to_string(ps[k]) + ")"); line_colors_.push_back(cols[k]); } } + } + public: IndMovingAverageRibbon(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250)) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { - - { auto rb = ind_ma_ribbon(series_closes(series)); const int ps[6] = {5, 10, 20, 30, 50, 100}; const Srgb cols[6] = {Srgb{0, 100, 200}, Srgb{0, 150, 0}, Srgb{200, 30, 30}, Srgb{230, 126, 34}, Srgb{120, 60, 180}, Srgb{0, 150, 150}}; for (int k = 0; k < 6; ++k) { lines_.push_back(rb.lines[(size_t)k]); line_names_.push_back(std::string("SMA(") + std::to_string(ps[k]) + ")"); line_colors_.push_back(cols[k]); } } - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndMovingAverageRibbon() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndNATR/IndNATR.h b/widgets/components/IndNATR/IndNATR.h index a6a427c..afc206b 100644 --- a/widgets/components/IndNATR/IndNATR.h +++ b/widgets/components/IndNATR/IndNATR.h @@ -147,6 +147,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_natr(series_, period_); + lines_.push_back(Line{"NATR", Srgb{200, 120, 0}, result}); + } + public: std::function on_view_change; IndNATR(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -155,9 +164,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_natr(series, period); - lines_.push_back(Line{"NATR", Srgb{200, 120, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndNATR() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndNegativeVolumeIndex/IndNegativeVolumeIndex.h b/widgets/components/IndNegativeVolumeIndex/IndNegativeVolumeIndex.h index 9c38f8f..b9f93fa 100644 --- a/widgets/components/IndNegativeVolumeIndex/IndNegativeVolumeIndex.h +++ b/widgets/components/IndNegativeVolumeIndex/IndNegativeVolumeIndex.h @@ -151,6 +151,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_negative_volume_index(series_, period_); + lines_.push_back(Line{"NVI", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndNegativeVolumeIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -159,9 +168,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_negative_volume_index(series, period); - lines_.push_back(Line{"NVI", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndNegativeVolumeIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndNormalizedROC/IndNormalizedROC.h b/widgets/components/IndNormalizedROC/IndNormalizedROC.h index 65eff6b..51a4162 100644 --- a/widgets/components/IndNormalizedROC/IndNormalizedROC.h +++ b/widgets/components/IndNormalizedROC/IndNormalizedROC.h @@ -201,6 +201,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 12; + int norm_ = 20; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_normalized_roc(xframe::series_closes(series_), period_, norm_); + lines_.push_back(result); + line_names_.push_back("NormalizedROC"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndNormalizedROC(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 12, int norm = 20) @@ -217,13 +235,30 @@ public: name_ = "IndNormalizedROC"; text_ = "NormalizedROC"; series_ = series; - std::vector result = xframe::ind_normalized_roc(xframe::series_closes(series), period, norm); - lines_.push_back(result); - line_names_.push_back("NormalizedROC"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + norm_ = norm; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndNormalizedROC() {} diff --git a/widgets/components/IndOBV/IndOBV.h b/widgets/components/IndOBV/IndOBV.h index 66fb3ce..33e27b9 100644 --- a/widgets/components/IndOBV/IndOBV.h +++ b/widgets/components/IndOBV/IndOBV.h @@ -153,6 +153,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_obv(series_, period_); + lines_.push_back(Line{"OBV", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndOBV(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -161,9 +170,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_obv(series, period); - lines_.push_back(Line{"OBV", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndOBV() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndPPO/IndPPO.h b/widgets/components/IndPPO/IndPPO.h index d998d7e..a13a0d9 100644 --- a/widgets/components/IndPPO/IndPPO.h +++ b/widgets/components/IndPPO/IndPPO.h @@ -198,6 +198,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int fast_ = 12; + int slow_ = 26; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_ppo(xframe::series_closes(series_), fast_, slow_); + lines_.push_back(result); + line_names_.push_back("PPO"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndPPO(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int fast = 12, int slow = 26) @@ -214,13 +232,30 @@ public: name_ = "IndPPO"; text_ = "PPO"; series_ = series; - std::vector result = xframe::ind_ppo(xframe::series_closes(series), fast, slow); - lines_.push_back(result); - line_names_.push_back("PPO"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + fast_ = fast; + slow_ = slow; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndPPO() {} diff --git a/widgets/components/IndPSAR/IndPSAR.h b/widgets/components/IndPSAR/IndPSAR.h index 171e64e..a05c60f 100644 --- a/widgets/components/IndPSAR/IndPSAR.h +++ b/widgets/components/IndPSAR/IndPSAR.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_psar(series_, step_, maxaf_)); + line_names_.push_back("PSAR(0.02,0.2)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndPSAR(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), double step = 0.02, double maxaf = 0.2) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { step_ = step; maxaf_ = maxaf; - - lines_.push_back(ind_psar(series, step_, maxaf_)); - line_names_.push_back("PSAR(0.02,0.2)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndPSAR() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndParkinsonVolatility/IndParkinsonVolatility.h b/widgets/components/IndParkinsonVolatility/IndParkinsonVolatility.h index a5395eb..d188114 100644 --- a/widgets/components/IndParkinsonVolatility/IndParkinsonVolatility.h +++ b/widgets/components/IndParkinsonVolatility/IndParkinsonVolatility.h @@ -155,6 +155,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_parkinson_volatility(series_, period_); + lines_.push_back(Line{"Parkinson", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndParkinsonVolatility(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -163,9 +172,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_parkinson_volatility(series, period); - lines_.push_back(Line{"Parkinson", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndParkinsonVolatility() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndPercentRank/IndPercentRank.h b/widgets/components/IndPercentRank/IndPercentRank.h index 01aca53..c32cf1a 100644 --- a/widgets/components/IndPercentRank/IndPercentRank.h +++ b/widgets/components/IndPercentRank/IndPercentRank.h @@ -200,6 +200,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_percent_rank(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("PercentRank"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndPercentRank(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -216,13 +233,29 @@ public: name_ = "IndPercentRank"; text_ = "PercentRank"; series_ = series; - std::vector result = xframe::ind_percent_rank(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("PercentRank"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndPercentRank() {} diff --git a/widgets/components/IndPercentageVolumeOscillator/IndPercentageVolumeOscillator.h b/widgets/components/IndPercentageVolumeOscillator/IndPercentageVolumeOscillator.h index 34ee244..fda8544 100644 --- a/widgets/components/IndPercentageVolumeOscillator/IndPercentageVolumeOscillator.h +++ b/widgets/components/IndPercentageVolumeOscillator/IndPercentageVolumeOscillator.h @@ -149,6 +149,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_percentage_volume_oscillator(series_, period_); + lines_.push_back(Line{"PVO", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndPercentageVolumeOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -157,9 +166,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_percentage_volume_oscillator(series, period); - lines_.push_back(Line{"PVO", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndPercentageVolumeOscillator() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndPercentileRank/IndPercentileRank.h b/widgets/components/IndPercentileRank/IndPercentileRank.h index c9ef293..0f31596 100644 --- a/widgets/components/IndPercentileRank/IndPercentileRank.h +++ b/widgets/components/IndPercentileRank/IndPercentileRank.h @@ -151,6 +151,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_percentile_rank(series_, period_); + lines_.push_back(Line{"PctRank", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndPercentileRank(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -159,9 +168,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_percentile_rank(series, period); - lines_.push_back(Line{"PctRank", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndPercentileRank() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndPivotPoint/IndPivotPoint.h b/widgets/components/IndPivotPoint/IndPivotPoint.h index 6484f2e..f9b72bc 100644 --- a/widgets/components/IndPivotPoint/IndPivotPoint.h +++ b/widgets/components/IndPivotPoint/IndPivotPoint.h @@ -231,16 +231,41 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + lines_.push_back(ind_pivot_point(series_)); + line_names_.push_back("PivotPoint"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndPivotPoint(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250)) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { - - lines_.push_back(ind_pivot_point(series)); - line_names_.push_back("PivotPoint"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndPivotPoint() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndPlusDI/IndPlusDI.h b/widgets/components/IndPlusDI/IndPlusDI.h index 207f012..d5f7b29 100644 --- a/widgets/components/IndPlusDI/IndPlusDI.h +++ b/widgets/components/IndPlusDI/IndPlusDI.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_plus_di(series_, period_)); + line_names_.push_back("+DI(14)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndPlusDI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_plus_di(series, period_)); - line_names_.push_back("+DI(14)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndPlusDI() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndPositiveVolumeIndex/IndPositiveVolumeIndex.h b/widgets/components/IndPositiveVolumeIndex/IndPositiveVolumeIndex.h index 6ff2b23..c15aaba 100644 --- a/widgets/components/IndPositiveVolumeIndex/IndPositiveVolumeIndex.h +++ b/widgets/components/IndPositiveVolumeIndex/IndPositiveVolumeIndex.h @@ -151,6 +151,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_positive_volume_index(series_, period_); + lines_.push_back(Line{"PVI", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndPositiveVolumeIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -159,9 +168,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_positive_volume_index(series, period); - lines_.push_back(Line{"PVI", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndPositiveVolumeIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndPrettyGoodOscillator/IndPrettyGoodOscillator.h b/widgets/components/IndPrettyGoodOscillator/IndPrettyGoodOscillator.h index 0fd319e..95cb5ff 100644 --- a/widgets/components/IndPrettyGoodOscillator/IndPrettyGoodOscillator.h +++ b/widgets/components/IndPrettyGoodOscillator/IndPrettyGoodOscillator.h @@ -201,6 +201,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_pretty_good_oscillator(series_, period_); + lines_.push_back(result); + line_names_.push_back("PrettyGoodOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndPrettyGoodOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -217,13 +234,29 @@ public: name_ = "IndPrettyGoodOscillator"; text_ = "PrettyGoodOscillator"; series_ = series; - std::vector result = xframe::ind_pretty_good_oscillator(series, period); - lines_.push_back(result); - line_names_.push_back("PrettyGoodOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndPrettyGoodOscillator() {} diff --git a/widgets/components/IndPriceMomentumOscillator/IndPriceMomentumOscillator.h b/widgets/components/IndPriceMomentumOscillator/IndPriceMomentumOscillator.h index ae44764..96c8f04 100644 --- a/widgets/components/IndPriceMomentumOscillator/IndPriceMomentumOscillator.h +++ b/widgets/components/IndPriceMomentumOscillator/IndPriceMomentumOscillator.h @@ -201,6 +201,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int slow_ = 35; + int fast_ = 20; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_price_momentum_oscillator(xframe::series_closes(series_), slow_, fast_); + lines_.push_back(result); + line_names_.push_back("PriceMomentumOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndPriceMomentumOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int slow = 35, int fast = 20) @@ -217,13 +235,30 @@ public: name_ = "IndPriceMomentumOscillator"; text_ = "PriceMomentumOscillator"; series_ = series; - std::vector result = xframe::ind_price_momentum_oscillator(xframe::series_closes(series), slow, fast); - lines_.push_back(result); - line_names_.push_back("PriceMomentumOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + slow_ = slow; + fast_ = fast; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndPriceMomentumOscillator() {} diff --git a/widgets/components/IndQStick/IndQStick.h b/widgets/components/IndQStick/IndQStick.h index 5171a86..28e4590 100644 --- a/widgets/components/IndQStick/IndQStick.h +++ b/widgets/components/IndQStick/IndQStick.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_qstick(series_, period_)); + line_names_.push_back("QStick(14)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndQStick(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_qstick(series, period_)); - line_names_.push_back("QStick(14)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndQStick() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndRMA/IndRMA.h b/widgets/components/IndRMA/IndRMA.h index 4e86c81..b6203da 100644 --- a/widgets/components/IndRMA/IndRMA.h +++ b/widgets/components/IndRMA/IndRMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_rma(series_closes(series_), period_)); + line_names_.push_back("RMA(14)"); + line_colors_.push_back(Srgb{150, 90, 30}); + } + public: IndRMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_rma(series_closes(series), period_)); - line_names_.push_back("RMA(14)"); - line_colors_.push_back(Srgb{150, 90, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndRMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndROC/IndROC.h b/widgets/components/IndROC/IndROC.h index c8d559a..377098a 100644 --- a/widgets/components/IndROC/IndROC.h +++ b/widgets/components/IndROC/IndROC.h @@ -197,6 +197,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 12; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_roc(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("ROC"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndROC(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 12) @@ -213,13 +230,29 @@ public: name_ = "IndROC"; text_ = "ROC"; series_ = series; - std::vector result = xframe::ind_roc(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("ROC"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndROC() {} diff --git a/widgets/components/IndROCR/IndROCR.h b/widgets/components/IndROCR/IndROCR.h index 4027c9f..fd2953a 100644 --- a/widgets/components/IndROCR/IndROCR.h +++ b/widgets/components/IndROCR/IndROCR.h @@ -197,6 +197,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 12; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_rocr(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("ROCR"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndROCR(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 12) @@ -213,13 +230,29 @@ public: name_ = "IndROCR"; text_ = "ROCR"; series_ = series; - std::vector result = xframe::ind_rocr(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("ROCR"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndROCR() {} diff --git a/widgets/components/IndRSI/IndRSI.h b/widgets/components/IndRSI/IndRSI.h index e003cbf..e08add2 100644 --- a/widgets/components/IndRSI/IndRSI.h +++ b/widgets/components/IndRSI/IndRSI.h @@ -195,6 +195,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_rsi(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("RSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndRSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -211,13 +228,29 @@ public: name_ = "IndRSI"; text_ = "RSI"; series_ = series; - std::vector result = xframe::ind_rsi(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("RSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRSI() {} diff --git a/widgets/components/IndRSX/IndRSX.h b/widgets/components/IndRSX/IndRSX.h index 863c03c..0b45c2a 100644 --- a/widgets/components/IndRSX/IndRSX.h +++ b/widgets/components/IndRSX/IndRSX.h @@ -207,6 +207,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_rsx(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("RSX"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndRSX(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -223,13 +240,29 @@ public: name_ = "IndRSX"; text_ = "RSX"; series_ = series; - std::vector result = xframe::ind_rsx(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("RSX"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRSX() {} diff --git a/widgets/components/IndRSquared/IndRSquared.h b/widgets/components/IndRSquared/IndRSquared.h index c842e51..709677e 100644 --- a/widgets/components/IndRSquared/IndRSquared.h +++ b/widgets/components/IndRSquared/IndRSquared.h @@ -163,6 +163,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_r_squared(series_, period_); + lines_.push_back(Line{"RSquared", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndRSquared(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -171,9 +180,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_r_squared(series, period); - lines_.push_back(Line{"RSquared", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRSquared() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndRWIHigh/IndRWIHigh.h b/widgets/components/IndRWIHigh/IndRWIHigh.h index af60a4a..14be299 100644 --- a/widgets/components/IndRWIHigh/IndRWIHigh.h +++ b/widgets/components/IndRWIHigh/IndRWIHigh.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_rwi_high(series_, period_)); + line_names_.push_back("RWIHigh(14)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndRWIHigh(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_rwi_high(series, period_)); - line_names_.push_back("RWIHigh(14)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndRWIHigh() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndRWILow/IndRWILow.h b/widgets/components/IndRWILow/IndRWILow.h index 9ea943f..9437833 100644 --- a/widgets/components/IndRWILow/IndRWILow.h +++ b/widgets/components/IndRWILow/IndRWILow.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_rwi_low(series_, period_)); + line_names_.push_back("RWILow(14)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndRWILow(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_rwi_low(series, period_)); - line_names_.push_back("RWILow(14)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndRWILow() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndRainbowOscillator/IndRainbowOscillator.h b/widgets/components/IndRainbowOscillator/IndRainbowOscillator.h index 1eec2b0..690fc56 100644 --- a/widgets/components/IndRainbowOscillator/IndRainbowOscillator.h +++ b/widgets/components/IndRainbowOscillator/IndRainbowOscillator.h @@ -207,6 +207,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int max_period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_rainbow_oscillator(xframe::series_closes(series_), max_period_); + lines_.push_back(result); + line_names_.push_back("RainbowOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndRainbowOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int max_period = 10) @@ -223,13 +240,29 @@ public: name_ = "IndRainbowOscillator"; text_ = "RainbowOscillator"; series_ = series; - std::vector result = xframe::ind_rainbow_oscillator(xframe::series_closes(series), max_period); - lines_.push_back(result); - line_names_.push_back("RainbowOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + max_period_ = max_period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRainbowOscillator() {} diff --git a/widgets/components/IndRangeExpansionIndex/IndRangeExpansionIndex.h b/widgets/components/IndRangeExpansionIndex/IndRangeExpansionIndex.h index b00ecbe..5510805 100644 --- a/widgets/components/IndRangeExpansionIndex/IndRangeExpansionIndex.h +++ b/widgets/components/IndRangeExpansionIndex/IndRangeExpansionIndex.h @@ -208,6 +208,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 8; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_range_expansion_index(series_, period_); + lines_.push_back(result); + line_names_.push_back("RangeExpansionIndex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndRangeExpansionIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 8) @@ -224,13 +241,29 @@ public: name_ = "IndRangeExpansionIndex"; text_ = "RangeExpansionIndex"; series_ = series; - std::vector result = xframe::ind_range_expansion_index(series, period); - lines_.push_back(result); - line_names_.push_back("RangeExpansionIndex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRangeExpansionIndex() {} diff --git a/widgets/components/IndReflex/IndReflex.h b/widgets/components/IndReflex/IndReflex.h index 6324f46..4d13c20 100644 --- a/widgets/components/IndReflex/IndReflex.h +++ b/widgets/components/IndReflex/IndReflex.h @@ -204,6 +204,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_reflex(series_, period_); + lines_.push_back(result); + line_names_.push_back("Reflex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndReflex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) @@ -220,13 +237,29 @@ public: name_ = "IndReflex"; text_ = "Reflex"; series_ = series; - std::vector result = xframe::ind_reflex(series, period); - lines_.push_back(result); - line_names_.push_back("Reflex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndReflex() {} diff --git a/widgets/components/IndRegressionChannel/IndRegressionChannel.h b/widgets/components/IndRegressionChannel/IndRegressionChannel.h index 363d1f8..bcb6f23 100644 --- a/widgets/components/IndRegressionChannel/IndRegressionChannel.h +++ b/widgets/components/IndRegressionChannel/IndRegressionChannel.h @@ -234,16 +234,42 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + { auto rc = ind_regression_channel(series_closes(series_), period_, mult_); lines_.push_back(rc.upper); line_names_.push_back("RegChUpper"); line_colors_.push_back(Srgb{0, 150, 0}); lines_.push_back(rc.mid); line_names_.push_back("LinReg"); line_colors_.push_back(Srgb{0, 100, 200}); lines_.push_back(rc.lower); line_names_.push_back("RegChLower"); line_colors_.push_back(Srgb{200, 30, 30}); } + } + public: IndRegressionChannel(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20, double mult = 2.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; mult_ = mult; - - { auto rc = ind_regression_channel(series_closes(series), period_, mult_); lines_.push_back(rc.upper); line_names_.push_back("RegChUpper"); line_colors_.push_back(Srgb{0, 150, 0}); lines_.push_back(rc.mid); line_names_.push_back("LinReg"); line_colors_.push_back(Srgb{0, 100, 200}); lines_.push_back(rc.lower); line_names_.push_back("RegChLower"); line_colors_.push_back(Srgb{200, 30, 30}); } - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndRegressionChannel() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndRelativeMomentumIndex/IndRelativeMomentumIndex.h b/widgets/components/IndRelativeMomentumIndex/IndRelativeMomentumIndex.h index ab912fc..7f5240a 100644 --- a/widgets/components/IndRelativeMomentumIndex/IndRelativeMomentumIndex.h +++ b/widgets/components/IndRelativeMomentumIndex/IndRelativeMomentumIndex.h @@ -206,6 +206,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 20; + int momentum_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_relative_momentum_index(xframe::series_closes(series_), period_, momentum_); + lines_.push_back(result); + line_names_.push_back("RelativeMomentumIndex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndRelativeMomentumIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20, int momentum = 5) @@ -222,13 +240,30 @@ public: name_ = "IndRelativeMomentumIndex"; text_ = "RelativeMomentumIndex"; series_ = series; - std::vector result = xframe::ind_relative_momentum_index(xframe::series_closes(series), period, momentum); - lines_.push_back(result); - line_names_.push_back("RelativeMomentumIndex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + momentum_ = momentum; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRelativeMomentumIndex() {} diff --git a/widgets/components/IndRelativeVigorIndex/IndRelativeVigorIndex.h b/widgets/components/IndRelativeVigorIndex/IndRelativeVigorIndex.h index 4ac6195..39bb156 100644 --- a/widgets/components/IndRelativeVigorIndex/IndRelativeVigorIndex.h +++ b/widgets/components/IndRelativeVigorIndex/IndRelativeVigorIndex.h @@ -201,6 +201,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_relative_vigor_index(series_, period_); + lines_.push_back(result); + line_names_.push_back("RelativeVigorIndex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndRelativeVigorIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) @@ -217,13 +234,29 @@ public: name_ = "IndRelativeVigorIndex"; text_ = "RelativeVigorIndex"; series_ = series; - std::vector result = xframe::ind_relative_vigor_index(series, period); - lines_.push_back(result); - line_names_.push_back("RelativeVigorIndex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRelativeVigorIndex() {} diff --git a/widgets/components/IndRelativeVolatilityIndex/IndRelativeVolatilityIndex.h b/widgets/components/IndRelativeVolatilityIndex/IndRelativeVolatilityIndex.h index b564458..338fa05 100644 --- a/widgets/components/IndRelativeVolatilityIndex/IndRelativeVolatilityIndex.h +++ b/widgets/components/IndRelativeVolatilityIndex/IndRelativeVolatilityIndex.h @@ -153,6 +153,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_relative_volatility_index(series_, period_); + lines_.push_back(Line{"RVI", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndRelativeVolatilityIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -161,9 +170,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_relative_volatility_index(series, period); - lines_.push_back(Line{"RVI", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRelativeVolatilityIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndRelativeVolume/IndRelativeVolume.h b/widgets/components/IndRelativeVolume/IndRelativeVolume.h index 913a7a6..0f5dc88 100644 --- a/widgets/components/IndRelativeVolume/IndRelativeVolume.h +++ b/widgets/components/IndRelativeVolume/IndRelativeVolume.h @@ -148,6 +148,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_relative_volume(series_, period_); + lines_.push_back(Line{"RVOL", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndRelativeVolume(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -156,9 +165,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_relative_volume(series, period); - lines_.push_back(Line{"RVOL", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRelativeVolume() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndRogersSatchellVolatility/IndRogersSatchellVolatility.h b/widgets/components/IndRogersSatchellVolatility/IndRogersSatchellVolatility.h index 4f70aa7..7715ab7 100644 --- a/widgets/components/IndRogersSatchellVolatility/IndRogersSatchellVolatility.h +++ b/widgets/components/IndRogersSatchellVolatility/IndRogersSatchellVolatility.h @@ -156,6 +156,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_rogers_satchell_volatility(series_, period_); + lines_.push_back(Line{"RogersSatchell", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndRogersSatchellVolatility(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,9 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_rogers_satchell_volatility(series, period); - lines_.push_back(Line{"RogersSatchell", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRogersSatchellVolatility() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndRoofingFilter/IndRoofingFilter.h b/widgets/components/IndRoofingFilter/IndRoofingFilter.h index 0618f4b..132e0b7 100644 --- a/widgets/components/IndRoofingFilter/IndRoofingFilter.h +++ b/widgets/components/IndRoofingFilter/IndRoofingFilter.h @@ -198,6 +198,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + int hp_period_ = 48; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_roofing_filter(xframe::series_closes(series_), period_, hp_period_); + lines_.push_back(result); + line_names_.push_back("RoofingFilter"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndRoofingFilter(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10, int hp_period = 48) @@ -214,13 +232,30 @@ public: name_ = "IndRoofingFilter"; text_ = "RoofingFilter"; series_ = series; - std::vector result = xframe::ind_roofing_filter(xframe::series_closes(series), period, hp_period); - lines_.push_back(result); - line_names_.push_back("RoofingFilter"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + hp_period_ = hp_period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndRoofingFilter() {} diff --git a/widgets/components/IndSMA/IndSMA.h b/widgets/components/IndSMA/IndSMA.h index 1582f0e..427f317 100644 --- a/widgets/components/IndSMA/IndSMA.h +++ b/widgets/components/IndSMA/IndSMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_sma(series_closes(series_), period_)); + line_names_.push_back("SMA(14)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndSMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_sma(series_closes(series), period_)); - line_names_.push_back("SMA(14)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndSMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndSMI/IndSMI.h b/widgets/components/IndSMI/IndSMI.h index f0fe73b..f15d650 100644 --- a/widgets/components/IndSMI/IndSMI.h +++ b/widgets/components/IndSMI/IndSMI.h @@ -202,6 +202,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 13; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_smi(series_, period_); + lines_.push_back(result); + line_names_.push_back("SMI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndSMI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 13) @@ -218,13 +235,29 @@ public: name_ = "IndSMI"; text_ = "SMI"; series_ = series; - std::vector result = xframe::ind_smi(series, period); - lines_.push_back(result); - line_names_.push_back("SMI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSMI() {} diff --git a/widgets/components/IndSMMA/IndSMMA.h b/widgets/components/IndSMMA/IndSMMA.h index 932a9e3..881d6c2 100644 --- a/widgets/components/IndSMMA/IndSMMA.h +++ b/widgets/components/IndSMMA/IndSMMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_smma(series_closes(series_), period_)); + line_names_.push_back("SMMA(14)"); + line_colors_.push_back(Srgb{0, 150, 150}); + } + public: IndSMMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_smma(series_closes(series), period_)); - line_names_.push_back("SMMA(14)"); - line_colors_.push_back(Srgb{0, 150, 150}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndSMMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndSSLChannel/IndSSLChannel.h b/widgets/components/IndSSLChannel/IndSSLChannel.h index 4571781..021d9f1 100644 --- a/widgets/components/IndSSLChannel/IndSSLChannel.h +++ b/widgets/components/IndSSLChannel/IndSSLChannel.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_ssl_channel(series_, period_)); + line_names_.push_back("SSL(10)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndSSLChannel(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_ssl_channel(series, period_)); - line_names_.push_back("SSL(10)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndSSLChannel() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndSchaffTrendCycle/IndSchaffTrendCycle.h b/widgets/components/IndSchaffTrendCycle/IndSchaffTrendCycle.h index 87fd768..c5da2ef 100644 --- a/widgets/components/IndSchaffTrendCycle/IndSchaffTrendCycle.h +++ b/widgets/components/IndSchaffTrendCycle/IndSchaffTrendCycle.h @@ -204,6 +204,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int fast_ = 23; + int slow_ = 50; + int cycle_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_schaff_trend_cycle(xframe::series_closes(series_), fast_, slow_, cycle_); + lines_.push_back(result); + line_names_.push_back("SchaffTrendCycle"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndSchaffTrendCycle(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int fast = 23, int slow = 50, int cycle = 10) @@ -220,13 +239,31 @@ public: name_ = "IndSchaffTrendCycle"; text_ = "SchaffTrendCycle"; series_ = series; - std::vector result = xframe::ind_schaff_trend_cycle(xframe::series_closes(series), fast, slow, cycle); - lines_.push_back(result); - line_names_.push_back("SchaffTrendCycle"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + fast_ = fast; + slow_ = slow; + cycle_ = cycle; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSchaffTrendCycle() {} diff --git a/widgets/components/IndSenkouSpanA/IndSenkouSpanA.h b/widgets/components/IndSenkouSpanA/IndSenkouSpanA.h index 3d581ec..9aff784 100644 --- a/widgets/components/IndSenkouSpanA/IndSenkouSpanA.h +++ b/widgets/components/IndSenkouSpanA/IndSenkouSpanA.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_senkou_span_a(series_, tenkan_, kijun_)); + line_names_.push_back("SenkouSpanA(9,26)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndSenkouSpanA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int tenkan = 9, int kijun = 26) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { tenkan_ = tenkan; kijun_ = kijun; - - lines_.push_back(ind_senkou_span_a(series, tenkan_, kijun_)); - line_names_.push_back("SenkouSpanA(9,26)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndSenkouSpanA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndSenkouSpanB/IndSenkouSpanB.h b/widgets/components/IndSenkouSpanB/IndSenkouSpanB.h index 4dda317..38ff396 100644 --- a/widgets/components/IndSenkouSpanB/IndSenkouSpanB.h +++ b/widgets/components/IndSenkouSpanB/IndSenkouSpanB.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_senkou_span_b(series_, period_)); + line_names_.push_back("SenkouSpanB(52)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndSenkouSpanB(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 52) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_senkou_span_b(series, period_)); - line_names_.push_back("SenkouSpanB(52)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndSenkouSpanB() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndShannonEntropy/IndShannonEntropy.h b/widgets/components/IndShannonEntropy/IndShannonEntropy.h index 6446115..b813ac4 100644 --- a/widgets/components/IndShannonEntropy/IndShannonEntropy.h +++ b/widgets/components/IndShannonEntropy/IndShannonEntropy.h @@ -159,6 +159,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_shannon_entropy(series_, period_); + lines_.push_back(Line{"Entropy", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndShannonEntropy(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -167,9 +176,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_shannon_entropy(series, period); - lines_.push_back(Line{"Entropy", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndShannonEntropy() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndSineWMA/IndSineWMA.h b/widgets/components/IndSineWMA/IndSineWMA.h index 41fd2ba..ed7f581 100644 --- a/widgets/components/IndSineWMA/IndSineWMA.h +++ b/widgets/components/IndSineWMA/IndSineWMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_sine_wma(series_closes(series_), period_)); + line_names_.push_back("SineWMA(14)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndSineWMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_sine_wma(series_closes(series), period_)); - line_names_.push_back("SineWMA(14)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndSineWMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndSineWave/IndSineWave.h b/widgets/components/IndSineWave/IndSineWave.h index 80d20e4..58f26bb 100644 --- a/widgets/components/IndSineWave/IndSineWave.h +++ b/widgets/components/IndSineWave/IndSineWave.h @@ -216,6 +216,26 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + xframe::IndSineWaveResult result = xframe::ind_sine_wave(xframe::series_closes(series_), dummy_); + lines_.push_back(result.sine); + line_names_.push_back("sine"); + line_colors_.push_back(Srgb{0, 100, 200}); + lines_.push_back(result.lead_sine); + line_names_.push_back("lead_sine"); + line_colors_.push_back(Srgb{200, 30, 30}); + + } + public: IndSineWave(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -232,16 +252,29 @@ public: name_ = "IndSineWave"; text_ = "SineWave"; series_ = series; - xframe::IndSineWaveResult result = xframe::ind_sine_wave(xframe::series_closes(series), dummy); - lines_.push_back(result.sine); - line_names_.push_back("sine"); - line_colors_.push_back(Srgb{0, 100, 200}); - lines_.push_back(result.lead_sine); - line_names_.push_back("lead_sine"); - line_colors_.push_back(Srgb{200, 30, 30}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSineWave() {} diff --git a/widgets/components/IndSkewness/IndSkewness.h b/widgets/components/IndSkewness/IndSkewness.h index 980a9d2..cac2968 100644 --- a/widgets/components/IndSkewness/IndSkewness.h +++ b/widgets/components/IndSkewness/IndSkewness.h @@ -152,6 +152,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_skewness(series_, period_); + lines_.push_back(Line{"Skew", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndSkewness(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -160,9 +169,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_skewness(series, period); - lines_.push_back(Line{"Skew", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSkewness() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndSmoothedROC/IndSmoothedROC.h b/widgets/components/IndSmoothedROC/IndSmoothedROC.h index e398516..e16e85a 100644 --- a/widgets/components/IndSmoothedROC/IndSmoothedROC.h +++ b/widgets/components/IndSmoothedROC/IndSmoothedROC.h @@ -197,6 +197,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 12; + int smooth_ = 25; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_smoothed_roc(xframe::series_closes(series_), period_, smooth_); + lines_.push_back(result); + line_names_.push_back("SmoothedROC"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndSmoothedROC(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 12, int smooth = 25) @@ -213,13 +231,30 @@ public: name_ = "IndSmoothedROC"; text_ = "SmoothedROC"; series_ = series; - std::vector result = xframe::ind_smoothed_roc(xframe::series_closes(series), period, smooth); - lines_.push_back(result); - line_names_.push_back("SmoothedROC"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + smooth_ = smooth; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSmoothedROC() {} diff --git a/widgets/components/IndSpearmanRank/IndSpearmanRank.h b/widgets/components/IndSpearmanRank/IndSpearmanRank.h index 9c305ab..d4daac7 100644 --- a/widgets/components/IndSpearmanRank/IndSpearmanRank.h +++ b/widgets/components/IndSpearmanRank/IndSpearmanRank.h @@ -210,6 +210,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_spearman_rank(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("SpearmanRank"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndSpearmanRank(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -226,13 +243,29 @@ public: name_ = "IndSpearmanRank"; text_ = "SpearmanRank"; series_ = series; - std::vector result = xframe::ind_spearman_rank(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("SpearmanRank"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSpearmanRank() {} diff --git a/widgets/components/IndSpecialK/IndSpecialK.h b/widgets/components/IndSpecialK/IndSpecialK.h index a2eee70..7b2d73f 100644 --- a/widgets/components/IndSpecialK/IndSpecialK.h +++ b/widgets/components/IndSpecialK/IndSpecialK.h @@ -206,6 +206,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_special_k(xframe::series_closes(series_), dummy_); + lines_.push_back(result); + line_names_.push_back("SpecialK"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndSpecialK(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -222,13 +239,29 @@ public: name_ = "IndSpecialK"; text_ = "SpecialK"; series_ = series; - std::vector result = xframe::ind_special_k(xframe::series_closes(series), dummy); - lines_.push_back(result); - line_names_.push_back("SpecialK"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSpecialK() {} diff --git a/widgets/components/IndStandardError/IndStandardError.h b/widgets/components/IndStandardError/IndStandardError.h index b48c91f..4f6b607 100644 --- a/widgets/components/IndStandardError/IndStandardError.h +++ b/widgets/components/IndStandardError/IndStandardError.h @@ -159,6 +159,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_standard_error(series_, period_); + lines_.push_back(Line{"StdError", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndStandardError(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -167,9 +176,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_standard_error(series, period); - lines_.push_back(Line{"StdError", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndStandardError() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndStandardPivotPoints/IndStandardPivotPoints.h b/widgets/components/IndStandardPivotPoints/IndStandardPivotPoints.h index b283e6f..af1d806 100644 --- a/widgets/components/IndStandardPivotPoints/IndStandardPivotPoints.h +++ b/widgets/components/IndStandardPivotPoints/IndStandardPivotPoints.h @@ -155,6 +155,17 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_standard_pivot_points(series_, period_); + lines_.push_back(Line{"Pivot", Srgb{0, 100, 200}, result.pivot}); + lines_.push_back(Line{"R1", Srgb{200, 30, 30}, result.r1}); + lines_.push_back(Line{"S1", Srgb{0, 150, 0}, result.s1}); + } + public: std::function on_view_change; IndStandardPivotPoints(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -163,11 +174,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_standard_pivot_points(series, period); - lines_.push_back(Line{"Pivot", Srgb{0, 100, 200}, result.pivot}); - lines_.push_back(Line{"R1", Srgb{200, 30, 30}, result.r1}); - lines_.push_back(Line{"S1", Srgb{0, 150, 0}, result.s1}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndStandardPivotPoints() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndStdDev/IndStdDev.h b/widgets/components/IndStdDev/IndStdDev.h index 2737b86..7dc29ff 100644 --- a/widgets/components/IndStdDev/IndStdDev.h +++ b/widgets/components/IndStdDev/IndStdDev.h @@ -143,6 +143,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_stddev(series_, period_); + lines_.push_back(Line{"StdDev", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndStdDev(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -151,9 +160,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_stddev(series, period); - lines_.push_back(Line{"StdDev", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndStdDev() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndStochRSI/IndStochRSI.h b/widgets/components/IndStochRSI/IndStochRSI.h index 5c79682..d4f529f 100644 --- a/widgets/components/IndStochRSI/IndStochRSI.h +++ b/widgets/components/IndStochRSI/IndStochRSI.h @@ -202,6 +202,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_stoch_rsi(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("StochRSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndStochRSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -218,13 +235,29 @@ public: name_ = "IndStochRSI"; text_ = "StochRSI"; series_ = series; - std::vector result = xframe::ind_stoch_rsi(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("StochRSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndStochRSI() {} diff --git a/widgets/components/IndStochasticFast/IndStochasticFast.h b/widgets/components/IndStochasticFast/IndStochasticFast.h index a759e02..9da1e70 100644 --- a/widgets/components/IndStochasticFast/IndStochasticFast.h +++ b/widgets/components/IndStochasticFast/IndStochasticFast.h @@ -200,6 +200,27 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + int smooth_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + xframe::IndStochasticFastResult result = xframe::ind_stochastic_fast(series_, period_, smooth_); + lines_.push_back(result.k); + line_names_.push_back("k"); + line_colors_.push_back(Srgb{0, 100, 200}); + lines_.push_back(result.d); + line_names_.push_back("d"); + line_colors_.push_back(Srgb{200, 30, 30}); + + } + public: IndStochasticFast(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14, int smooth = 3) @@ -216,16 +237,30 @@ public: name_ = "IndStochasticFast"; text_ = "StochasticFast"; series_ = series; - xframe::IndStochasticFastResult result = xframe::ind_stochastic_fast(series, period, smooth); - lines_.push_back(result.k); - line_names_.push_back("k"); - line_colors_.push_back(Srgb{0, 100, 200}); - lines_.push_back(result.d); - line_names_.push_back("d"); - line_colors_.push_back(Srgb{200, 30, 30}); - view_count_ = (double)item_count(); + period_ = period; + smooth_ = smooth; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndStochasticFast() {} diff --git a/widgets/components/IndStochasticFull/IndStochasticFull.h b/widgets/components/IndStochasticFull/IndStochasticFull.h index 161edfe..4ed69f8 100644 --- a/widgets/components/IndStochasticFull/IndStochasticFull.h +++ b/widgets/components/IndStochasticFull/IndStochasticFull.h @@ -201,6 +201,28 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + int smooth_k_ = 3; + int smooth_d_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + xframe::IndStochasticFullResult result = xframe::ind_stochastic_full(series_, period_, smooth_k_, smooth_d_); + lines_.push_back(result.k); + line_names_.push_back("k"); + line_colors_.push_back(Srgb{0, 100, 200}); + lines_.push_back(result.d); + line_names_.push_back("d"); + line_colors_.push_back(Srgb{200, 30, 30}); + + } + public: IndStochasticFull(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14, int smooth_k = 3, int smooth_d = 3) @@ -217,16 +239,31 @@ public: name_ = "IndStochasticFull"; text_ = "StochasticFull"; series_ = series; - xframe::IndStochasticFullResult result = xframe::ind_stochastic_full(series, period, smooth_k, smooth_d); - lines_.push_back(result.k); - line_names_.push_back("k"); - line_colors_.push_back(Srgb{0, 100, 200}); - lines_.push_back(result.d); - line_names_.push_back("d"); - line_colors_.push_back(Srgb{200, 30, 30}); - view_count_ = (double)item_count(); + period_ = period; + smooth_k_ = smooth_k; + smooth_d_ = smooth_d; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndStochasticFull() {} diff --git a/widgets/components/IndStochasticPop/IndStochasticPop.h b/widgets/components/IndStochasticPop/IndStochasticPop.h index 944e0d3..f75ba67 100644 --- a/widgets/components/IndStochasticPop/IndStochasticPop.h +++ b/widgets/components/IndStochasticPop/IndStochasticPop.h @@ -204,6 +204,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_stochastic_pop(series_, period_); + lines_.push_back(result); + line_names_.push_back("StochasticPop"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndStochasticPop(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -220,13 +237,29 @@ public: name_ = "IndStochasticPop"; text_ = "StochasticPop"; series_ = series; - std::vector result = xframe::ind_stochastic_pop(series, period); - lines_.push_back(result); - line_names_.push_back("StochasticPop"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndStochasticPop() {} diff --git a/widgets/components/IndStochasticSlow/IndStochasticSlow.h b/widgets/components/IndStochasticSlow/IndStochasticSlow.h index 738dc26..c1d7939 100644 --- a/widgets/components/IndStochasticSlow/IndStochasticSlow.h +++ b/widgets/components/IndStochasticSlow/IndStochasticSlow.h @@ -201,6 +201,27 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + int smooth_ = 3; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + xframe::IndStochasticSlowResult result = xframe::ind_stochastic_slow(series_, period_, smooth_); + lines_.push_back(result.k); + line_names_.push_back("k"); + line_colors_.push_back(Srgb{0, 100, 200}); + lines_.push_back(result.d); + line_names_.push_back("d"); + line_colors_.push_back(Srgb{200, 30, 30}); + + } + public: IndStochasticSlow(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14, int smooth = 3) @@ -217,16 +238,30 @@ public: name_ = "IndStochasticSlow"; text_ = "StochasticSlow"; series_ = series; - xframe::IndStochasticSlowResult result = xframe::ind_stochastic_slow(series, period, smooth); - lines_.push_back(result.k); - line_names_.push_back("k"); - line_colors_.push_back(Srgb{0, 100, 200}); - lines_.push_back(result.d); - line_names_.push_back("d"); - line_colors_.push_back(Srgb{200, 30, 30}); - view_count_ = (double)item_count(); + period_ = period; + smooth_ = smooth; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndStochasticSlow() {} diff --git a/widgets/components/IndSuperSmoother/IndSuperSmoother.h b/widgets/components/IndSuperSmoother/IndSuperSmoother.h index 9e44551..c6ecb64 100644 --- a/widgets/components/IndSuperSmoother/IndSuperSmoother.h +++ b/widgets/components/IndSuperSmoother/IndSuperSmoother.h @@ -196,6 +196,23 @@ private: int grid_divisions_ = 4; Srgb overlay_candle_color_ = Srgb{180, 180, 180}; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_super_smoother(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("SuperSmoother"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndSuperSmoother(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) @@ -212,13 +229,29 @@ public: name_ = "IndSuperSmoother"; text_ = "SuperSmoother"; series_ = series; - std::vector result = xframe::ind_super_smoother(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("SuperSmoother"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSuperSmoother() {} diff --git a/widgets/components/IndSupertrend/IndSupertrend.h b/widgets/components/IndSupertrend/IndSupertrend.h index 91380ac..ad32188 100644 --- a/widgets/components/IndSupertrend/IndSupertrend.h +++ b/widgets/components/IndSupertrend/IndSupertrend.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_supertrend(series_, period_, mult_)); + line_names_.push_back("Supertrend(10,3)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndSupertrend(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10, double mult = 3.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; mult_ = mult; - - lines_.push_back(ind_supertrend(series, period_, mult_)); - line_names_.push_back("Supertrend(10,3)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndSupertrend() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndSwenlinTradingOscillator/IndSwenlinTradingOscillator.h b/widgets/components/IndSwenlinTradingOscillator/IndSwenlinTradingOscillator.h index 4a5dbed..29afb74 100644 --- a/widgets/components/IndSwenlinTradingOscillator/IndSwenlinTradingOscillator.h +++ b/widgets/components/IndSwenlinTradingOscillator/IndSwenlinTradingOscillator.h @@ -204,6 +204,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int slow_ = 35; + int fast_ = 20; + int signal_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_swenlin_trading_oscillator(xframe::series_closes(series_), slow_, fast_, signal_); + lines_.push_back(result); + line_names_.push_back("SwenlinTradingOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndSwenlinTradingOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int slow = 35, int fast = 20, int signal = 10) @@ -220,13 +239,31 @@ public: name_ = "IndSwenlinTradingOscillator"; text_ = "SwenlinTradingOscillator"; series_ = series; - std::vector result = xframe::ind_swenlin_trading_oscillator(xframe::series_closes(series), slow, fast, signal); - lines_.push_back(result); - line_names_.push_back("SwenlinTradingOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + slow_ = slow; + fast_ = fast; + signal_ = signal; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndSwenlinTradingOscillator() {} diff --git a/widgets/components/IndSwingIndex/IndSwingIndex.h b/widgets/components/IndSwingIndex/IndSwingIndex.h index cca7353..9448818 100644 --- a/widgets/components/IndSwingIndex/IndSwingIndex.h +++ b/widgets/components/IndSwingIndex/IndSwingIndex.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_swing_index(series_, limitMove_)); + line_names_.push_back("SwingIndex(1)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndSwingIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), double limitMove = 1.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { limitMove_ = limitMove; - - lines_.push_back(ind_swing_index(series, limitMove_)); - line_names_.push_back("SwingIndex(1)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndSwingIndex() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndT3/IndT3.h b/widgets/components/IndT3/IndT3.h index bacaa61..a17e3be 100644 --- a/widgets/components/IndT3/IndT3.h +++ b/widgets/components/IndT3/IndT3.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_t3(series_closes(series_), period_, vf_)); + line_names_.push_back("T3(5,0.7)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndT3(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 5, double vf = 0.7) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; vf_ = vf; - - lines_.push_back(ind_t3(series_closes(series), period_, vf_)); - line_names_.push_back("T3(5,0.7)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndT3() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndTDSequential/IndTDSequential.h b/widgets/components/IndTDSequential/IndTDSequential.h index 69463e9..65ccc56 100644 --- a/widgets/components/IndTDSequential/IndTDSequential.h +++ b/widgets/components/IndTDSequential/IndTDSequential.h @@ -206,6 +206,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_td_sequential(xframe::series_closes(series_), dummy_); + lines_.push_back(result); + line_names_.push_back("TDSequential"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndTDSequential(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -222,13 +239,29 @@ public: name_ = "IndTDSequential"; text_ = "TDSequential"; series_ = series; - std::vector result = xframe::ind_td_sequential(xframe::series_closes(series), dummy); - lines_.push_back(result); - line_names_.push_back("TDSequential"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndTDSequential() {} diff --git a/widgets/components/IndTEMA/IndTEMA.h b/widgets/components/IndTEMA/IndTEMA.h index 6b38ac9..2bcde4d 100644 --- a/widgets/components/IndTEMA/IndTEMA.h +++ b/widgets/components/IndTEMA/IndTEMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_tema(series_closes(series_), period_)); + line_names_.push_back("TEMA(14)"); + line_colors_.push_back(Srgb{120, 60, 180}); + } + public: IndTEMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_tema(series_closes(series), period_)); - line_names_.push_back("TEMA(14)"); - line_colors_.push_back(Srgb{120, 60, 180}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndTEMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndTRIMA/IndTRIMA.h b/widgets/components/IndTRIMA/IndTRIMA.h index 4353991..f3342b5 100644 --- a/widgets/components/IndTRIMA/IndTRIMA.h +++ b/widgets/components/IndTRIMA/IndTRIMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_trima(series_closes(series_), period_)); + line_names_.push_back("TRIMA(14)"); + line_colors_.push_back(Srgb{0, 150, 150}); + } + public: IndTRIMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_trima(series_closes(series), period_)); - line_names_.push_back("TRIMA(14)"); - line_colors_.push_back(Srgb{0, 150, 150}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndTRIMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndTRIX/IndTRIX.h b/widgets/components/IndTRIX/IndTRIX.h index 4e5aca4..f6993db 100644 --- a/widgets/components/IndTRIX/IndTRIX.h +++ b/widgets/components/IndTRIX/IndTRIX.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_trix(series_closes(series_), period_)); + line_names_.push_back("TRIX(14)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndTRIX(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_trix(series_closes(series), period_)); - line_names_.push_back("TRIX(14)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndTRIX() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndTSF/IndTSF.h b/widgets/components/IndTSF/IndTSF.h index 994a08a..fb3b0cb 100644 --- a/widgets/components/IndTSF/IndTSF.h +++ b/widgets/components/IndTSF/IndTSF.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_tsf(series_closes(series_), period_)); + line_names_.push_back("TSF(14)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndTSF(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_tsf(series_closes(series), period_)); - line_names_.push_back("TSF(14)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndTSF() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndTSI/IndTSI.h b/widgets/components/IndTSI/IndTSI.h index 689bf27..f5b2c3b 100644 --- a/widgets/components/IndTSI/IndTSI.h +++ b/widgets/components/IndTSI/IndTSI.h @@ -201,6 +201,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int long_period_ = 25; + int short_period_ = 13; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_tsi(xframe::series_closes(series_), long_period_, short_period_); + lines_.push_back(result); + line_names_.push_back("TSI"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndTSI(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int long_period = 25, int short_period = 13) @@ -217,13 +235,30 @@ public: name_ = "IndTSI"; text_ = "TSI"; series_ = series; - std::vector result = xframe::ind_tsi(xframe::series_closes(series), long_period, short_period); - lines_.push_back(result); - line_names_.push_back("TSI"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + long_period_ = long_period; + short_period_ = short_period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndTSI() {} diff --git a/widgets/components/IndTSMA/IndTSMA.h b/widgets/components/IndTSMA/IndTSMA.h index 16f0524..a28c3e9 100644 --- a/widgets/components/IndTSMA/IndTSMA.h +++ b/widgets/components/IndTSMA/IndTSMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_tsma(series_closes(series_), period_)); + line_names_.push_back("TSMA(14)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndTSMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_tsma(series_closes(series), period_)); - line_names_.push_back("TSMA(14)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndTSMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndTTMSqueeze/IndTTMSqueeze.h b/widgets/components/IndTTMSqueeze/IndTTMSqueeze.h index bc42d4b..7a36be3 100644 --- a/widgets/components/IndTTMSqueeze/IndTTMSqueeze.h +++ b/widgets/components/IndTTMSqueeze/IndTTMSqueeze.h @@ -158,6 +158,16 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_ttm_squeeze(series_, period_, mult_); + lines_.push_back(Line{"Squeeze", Srgb{200, 30, 30}, result.squeeze}); + lines_.push_back(Line{"BB/KC ratio", Srgb{0, 100, 200}, result.ratio}); + } + public: std::function on_view_change; IndTTMSqueeze(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -166,10 +176,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_ttm_squeeze(series, period, mult); - lines_.push_back(Line{"Squeeze", Srgb{200, 30, 30}, result.squeeze}); - lines_.push_back(Line{"BB/KC ratio", Srgb{0, 100, 200}, result.ratio}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndTTMSqueeze() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndTenkanSen/IndTenkanSen.h b/widgets/components/IndTenkanSen/IndTenkanSen.h index 34a9ef6..d2cdb41 100644 --- a/widgets/components/IndTenkanSen/IndTenkanSen.h +++ b/widgets/components/IndTenkanSen/IndTenkanSen.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_tenkan_sen(series_, period_)); + line_names_.push_back("TenkanSen(9)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndTenkanSen(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 9) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_tenkan_sen(series, period_)); - line_names_.push_back("TenkanSen(9)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndTenkanSen() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndTrendFlex/IndTrendFlex.h b/widgets/components/IndTrendFlex/IndTrendFlex.h index f5e762e..65fed2d 100644 --- a/widgets/components/IndTrendFlex/IndTrendFlex.h +++ b/widgets/components/IndTrendFlex/IndTrendFlex.h @@ -197,6 +197,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 10; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_trend_flex(xframe::series_closes(series_), period_); + lines_.push_back(result); + line_names_.push_back("TrendFlex"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndTrendFlex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10) @@ -213,13 +230,29 @@ public: name_ = "IndTrendFlex"; text_ = "TrendFlex"; series_ = series; - std::vector result = xframe::ind_trend_flex(xframe::series_closes(series), period); - lines_.push_back(result); - line_names_.push_back("TrendFlex"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndTrendFlex() {} diff --git a/widgets/components/IndTrendIntensityIndex/IndTrendIntensityIndex.h b/widgets/components/IndTrendIntensityIndex/IndTrendIntensityIndex.h index a507042..731f6fd 100644 --- a/widgets/components/IndTrendIntensityIndex/IndTrendIntensityIndex.h +++ b/widgets/components/IndTrendIntensityIndex/IndTrendIntensityIndex.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_trend_intensity(series_closes(series_), period_)); + line_names_.push_back("TII(30)"); + line_colors_.push_back(Srgb{0, 100, 200}); + } + public: IndTrendIntensityIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 30) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_trend_intensity(series_closes(series), period_)); - line_names_.push_back("TII(30)"); - line_colors_.push_back(Srgb{0, 100, 200}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndTrendIntensityIndex() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndTrueRange/IndTrueRange.h b/widgets/components/IndTrueRange/IndTrueRange.h index bfb47cc..b6e2545 100644 --- a/widgets/components/IndTrueRange/IndTrueRange.h +++ b/widgets/components/IndTrueRange/IndTrueRange.h @@ -143,6 +143,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_true_range(series_, period_); + lines_.push_back(Line{"TR", Srgb{200, 120, 0}, result}); + } + public: std::function on_view_change; IndTrueRange(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -151,9 +160,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_true_range(series, period); - lines_.push_back(Line{"TR", Srgb{200, 120, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndTrueRange() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndTwiggsMoneyFlow/IndTwiggsMoneyFlow.h b/widgets/components/IndTwiggsMoneyFlow/IndTwiggsMoneyFlow.h index 800cfd0..49e54e0 100644 --- a/widgets/components/IndTwiggsMoneyFlow/IndTwiggsMoneyFlow.h +++ b/widgets/components/IndTwiggsMoneyFlow/IndTwiggsMoneyFlow.h @@ -158,6 +158,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_twiggs_money_flow(series_, period_); + lines_.push_back(Line{"TwiggsMF", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndTwiggsMoneyFlow(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -166,9 +175,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_twiggs_money_flow(series, period); - lines_.push_back(Line{"TwiggsMF", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndTwiggsMoneyFlow() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndTypicalPrice/IndTypicalPrice.h b/widgets/components/IndTypicalPrice/IndTypicalPrice.h index 59f4ef5..60fb331 100644 --- a/widgets/components/IndTypicalPrice/IndTypicalPrice.h +++ b/widgets/components/IndTypicalPrice/IndTypicalPrice.h @@ -143,6 +143,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_typical_price(series_, period_); + lines_.push_back(Line{"Typical", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndTypicalPrice(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -151,9 +160,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_typical_price(series, period); - lines_.push_back(Line{"Typical", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndTypicalPrice() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndUTBot/IndUTBot.h b/widgets/components/IndUTBot/IndUTBot.h index 1592411..6e56234 100644 --- a/widgets/components/IndUTBot/IndUTBot.h +++ b/widgets/components/IndUTBot/IndUTBot.h @@ -233,18 +233,44 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_ut_bot(series_, period_, mult_)); + line_names_.push_back("UTBot(10,1)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndUTBot(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 10, double mult = 1.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; mult_ = mult; - - lines_.push_back(ind_ut_bot(series, period_, mult_)); - line_names_.push_back("UTBot(10,1)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndUTBot() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndUlcerIndex/IndUlcerIndex.h b/widgets/components/IndUlcerIndex/IndUlcerIndex.h index 8f63e99..b818bde 100644 --- a/widgets/components/IndUlcerIndex/IndUlcerIndex.h +++ b/widgets/components/IndUlcerIndex/IndUlcerIndex.h @@ -154,6 +154,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_ulcer_index(series_, period_); + lines_.push_back(Line{"UlcerIndex", Srgb{200, 0, 0}, result}); + } + public: std::function on_view_change; IndUlcerIndex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -162,9 +171,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_ulcer_index(series, period); - lines_.push_back(Line{"UlcerIndex", Srgb{200, 0, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndUlcerIndex() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndUltimateOscillator/IndUltimateOscillator.h b/widgets/components/IndUltimateOscillator/IndUltimateOscillator.h index 7b3f52c..3076ec1 100644 --- a/widgets/components/IndUltimateOscillator/IndUltimateOscillator.h +++ b/widgets/components/IndUltimateOscillator/IndUltimateOscillator.h @@ -210,6 +210,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int p1_ = 7; + int p2_ = 14; + int p3_ = 28; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_ultimate_oscillator(series_, p1_, p2_, p3_); + lines_.push_back(result); + line_names_.push_back("UltimateOscillator"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndUltimateOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int p1 = 7, int p2 = 14, int p3 = 28) @@ -226,13 +245,31 @@ public: name_ = "IndUltimateOscillator"; text_ = "UltimateOscillator"; series_ = series; - std::vector result = xframe::ind_ultimate_oscillator(series, p1, p2, p3); - lines_.push_back(result); - line_names_.push_back("UltimateOscillator"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + p1_ = p1; + p2_ = p2; + p3_ = p3; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndUltimateOscillator() {} diff --git a/widgets/components/IndUpDownRatio/IndUpDownRatio.h b/widgets/components/IndUpDownRatio/IndUpDownRatio.h index 8cff57d..933a3e1 100644 --- a/widgets/components/IndUpDownRatio/IndUpDownRatio.h +++ b/widgets/components/IndUpDownRatio/IndUpDownRatio.h @@ -154,6 +154,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_up_down_ratio(series_, period_); + lines_.push_back(Line{"UpDownRatio", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndUpDownRatio(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -162,9 +171,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_up_down_ratio(series, period); - lines_.push_back(Line{"UpDownRatio", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndUpDownRatio() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndUpDownVolumeRatio/IndUpDownVolumeRatio.h b/widgets/components/IndUpDownVolumeRatio/IndUpDownVolumeRatio.h index 641cc09..ace9f12 100644 --- a/widgets/components/IndUpDownVolumeRatio/IndUpDownVolumeRatio.h +++ b/widgets/components/IndUpDownVolumeRatio/IndUpDownVolumeRatio.h @@ -152,6 +152,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_up_down_volume_ratio(series_, period_); + lines_.push_back(Line{"UpDownVol", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndUpDownVolumeRatio(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -160,9 +169,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_up_down_volume_ratio(series, period); - lines_.push_back(Line{"UpDownVol", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndUpDownVolumeRatio() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVHF/IndVHF.h b/widgets/components/IndVHF/IndVHF.h index 16fbde7..7e7efb7 100644 --- a/widgets/components/IndVHF/IndVHF.h +++ b/widgets/components/IndVHF/IndVHF.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_vhf(series_, period_)); + line_names_.push_back("VHF(28)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndVHF(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 28) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_vhf(series, period_)); - line_names_.push_back("VHF(28)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndVHF() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndVIDYA/IndVIDYA.h b/widgets/components/IndVIDYA/IndVIDYA.h index edb7b6b..48cb86d 100644 --- a/widgets/components/IndVIDYA/IndVIDYA.h +++ b/widgets/components/IndVIDYA/IndVIDYA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_vidya(series_closes(series_), period_)); + line_names_.push_back("VIDYA(14)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndVIDYA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_vidya(series_closes(series), period_)); - line_names_.push_back("VIDYA(14)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndVIDYA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndVWAP/IndVWAP.h b/widgets/components/IndVWAP/IndVWAP.h index 902e714..035a336 100644 --- a/widgets/components/IndVWAP/IndVWAP.h +++ b/widgets/components/IndVWAP/IndVWAP.h @@ -151,6 +151,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_vwap(series_, period_); + lines_.push_back(Line{"VWAP", Srgb{200, 120, 0}, result}); + } + public: std::function on_view_change; IndVWAP(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -159,9 +168,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_vwap(series, period); - lines_.push_back(Line{"VWAP", Srgb{200, 120, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVWAP() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVWAPBands/IndVWAPBands.h b/widgets/components/IndVWAPBands/IndVWAPBands.h index 52f5ba1..13e585c 100644 --- a/widgets/components/IndVWAPBands/IndVWAPBands.h +++ b/widgets/components/IndVWAPBands/IndVWAPBands.h @@ -161,6 +161,17 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_vwap_bands(series_, period_, mult_); + lines_.push_back(Line{"Upper", Srgb{200, 30, 30}, result.upper}); + lines_.push_back(Line{"VWAP", Srgb{200, 120, 0}, result.vwap}); + lines_.push_back(Line{"Lower", Srgb{200, 30, 30}, result.lower}); + } + public: std::function on_view_change; IndVWAPBands(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -169,11 +180,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_vwap_bands(series, period, mult); - lines_.push_back(Line{"Upper", Srgb{200, 30, 30}, result.upper}); - lines_.push_back(Line{"VWAP", Srgb{200, 120, 0}, result.vwap}); - lines_.push_back(Line{"Lower", Srgb{200, 30, 30}, result.lower}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVWAPBands() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVWEMA/IndVWEMA.h b/widgets/components/IndVWEMA/IndVWEMA.h index fd0874d..50b2b30 100644 --- a/widgets/components/IndVWEMA/IndVWEMA.h +++ b/widgets/components/IndVWEMA/IndVWEMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_vwema(series_, period_)); + line_names_.push_back("VWEMA(14)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndVWEMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_vwema(series, period_)); - line_names_.push_back("VWEMA(14)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndVWEMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndVWMA/IndVWMA.h b/widgets/components/IndVWMA/IndVWMA.h index efa1c0c..94dd881 100644 --- a/widgets/components/IndVWMA/IndVWMA.h +++ b/widgets/components/IndVWMA/IndVWMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_vwma(series_, period_)); + line_names_.push_back("VWMA(20)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndVWMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 20) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_vwma(series, period_)); - line_names_.push_back("VWMA(20)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndVWMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndVariance/IndVariance.h b/widgets/components/IndVariance/IndVariance.h index bee76d8..e9f1765 100644 --- a/widgets/components/IndVariance/IndVariance.h +++ b/widgets/components/IndVariance/IndVariance.h @@ -146,6 +146,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_variance(series_, period_); + lines_.push_back(Line{"Variance", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndVariance(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -154,9 +163,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_variance(series, period); - lines_.push_back(Line{"Variance", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVariance() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolatilityRatio/IndVolatilityRatio.h b/widgets/components/IndVolatilityRatio/IndVolatilityRatio.h index db4463c..0a7d7aa 100644 --- a/widgets/components/IndVolatilityRatio/IndVolatilityRatio.h +++ b/widgets/components/IndVolatilityRatio/IndVolatilityRatio.h @@ -148,6 +148,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volatility_ratio(series_, period_); + lines_.push_back(Line{"VolRatio", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndVolatilityRatio(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -156,9 +165,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volatility_ratio(series, period); - lines_.push_back(Line{"VolRatio", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolatilityRatio() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolatilityStop/IndVolatilityStop.h b/widgets/components/IndVolatilityStop/IndVolatilityStop.h index 118c9b5..3203cd3 100644 --- a/widgets/components/IndVolatilityStop/IndVolatilityStop.h +++ b/widgets/components/IndVolatilityStop/IndVolatilityStop.h @@ -158,6 +158,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volatility_stop(series_, period_, mult_); + lines_.push_back(Line{"VolStop", Srgb{200, 30, 30}, result}); + } + public: std::function on_view_change; IndVolatilityStop(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -166,9 +175,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volatility_stop(series, period, mult); - lines_.push_back(Line{"VolStop", Srgb{200, 30, 30}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolatilityStop() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolumeAverage/IndVolumeAverage.h b/widgets/components/IndVolumeAverage/IndVolumeAverage.h index 0328611..269b274 100644 --- a/widgets/components/IndVolumeAverage/IndVolumeAverage.h +++ b/widgets/components/IndVolumeAverage/IndVolumeAverage.h @@ -143,6 +143,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volume_average(series_, period_); + lines_.push_back(Line{"VolAvg", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndVolumeAverage(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -151,9 +160,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volume_average(series, period); - lines_.push_back(Line{"VolAvg", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolumeAverage() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolumeDelta/IndVolumeDelta.h b/widgets/components/IndVolumeDelta/IndVolumeDelta.h index 5485525..0aa1d52 100644 --- a/widgets/components/IndVolumeDelta/IndVolumeDelta.h +++ b/widgets/components/IndVolumeDelta/IndVolumeDelta.h @@ -150,6 +150,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volume_delta(series_, period_); + lines_.push_back(Line{"VolDelta", Srgb{0, 150, 0}, result}); + } + public: std::function on_view_change; IndVolumeDelta(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -158,9 +167,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volume_delta(series, period); - lines_.push_back(Line{"VolDelta", Srgb{0, 150, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolumeDelta() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolumeOscillator/IndVolumeOscillator.h b/widgets/components/IndVolumeOscillator/IndVolumeOscillator.h index e6756a2..4c3f0f2 100644 --- a/widgets/components/IndVolumeOscillator/IndVolumeOscillator.h +++ b/widgets/components/IndVolumeOscillator/IndVolumeOscillator.h @@ -149,6 +149,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volume_oscillator(series_, period_); + lines_.push_back(Line{"VolOsc", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndVolumeOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -157,9 +166,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volume_oscillator(series, period); - lines_.push_back(Line{"VolOsc", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolumeOscillator() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolumePriceTrend/IndVolumePriceTrend.h b/widgets/components/IndVolumePriceTrend/IndVolumePriceTrend.h index a45a0a5..8a4f592 100644 --- a/widgets/components/IndVolumePriceTrend/IndVolumePriceTrend.h +++ b/widgets/components/IndVolumePriceTrend/IndVolumePriceTrend.h @@ -151,6 +151,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volume_price_trend(series_, period_); + lines_.push_back(Line{"VPT", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndVolumePriceTrend(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -159,9 +168,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volume_price_trend(series, period); - lines_.push_back(Line{"VPT", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolumePriceTrend() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolumeRateOfChange/IndVolumeRateOfChange.h b/widgets/components/IndVolumeRateOfChange/IndVolumeRateOfChange.h index d0cc6bf..c8fa12e 100644 --- a/widgets/components/IndVolumeRateOfChange/IndVolumeRateOfChange.h +++ b/widgets/components/IndVolumeRateOfChange/IndVolumeRateOfChange.h @@ -147,6 +147,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volume_rate_of_change(series_, period_); + lines_.push_back(Line{"VROC", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndVolumeRateOfChange(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -155,9 +164,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volume_rate_of_change(series, period); - lines_.push_back(Line{"VROC", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolumeRateOfChange() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolumeWeightedMovingAverage/IndVolumeWeightedMovingAverage.h b/widgets/components/IndVolumeWeightedMovingAverage/IndVolumeWeightedMovingAverage.h index e07ff38..057e89d 100644 --- a/widgets/components/IndVolumeWeightedMovingAverage/IndVolumeWeightedMovingAverage.h +++ b/widgets/components/IndVolumeWeightedMovingAverage/IndVolumeWeightedMovingAverage.h @@ -150,6 +150,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volume_weighted_moving_average(series_, period_); + lines_.push_back(Line{"VWMA", Srgb{200, 120, 0}, result}); + } + public: std::function on_view_change; IndVolumeWeightedMovingAverage(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -158,9 +167,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volume_weighted_moving_average(series, period); - lines_.push_back(Line{"VWMA", Srgb{200, 120, 0}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolumeWeightedMovingAverage() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVolumeZoneOscillator/IndVolumeZoneOscillator.h b/widgets/components/IndVolumeZoneOscillator/IndVolumeZoneOscillator.h index 69837df..f815b88 100644 --- a/widgets/components/IndVolumeZoneOscillator/IndVolumeZoneOscillator.h +++ b/widgets/components/IndVolumeZoneOscillator/IndVolumeZoneOscillator.h @@ -156,6 +156,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_volume_zone_oscillator(series_, period_); + lines_.push_back(Line{"VZO", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndVolumeZoneOscillator(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -164,9 +173,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_volume_zone_oscillator(series, period); - lines_.push_back(Line{"VZO", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndVolumeZoneOscillator() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndVortex/IndVortex.h b/widgets/components/IndVortex/IndVortex.h index c90dda0..5b28896 100644 --- a/widgets/components/IndVortex/IndVortex.h +++ b/widgets/components/IndVortex/IndVortex.h @@ -233,15 +233,41 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + { auto vr = ind_vortex(series_, period_); lines_.push_back(vr.plus); line_names_.push_back("VI+(14)"); line_colors_.push_back(Srgb{0, 150, 0}); lines_.push_back(vr.minus); line_names_.push_back("VI-(14)"); line_colors_.push_back(Srgb{200, 30, 30}); } + } + public: IndVortex(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - { auto vr = ind_vortex(series, period_); lines_.push_back(vr.plus); line_names_.push_back("VI+(14)"); line_colors_.push_back(Srgb{0, 150, 0}); lines_.push_back(vr.minus); line_names_.push_back("VI-(14)"); line_colors_.push_back(Srgb{200, 30, 30}); } - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndVortex() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndWMA/IndWMA.h b/widgets/components/IndWMA/IndWMA.h index d6b517a..fc6f51f 100644 --- a/widgets/components/IndWMA/IndWMA.h +++ b/widgets/components/IndWMA/IndWMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_wma(series_closes(series_), period_)); + line_names_.push_back("WMA(14)"); + line_colors_.push_back(Srgb{0, 150, 0}); + } + public: IndWMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_wma(series_closes(series), period_)); - line_names_.push_back("WMA(14)"); - line_colors_.push_back(Srgb{0, 150, 0}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndWMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndWaveTrend/IndWaveTrend.h b/widgets/components/IndWaveTrend/IndWaveTrend.h index 1d76835..c029494 100644 --- a/widgets/components/IndWaveTrend/IndWaveTrend.h +++ b/widgets/components/IndWaveTrend/IndWaveTrend.h @@ -202,6 +202,24 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int esa_ = 10; + int d_ = 21; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_wave_trend(series_, esa_, d_); + lines_.push_back(result); + line_names_.push_back("WaveTrend"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndWaveTrend(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int esa = 10, int d = 21) @@ -218,13 +236,30 @@ public: name_ = "IndWaveTrend"; text_ = "WaveTrend"; series_ = series; - std::vector result = xframe::ind_wave_trend(series, esa, d); - lines_.push_back(result); - line_names_.push_back("WaveTrend"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + esa_ = esa; + d_ = d; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndWaveTrend() {} diff --git a/widgets/components/IndWeightedClose/IndWeightedClose.h b/widgets/components/IndWeightedClose/IndWeightedClose.h index 1995dde..83554df 100644 --- a/widgets/components/IndWeightedClose/IndWeightedClose.h +++ b/widgets/components/IndWeightedClose/IndWeightedClose.h @@ -146,6 +146,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_weighted_close(series_, period_); + lines_.push_back(Line{"WtdClose", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndWeightedClose(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -154,9 +163,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_weighted_close(series, period); - lines_.push_back(Line{"WtdClose", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndWeightedClose() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndWilderVolatilitySystem/IndWilderVolatilitySystem.h b/widgets/components/IndWilderVolatilitySystem/IndWilderVolatilitySystem.h index 99800b0..066d748 100644 --- a/widgets/components/IndWilderVolatilitySystem/IndWilderVolatilitySystem.h +++ b/widgets/components/IndWilderVolatilitySystem/IndWilderVolatilitySystem.h @@ -160,6 +160,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_wilder_volatility_system(series_, period_, mult_); + lines_.push_back(Line{"VolSystem", Srgb{200, 30, 30}, result}); + } + public: std::function on_view_change; IndWilderVolatilitySystem(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -168,9 +177,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_wilder_volatility_system(series, period, mult); - lines_.push_back(Line{"VolSystem", Srgb{200, 30, 30}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndWilderVolatilitySystem() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndWildersMA/IndWildersMA.h b/widgets/components/IndWildersMA/IndWildersMA.h index 8393691..2a8083a 100644 --- a/widgets/components/IndWildersMA/IndWildersMA.h +++ b/widgets/components/IndWildersMA/IndWildersMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_wilders_ma(series_closes(series_), period_)); + line_names_.push_back("WildersMA(14)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndWildersMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_wilders_ma(series_closes(series), period_)); - line_names_.push_back("WildersMA(14)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndWildersMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndWilliamsAccumulationDistribution/IndWilliamsAccumulationDistribution.h b/widgets/components/IndWilliamsAccumulationDistribution/IndWilliamsAccumulationDistribution.h index e7390a4..4201836 100644 --- a/widgets/components/IndWilliamsAccumulationDistribution/IndWilliamsAccumulationDistribution.h +++ b/widgets/components/IndWilliamsAccumulationDistribution/IndWilliamsAccumulationDistribution.h @@ -205,6 +205,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int dummy_ = 0; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_williams_ad(series_, dummy_); + lines_.push_back(result); + line_names_.push_back("WilliamsAccumulationDistribution"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndWilliamsAccumulationDistribution(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int dummy = 0) @@ -221,13 +238,29 @@ public: name_ = "IndWilliamsAccumulationDistribution"; text_ = "WilliamsAccumulationDistribution"; series_ = series; - std::vector result = xframe::ind_williams_ad(series, dummy); - lines_.push_back(result); - line_names_.push_back("WilliamsAccumulationDistribution"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + dummy_ = dummy; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndWilliamsAccumulationDistribution() {} diff --git a/widgets/components/IndWilliamsR/IndWilliamsR.h b/widgets/components/IndWilliamsR/IndWilliamsR.h index d60b7f7..8ef9e50 100644 --- a/widgets/components/IndWilliamsR/IndWilliamsR.h +++ b/widgets/components/IndWilliamsR/IndWilliamsR.h @@ -202,6 +202,23 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int period_ = 14; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_williams_r(series_, period_); + lines_.push_back(result); + line_names_.push_back("WilliamsR"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndWilliamsR(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) @@ -218,13 +235,29 @@ public: name_ = "IndWilliamsR"; text_ = "WilliamsR"; series_ = series; - std::vector result = xframe::ind_williams_r(series, period); - lines_.push_back(result); - line_names_.push_back("WilliamsR"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + period_ = period; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndWilliamsR() {} diff --git a/widgets/components/IndWoodiePivotPoints/IndWoodiePivotPoints.h b/widgets/components/IndWoodiePivotPoints/IndWoodiePivotPoints.h index 8e69dbf..0510a0b 100644 --- a/widgets/components/IndWoodiePivotPoints/IndWoodiePivotPoints.h +++ b/widgets/components/IndWoodiePivotPoints/IndWoodiePivotPoints.h @@ -155,6 +155,17 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_woodie_pivot_points(series_, period_); + lines_.push_back(Line{"Pivot", Srgb{0, 100, 200}, result.pivot}); + lines_.push_back(Line{"R1", Srgb{200, 30, 30}, result.r1}); + lines_.push_back(Line{"S1", Srgb{0, 150, 0}, result.s1}); + } + public: std::function on_view_change; IndWoodiePivotPoints(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -163,11 +174,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_woodie_pivot_points(series, period); - lines_.push_back(Line{"Pivot", Srgb{0, 100, 200}, result.pivot}); - lines_.push_back(Line{"R1", Srgb{200, 30, 30}, result.r1}); - lines_.push_back(Line{"S1", Srgb{0, 150, 0}, result.s1}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndWoodiePivotPoints() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndYangZhangVolatility/IndYangZhangVolatility.h b/widgets/components/IndYangZhangVolatility/IndYangZhangVolatility.h index d20b2a2..04c1dad 100644 --- a/widgets/components/IndYangZhangVolatility/IndYangZhangVolatility.h +++ b/widgets/components/IndYangZhangVolatility/IndYangZhangVolatility.h @@ -178,6 +178,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_yang_zhang_volatility(series_, period_); + lines_.push_back(Line{"YangZhang", Srgb{150, 0, 150}, result}); + } + public: std::function on_view_change; IndYangZhangVolatility(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -186,9 +195,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_yang_zhang_volatility(series, period); - lines_.push_back(Line{"YangZhang", Srgb{150, 0, 150}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndYangZhangVolatility() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndZLEMA/IndZLEMA.h b/widgets/components/IndZLEMA/IndZLEMA.h index 4b7ceb9..7f1c9c3 100644 --- a/widgets/components/IndZLEMA/IndZLEMA.h +++ b/widgets/components/IndZLEMA/IndZLEMA.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_zlema(series_closes(series_), period_)); + line_names_.push_back("ZLEMA(14)"); + line_colors_.push_back(Srgb{230, 126, 34}); + } + public: IndZLEMA(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), int period = 14) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { period_ = period; - - lines_.push_back(ind_zlema(series_closes(series), period_)); - line_names_.push_back("ZLEMA(14)"); - line_colors_.push_back(Srgb{230, 126, 34}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndZLEMA() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/components/IndZScore/IndZScore.h b/widgets/components/IndZScore/IndZScore.h index c06e3f8..5c1c366 100644 --- a/widgets/components/IndZScore/IndZScore.h +++ b/widgets/components/IndZScore/IndZScore.h @@ -148,6 +148,15 @@ private: Srgb candle_up_color_ = Srgb{0, 150, 0}; Srgb candle_down_color_ = Srgb{200, 30, 30}; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + auto result = ind_z_score(series_, period_); + lines_.push_back(Line{"ZScore", Srgb{0, 100, 200}, result}); + } + public: std::function on_view_change; IndZScore(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, @@ -156,9 +165,27 @@ public: : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series), period_(period), mult_(mult) { - auto result = ind_z_score(series, period); - lines_.push_back(Line{"ZScore", Srgb{0, 100, 200}, result}); + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndZScore() {} void set_bounds(int x, int y, int width, int height) { x1_ = x; y1_ = y; x2_ = x + width; y2_ = y + height; } int width() { return x2_ - x1_; } diff --git a/widgets/components/IndZeroLagMACD/IndZeroLagMACD.h b/widgets/components/IndZeroLagMACD/IndZeroLagMACD.h index 6c65699..4bdbfbe 100644 --- a/widgets/components/IndZeroLagMACD/IndZeroLagMACD.h +++ b/widgets/components/IndZeroLagMACD/IndZeroLagMACD.h @@ -208,6 +208,25 @@ private: int line_width_ = 2; int grid_divisions_ = 4; + // Series parameters stored for recompute_lines() (these were + // constructor-only before the CSV series API). + int fast_ = 12; + int slow_ = 26; + int signal_ = 9; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + std::vector result = xframe::ind_zero_lag_macd(xframe::series_closes(series_), fast_, slow_, signal_); + lines_.push_back(result); + line_names_.push_back("ZeroLagMACD"); + line_colors_.push_back(Srgb{0, 100, 200}); + + } + public: IndZeroLagMACD(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const xframe::OHLCVSeries& series = xframe::make_seeded_series(250), int fast = 12, int slow = 26, int signal = 9) @@ -224,13 +243,31 @@ public: name_ = "IndZeroLagMACD"; text_ = "ZeroLagMACD"; series_ = series; - std::vector result = xframe::ind_zero_lag_macd(xframe::series_closes(series), fast, slow, signal); - lines_.push_back(result); - line_names_.push_back("ZeroLagMACD"); - line_colors_.push_back(Srgb{0, 100, 200}); - view_count_ = (double)item_count(); + fast_ = fast; + slow_ = slow; + signal_ = signal; + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + reset_view(); + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + const xframe::OHLCVSeries& series() const { return series_; } + ~IndZeroLagMACD() {} diff --git a/widgets/components/IndZigZag/IndZigZag.h b/widgets/components/IndZigZag/IndZigZag.h index a70ebde..e033e1b 100644 --- a/widgets/components/IndZigZag/IndZigZag.h +++ b/widgets/components/IndZigZag/IndZigZag.h @@ -232,17 +232,43 @@ private: Srgb candle_down_color_ = Srgb{210, 130, 130}; int point_size_ = 5; + // Rebuild lines_ (and line_names_/line_colors_ where present) + // from series_ with the stored parameters. Called by the + // constructor and by set_series(). + void recompute_lines() { + lines_.clear(); + line_names_.clear(); + line_colors_.clear(); + + lines_.push_back(ind_zigzag(series_, deviation_)); + line_names_.push_back("ZigZag(5%)"); + line_colors_.push_back(Srgb{200, 30, 30}); + } + public: IndZigZag(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height, const OHLCVSeries& series = xframe::make_seeded_series(250), double deviation = 5.0) : display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles), x1_(x), y1_(y), x2_(x + width), y2_(y + height), series_(series) { deviation_ = deviation; - - lines_.push_back(ind_zigzag(series, deviation_)); - line_names_.push_back("ZigZag(5%)"); - line_colors_.push_back(Srgb{200, 30, 30}); - + recompute_lines(); } + // Series API (CSV): replace the plotted series and recompute the + // indicator lines from it — same shape as the Stock* chart widgets + // (see docs/stock-market-csv-data.md). load_csv leaves the old + // series untouched on failure; clear_series() empties the series + // (the seeded template is only the constructor default). + void set_series(const xframe::OHLCVSeries& s) { + series_ = s; + recompute_lines(); + } + bool load_csv(const std::string& path, std::string& error) { + xframe::OHLCVSeries s = xframe::load_ohlcv_csv(path, error); + if (!error.empty()) return false; + set_series(s); + return true; + } + void clear_series() { set_series(xframe::OHLCVSeries{}); } + ~IndZigZag() {} void set_bounds(int x, int y, int w, int h) { x1_ = x; y1_ = y; x2_ = x + w; y2_ = y + h; } int width() { return x2_ - x1_; } int height() { return y2_ - y1_; } diff --git a/widgets/tests/ind_csv_harness.cpp b/widgets/tests/ind_csv_harness.cpp new file mode 100644 index 0000000..88fdd62 --- /dev/null +++ b/widgets/tests/ind_csv_harness.cpp @@ -0,0 +1,146 @@ +// ind_csv_harness.cpp — per-widget harness for the Ind* CSV series API. +// +// Compiled once per indicator with: +// g++ -std=c++17 -O2 -Wall -Wextra -I widgets/components +// -DIND_HEADER=IndSMA/IndSMA.h -DIND_NAME=IndSMA +// -DIND_LINE_FN=line_values +// widgets/tests/ind_csv_harness.cpp -lX11 -o /tmp/ind_harness_IndSMA +// +// IND_LINE_FN is the widget's line accessor: line_values (165 widgets) or +// line (85 widgets). Modes (argv[1]): +// numeric template dump, load_csv(A), set_series(B), +// bad-path load, clear_series + draw; prints +// machine-readable lines and exits. +// shot-template draw the template series, stay alive until the +// window is closed (driver screenshots it). +// shot-csv same, after load_csv(csv). +// Attribution: XFrame. +#include +#include +#include +#include +#include +#include + +#define _IND_STR(x) #x +#define IND_STR(x) _IND_STR(x) +#include IND_STR(IND_HEADER) + +// 85 of the 250 widgets declare their class in the global namespace +// (their namespace xframe closes before the class); the other 165 are +// xframe::Ind*. The using-directive makes the unqualified name work for +// both shapes. +using namespace xframe; + +static const char* kName = IND_STR(IND_NAME); + +template +static void dump_lines(const char* tag, W& w) { + std::printf("%s lines=%d items=%d\n", tag, w.line_count(), + (int)w.series().size()); + for (int i = 0; i < w.line_count(); ++i) { + const std::vector& v = w.IND_LINE_FN(i); + double last = std::numeric_limits::quiet_NaN(); + double sum = 0.0, sumsq = 0.0; + long finite = 0; + for (int j = (int)v.size() - 1; j >= 0; --j) + if (std::isfinite(v[(size_t)j])) { last = v[(size_t)j]; break; } + for (double x : v) + if (std::isfinite(x)) { sum += x; sumsq += x * x; ++finite; } + std::printf("%s line %d n=%d finite=%ld last=%.6g sum=%.6g sumsq=%.6g\n", + tag, i, (int)v.size(), finite, last, sum, sumsq); + } + std::fflush(stdout); +} + +int main(int argc, char** argv) { + const char* mode = argc > 1 ? argv[1] : "numeric"; + Display* display = XOpenDisplay(nullptr); + if (!display) { std::printf("NO DISPLAY\n"); return 1; } + int screen = DefaultScreen(display); + XID Xid = RootWindow(display, screen); + Window window = XCreateSimpleWindow(display, Xid, 100, 100, 800, 600, 1, + BlackPixel(display, screen), + WhitePixel(display, screen)); + std::string title = std::string(kName) + " - XFrame demo"; + XStoreName(display, window, title.c_str()); + XSelectInput(display, window, + ExposureMask | KeyPressMask | StructureNotifyMask | + ButtonPressMask | ButtonReleaseMask | PointerMotionMask); + Atom deleteWindowMessage = XInternAtom(display, "WM_DELETE_WINDOW", False); + XSetWMProtocols(display, window, &deleteWindowMessage, 1); + XMapWindow(display, window); + GC gc = DefaultGC(display, screen); + SStyle_Manager styles(display, window, screen, gc); + styles.add_style_ex("default", Srgb{225, 225, 225}, Srgb{120, 120, 120}, + Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, + "-misc-fixed-medium-r-normal--13-*"); + styles.set_active_style_byName("default"); + (void)screen; + // Construct with the seeded template series (250 bars). + IND_NAME widget(display, screen, window, gc, &styles, 20, 20, 720, 480); + widget.draw(); + + if (std::strcmp(mode, "numeric") == 0) { + dump_lines("template", widget); + std::string err; + if (!widget.load_csv(argv[2], err)) { + std::printf("csv_load FAIL %s\n", err.c_str()); + return 2; + } + std::printf("csv_load ok items=%d\n", (int)widget.series().size()); + widget.draw(); + dump_lines("csv", widget); + // set_series path with the second file. + std::string err2; + xframe::OHLCVSeries s2 = xframe::load_ohlcv_csv(argv[3], err2); + if (!err2.empty()) { std::printf("csvB_load FAIL %s\n", err2.c_str()); return 2; } + widget.set_series(s2); + std::printf("set_series ok items=%d\n", (int)widget.series().size()); + widget.draw(); + dump_lines("csvB", widget); + // A failed load must leave the series untouched. + std::string err3; + bool bad = widget.load_csv("/tmp/does-not-exist.csv", err3); + std::printf("badpath ok=%d err_set=%d items=%d\n", (int)!bad, + (int)!err3.empty(), (int)widget.series().size()); + if (bad) return 3; + dump_lines("after_badpath", widget); + // Clear: empty series, empty lines, draw must not crash. + widget.clear_series(); + std::printf("clear items=%d lines=%d\n", (int)widget.series().size(), + widget.line_count()); + widget.draw(); + dump_lines("clear", widget); + XFlush(display); + std::printf("NUMERIC DONE %s\n", kName); + XCloseDisplay(display); + return 0; + } + + if (std::strcmp(mode, "shot-csv") == 0) { + std::string err; + if (!widget.load_csv(argv[2], err)) { + std::fprintf(stderr, "csv: %s\n", err.c_str()); + return 2; + } + } + widget.draw(); + widget.on_button_press(400, 300, 1); + widget.on_button_release(400, 300, 1); + widget.on_motion(410, 300); + widget.on_key(XK_Right, ""); + widget.draw(); + XFlush(display); + std::printf("SHOT READY %s %s\n", kName, mode); + std::fflush(stdout); + // Stay alive until the driver closes the window. + while (true) { + XEvent ev; + XNextEvent(display, &ev); + if (ev.type == Expose) widget.draw(); + if (ev.type == ClientMessage) break; + } + XCloseDisplay(display); + return 0; +} diff --git a/widgets/tests/test_ind_csv.py b/widgets/tests/test_ind_csv.py new file mode 100644 index 0000000..9200b0b --- /dev/null +++ b/widgets/tests/test_ind_csv.py @@ -0,0 +1,392 @@ +#!/usr/bin/env python3 +"""Ind* indicator CSV test driver: proves every Ind* widget recomputes its +lines from real CSV data (not just the seeded template series). + +- Compiles + runs widgets/tests/csv_unit_test.cpp (parser unit tests). +- For each of the 250 Ind* widgets: builds widgets/tests/ind_csv_harness.cpp + against that widget's header and runs it in `numeric` mode under Xvfb: + template (250 seeded bars) -> load_csv(ohlcv_sample.csv, 30 rows) -> + set_series(ohlcv_sample_b.csv) -> failed load leaves data untouched -> + clear_series() (0 items, empty lines, draw must not crash). + The CSV checksums must differ from the template on at least one line, and + the B-series checksums must differ from the A-series. +- Screenshots a broad sample (every 8th widget + named extras): template + vs CSV renders must differ substantially and the CSV shot must be non-blank. +- Builds all 250 demo mains to catch regressions in existing demo code. +Re-derives every count from fresh artifacts each round; exits non-zero on +any failure. Attribution: XFrame. +""" +import glob +import os +import re +import subprocess +import sys +import time +from concurrent.futures import ThreadPoolExecutor + +from PIL import Image, ImageChops + +WIDGETS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +REPO = os.path.dirname(WIDGETS_DIR) +COMP = os.path.join(WIDGETS_DIR, "components") +TMP = "/tmp/ind-csv-shots" +BUILD = "/tmp/ind-csv-build" +CSV_A = os.path.join(REPO, "tests/data/ohlcv_sample.csv") +CSV_B = os.path.join(REPO, "tests/data/SPY_fake_long.csv") +CSV_B_ROWS = 1170 # verified: loader reads 1170 rows, 0 skipped +DISPLAY = ":94" +ENV = dict(os.environ, DISPLAY=DISPLAY) +NPROC = 8 + +NAMES = sorted(os.path.basename(d)[3:] if False else os.path.basename(d) + for d in glob.glob(os.path.join(COMP, "Ind*"))) +# NAMES are the directory names (IndSMA, ...); the class names match. +WIDGETS = NAMES + +os.makedirs(TMP, exist_ok=True) +os.makedirs(BUILD, exist_ok=True) +failures = [] +rows = [] + + +def run(*a, timeout=30, **k): + return subprocess.run(*a, capture_output=True, text=True, timeout=timeout, + env=ENV, **k) + + +def check(cond, msg): + if not cond: + failures.append(msg) + return cond + + +def nonbg(path): + im = Image.open(path).convert("L") + h = im.histogram() + modal = max(range(256), key=lambda v: h[v]) + return sum(c for v, c in enumerate(h) if abs(v - modal) > 10) + + +def diff(a, b): + ia = Image.open(a).convert("RGB") + ib = Image.open(b).convert("RGB") + if ia.size != ib.size: + ib = ib.resize(ia.size) + return sum(ImageChops.difference(ia, ib).convert("L").histogram()[31:]) + + +def line_accessor(name): + src = open(os.path.join(COMP, name, name + ".h")).read() + return "line_values" if "line_values(" in src else "line" + + +def shot(wid, path): + r = run(["import", "-window", str(wid), path], timeout=15) + return os.path.exists(path) and os.path.getsize(path) > 0 + + +_xvfb = None + + +def xvfb_alive(): + r = subprocess.run(["xdpyinfo", "-display", DISPLAY], + capture_output=True, timeout=5) + return r.returncode == 0 + + +def restart_xvfb(): + global _xvfb + if _xvfb is not None: + try: + _xvfb.terminate() + _xvfb.wait(timeout=5) + except Exception: + try: + _xvfb.kill() + except Exception: + pass + _xvfb = None + subprocess.run(["pkill", "-f", f"Xvfb {DISPLAY}"], capture_output=True, + timeout=10) + time.sleep(0.5) + try: + os.remove(f"/tmp/.X{DISPLAY[1:]}-lock") + except FileNotFoundError: + pass + _xvfb = subprocess.Popen(["Xvfb", DISPLAY, "-screen", "0", "1024x768x24"]) + for _ in range(20): + if xvfb_alive(): + return True + time.sleep(0.25) + return False + + +def ensure_xvfb(): + if not xvfb_alive(): + return restart_xvfb() + return True + + +def wait_window(name, proc, tries=50): + for _ in range(tries): + if proc.poll() is not None: + return None + rr = run(["xdotool", "search", "--name", f"{name} - XFrame demo"], + timeout=10) + if rr.stdout.strip(): + return rr.stdout.strip().split()[0] + time.sleep(0.2) + return None + + +sd = "/tmp/send_delete" +if not os.path.exists(sd): + subprocess.run(["cc", os.path.join(REPO, "widgets", "test-driver", + "send_delete.c"), "-lX11", "-o", sd], + capture_output=True, timeout=60) + + +def shoot_demo(binp, name, outpng, args, tag): + logout = open(os.path.join(TMP, f"{name}_{tag}.stdout"), "w") + logf = open(os.path.join(TMP, f"{name}_{tag}.stderr"), "wb") + p = subprocess.Popen([binp] + args, env=ENV, stdout=logout, stderr=logf) + wid = wait_window(name, p) + if wid is None: + rc = p.poll() + try: + p.wait(timeout=3) + except Exception: + p.kill() + p.wait(timeout=5) + logf.close(); logout.close() + return False, f"{tag}: no window rc={rc}", "" + time.sleep(0.4) + ok = shot(wid, outpng) + if p.poll() is None: + run([sd, str(wid)], timeout=10) + try: + p.wait(timeout=5) + except Exception: + p.kill(); p.wait(timeout=5) + logf.close(); logout.close() + if not ok: + return False, f"{tag}: screenshot failed", "" + return True, "", open(os.path.join(TMP, f"{name}_{tag}.stdout")).read() + + +# --- 0. parser unit test --- +unit_src = os.path.join(WIDGETS_DIR, "tests", "csv_unit_test.cpp") +unit_bin = os.path.join(TMP, "csv_unit_test") +r = subprocess.run(["g++", "-std=c++17", "-Wall", "-Wextra", "-I", COMP, + unit_src, "-o", unit_bin], + capture_output=True, text=True, timeout=120) +check(r.returncode == 0 and "warning:" not in r.stderr, + f"csv_unit_test compile failed/warnings: {r.stderr[:400]}") +if r.returncode == 0: + r2 = subprocess.run([unit_bin], capture_output=True, text=True, + timeout=30, cwd=REPO) + check(r2.returncode == 0, f"csv_unit_test rc={r2.returncode}: {r2.stdout}") + print("csv_unit_test:", r2.stdout.strip().splitlines()[-1] + if r2.stdout else "no output", flush=True) + +if not restart_xvfb(): + print("FATAL: Xvfb never answered", flush=True) + sys.exit(1) + +# --- 1. build one harness per widget (parallel) --- +HARNESS = os.path.join(WIDGETS_DIR, "tests", "ind_csv_harness.cpp") + + +def build_one(name): + hbin = os.path.join(BUILD, f"harness_{name}") + r = subprocess.run( + ["g++", "-std=c++17", "-O2", "-Wall", "-Wextra", "-I", COMP, + f"-DIND_HEADER={name}/{name}.h", f"-DIND_NAME={name}", + f"-DIND_LINE_FN={line_accessor(name)}", + HARNESS, "-lX11", "-o", hbin], + capture_output=True, text=True, timeout=300) + return name, r.returncode == 0 and "warning:" not in r.stderr, r.stderr[-500:] + + +print(f"building {len(WIDGETS)} harnesses ...", flush=True) +built = {} +with ThreadPoolExecutor(max_workers=NPROC) as ex: + for name, ok, err in ex.map(build_one, WIDGETS): + built[name] = ok + if not ok: + failures.append(f"{name}: harness build failed: {err}") +print(f"harnesses built: {sum(built.values())}/{len(WIDGETS)}", flush=True) + +LINE_RE = re.compile( + r"^(template|csv|csvB|after_badpath|clear) line (\d+) n=(\d+) finite=(\d+) " + r"last=(\S+) sum=(\S+) sumsq=(\S+)$", re.M) +HEAD_RE = re.compile(r"^(template|csv|csvB|after_badpath|clear) lines=(\d+) items=(\d+)$", re.M) + + +def parse_dump(out): + heads = {m.group(1): (int(m.group(2)), int(m.group(3))) + for m in HEAD_RE.finditer(out)} + lines = {} + for m in LINE_RE.finditer(out): + lines.setdefault(m.group(1), {})[int(m.group(2))] = ( + int(m.group(3)), int(m.group(4)), m.group(5), m.group(6), m.group(7)) + return heads, lines + + +def sig(lines_dict): + """Per-line checksum signature (n, finite, last, sum, sumsq).""" + return {k: v for k, v in lines_dict.items()} + + +def run_numeric(name): + hbin = os.path.join(BUILD, f"harness_{name}") + row = {"name": name, "build": "PASS" if built[name] else "FAIL", + "numeric": "FAIL", "notes": ""} + if not built[name]: + return row + try: + r = run([hbin, "numeric", CSV_A, CSV_B], timeout=60) + except subprocess.TimeoutExpired: + row["notes"] = "numeric run timed out" + failures.append(f"{name}: numeric timeout") + return row + out = r.stdout or "" + notes = [] + if r.returncode != 0: + notes.append(f"numeric rc={r.returncode}: {out[-300:]} {r.stderr[-200:]}") + failures.append(f"{name}: numeric rc={r.returncode}") + row["notes"] = "; ".join(notes) + return row + heads, lines = parse_dump(out) + ok = True + + def need(cond, msg): + nonlocal ok + if not cond: + ok = False + notes.append(msg) + + need(heads.get("template", (0, 0))[1] == 250, "template items != 250") + need(heads.get("csv", (0, 0))[1] == 30, "csv items != 30") + need(heads.get("csvB", (0, 0))[1] == CSV_B_ROWS, "csvB items != 1170") + need("csv_load ok items=30" in out, "csv_load not ok") + need(f"set_series ok items={CSV_B_ROWS}" in out, "set_series not ok") + need(f"badpath ok=1 err_set=1 items={CSV_B_ROWS}" in out, + "badpath did not preserve series") + need(heads.get("clear", (0, 0))[1] == 0, "clear items != 0") + need(all(v[0] == 0 for v in lines.get("clear", {}).values()), + "clear lines not empty") + need("NUMERIC DONE" in out, "numeric did not finish") + t, c, b = lines.get("template", {}), lines.get("csv", {}), lines.get("csvB", {}) + ab = lines.get("after_badpath", {}) + need(t.keys() == c.keys() == b.keys() and len(t) >= 1, "line sets differ") + need(c != t, "CSV lines identical to template (no recompute?)") + need(b != c, "csvB lines identical to csv (set_series no-op?)") + # The 1170-row B series must satisfy every warm-up: at least one line + # carries finite values (a 30-row file leaves long-period indicators + # all-NaN, which is correct behaviour, not a failure). + need(any(v[1] > 0 for v in b.values()), + "csvB lines all-NaN (warm-up not satisfied?)") + need(ab == b, "series changed after failed load") + row["numeric"] = "PASS" if ok else "FAIL" + if not ok: + failures.append(f"{name}: numeric: {'; '.join(notes)}") + row["notes"] = "; ".join(notes) + return row + + +print("running numeric checks ...", flush=True) +with ThreadPoolExecutor(max_workers=NPROC) as ex: + for row in ex.map(run_numeric, WIDGETS): + rows.append(row) +npass = sum(1 for r in rows if r["numeric"] == "PASS") +print(f"numeric: {npass}/{len(WIDGETS)} PASS", flush=True) +for r in rows: + if r["numeric"] != "PASS": + print(" FAIL", r["name"], r["notes"], flush=True) + +# --- 2. screenshots: broad sample --- +SAMPLE = sorted(set(WIDGETS[::8]) | { + "IndBollingerBands", "IndMACD", "IndRSI", "IndSMA", "IndEMA", + "IndGuppyMMA", "IndADX", "IndStochastic", "IndVWAP", "IndIchimoku", +} & set(WIDGETS)) +print(f"screenshots: sampling {len(SAMPLE)} widgets ...", flush=True) +for name in SAMPLE: + row = next(r for r in rows if r["name"] == name) + row["shot"] = "FAIL" + hbin = os.path.join(BUILD, f"harness_{name}") + if not built.get(name): + row["notes"] += "; shot skipped: harness did not build" + failures.append(f"{name}: shot skipped: harness did not build") + continue + tmpl = os.path.join(TMP, name + "_template.png") + ok, note, _ = shoot_demo(hbin, name, tmpl, ["shot-template"], "template") + if not ok: + ensure_xvfb() + ok, note, _ = shoot_demo(hbin, name, tmpl, ["shot-template"], "template") + if not ok: + failures.append(f"{name}: template shot: {note}") + row["notes"] += f"; template shot: {note}" + continue + csvshot = os.path.join(TMP, name + "_csv.png") + ok, note, _ = shoot_demo(hbin, name, csvshot, ["shot-csv", CSV_A], "csv") + if not ok: + ensure_xvfb() + ok, note, _ = shoot_demo(hbin, name, csvshot, ["shot-csv", CSV_A], "csv") + if not ok: + failures.append(f"{name}: csv shot: {note}") + row["notes"] += f"; csv shot: {note}" + continue + nb = nonbg(csvshot) + d = diff(tmpl, csvshot) + row["shot_diff"] = d + row["shot_nonbg"] = nb + if nb > 20 and d > 5000: + row["shot"] = "PASS" + else: + failures.append(f"{name}: shot diff={d} nonbg={nb}") + row["notes"] += f"; shot diff={d} nonbg={nb}" +spass = sum(1 for r in rows if r.get("shot") == "PASS") +print(f"screenshots: {spass}/{len(SAMPLE)} PASS", flush=True) + +# --- 3. build all demo mains (regression: existing demo code still compiles) --- +print("building 250 demo mains ...", flush=True) + + +def build_main(name): + src = os.path.join(COMP, name, f"main_{name}.cpp") + out = os.path.join(BUILD, f"main_{name}") + r = subprocess.run( + ["g++", "-std=c++17", "-O2", "-Wall", "-Wextra", + "-I", os.path.join(COMP, name), "-I", COMP, + src, "-lX11", "-o", out], + capture_output=True, text=True, timeout=300) + return name, r.returncode == 0, r.stderr[-500:] + + +mbad = [] +with ThreadPoolExecutor(max_workers=NPROC) as ex: + for name, ok, err in ex.map(build_main, WIDGETS): + if not ok: + mbad.append(name) + failures.append(f"{name}: demo main build failed: {err}") +print(f"demo mains built: {len(WIDGETS) - len(mbad)}/{len(WIDGETS)}", flush=True) + +# --- report --- +with open(os.path.join(TMP, "ind_csv_report.tsv"), "w") as f: + f.write("name\tbuild\tnumeric\tshot\tshot_diff\tshot_nonbg\tnotes\n") + for r in rows: + f.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( + r["name"], r.get("build", ""), r.get("numeric", ""), + r.get("shot", ""), r.get("shot_diff", ""), + r.get("shot_nonbg", ""), r.get("notes", "").replace("\t", " "))) +print("=" * 60) +print(f"IND CSV: harnesses {sum(built.values())}/{len(WIDGETS)}, " + f"numeric {npass}/{len(WIDGETS)}, shots {spass}/{len(SAMPLE)}, " + f"mains {len(WIDGETS) - len(mbad)}/{len(WIDGETS)}") +if failures: + print(f"FAILURES ({len(failures)}):") + for msg in failures[:40]: + print(" -", msg) + sys.exit(1) +print("IND CSV: ALL PASS")