[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"indicator-rsi_safe-en":3},"# RSI Safe (RSI_SAFE)\n\n> Checked StratForge C++23 API, calculation and warm-up behavior.\n\n**Route**: `\u002Findicators\u002Frsi_safe\u002F`\n\nSafe division handles a zero average loss; it does not detect price\u002FRSI divergence. Output is on the 0–100 RSI scale with default safety values, not a return percentage.\n\n`change = close[t] - close[t - lookback]`\n\n`gain = max(change, 0)`; `loss = max(-change, 0)`\n\n`average[t] = (average[t - 1] * (period - 1) + value[t]) \u002F period`\n\n`RS = average_gain \u002F average_loss`; `RSI = 100 - 100 \u002F (1 + RS)`\n\n## Parameters\n\n- `period = 14`\n- `movav = stratforge::RsiMovAv::Smoothed` (`Simple`, `Exponential`)\n- `safehigh = 100.0`\n- `safelow = 50.0`\n- `lookback = 1`\n\n`RSI_Safe`: `safediv = true`; `RSI`: `safediv = false`.\n`upperband` \u002F `lowerband`: 70 \u002F 30 — Chart thresholds, not constructor arguments.\n\n## Worked example\n\nFor period = 3 and lookback = 1, closes [10, 11, 10, 11, 13] give changes [1, -1, 1, 2]. Initial mean gain = 2\u002F3 and mean loss = 1\u002F3, so RSI on bar 4 = 66.666667. On bar 5, smoothed gain = 10\u002F9 and loss = 2\u002F9, so RSI = 83.333333. The first three bars produce NaN. Warm-up is period + lookback (15 bars by default).\n\nWith default safety values, a rising series with zero losses gives 100, a falling series with zero gains gives 0, and a flat series (0\u002F0) gives 50. These branches apply only after warm-up. Custom safehigh\u002Fsafelow replace the zero-denominator results; they are RSI values, not denominator epsilons.\n\nUse finite inputs and positive periods\u002Flookback. This revision normalizes zero period\u002Flookback to 1; it does not validate custom safety values or promise meaningful output for non-finite prices. These illustrative calculations are not trading signals or evidence of returns.\n\n## C++23 API — StratForge\n\n```cpp\n#include \u003Cstratforge\u002Findicators\u002Frsi.hpp>\n#include \u003Ccassert>\n#include \u003Ccmath>\n#include \u003Ciomanip>\n#include \u003Ciostream>\n\nint main() {\n    stratforge::Line\u003Cdouble> close, rising, falling, flat;\n    stratforge::RSI_Safe rsi(close, 3);\n    stratforge::RSI_Safe up(rising, 3), down(falling, 3), neutral(flat, 3);\n    assert(rsi.minimum_period() == 4);\n    std::cout \u003C\u003C std::fixed \u003C\u003C std::setprecision(6);\n    for (double price : {10.0, 11.0, 10.0, 11.0, 13.0}) {\n        close.forward(price);\n        rsi.next();\n        if (close.size() \u003C 4) assert(std::isnan(rsi[0]));\n        else std::cout \u003C\u003C rsi[0] \u003C\u003C \" \";\n    }\n    assert(std::abs(rsi.line()[-1] - 66.666666667) \u003C 1e-9);\n    assert(std::abs(rsi[0] - 83.333333333) \u003C 1e-9);\n    for (int i = 0; i \u003C 4; ++i) {\n        rising.forward(10.0 + i);\n        falling.forward(10.0 - i);\n        flat.forward(10.0);\n        up.next();\n        down.next();\n        neutral.next();\n    }\n    assert(up[0] == 100.0 && down[0] == 0.0 && neutral[0] == 50.0);\n    std::cout \u003C\u003C up[0] \u003C\u003C \" \" \u003C\u003C down[0] \u003C\u003C \" \" \u003C\u003C neutral[0] \u003C\u003C \"\\n\";\n}\n```\n\n## Reproduce\n\nStratForge `d25404dcf2c3842ba304ddc60ac19cfec1f8aa37` (2026-08-28); GCC 14, C++23; scalar build, no xsimd dependency.\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002FStratCraftsAI\u002FStratForge.git StratForge\ngit -C StratForge checkout --detach d25404dcf2c3842ba304ddc60ac19cfec1f8aa37\ng++-14 -std=c++23 -O2 -Wall -Wextra -pedantic -IStratForge\u002Finclude example.cpp -o example\n.\u002Fexample\n```\n\n`example.cpp`: C++23 API. stdout:\n\n```text\n66.666667 83.333333 100.000000 0.000000 50.000000\n```\n\n## Sources\n\n- [StratForge rsi.hpp](https:\u002F\u002Fgithub.com\u002FStratCraftsAI\u002FStratForge\u002Fblob\u002Fd25404dcf2c3842ba304ddc60ac19cfec1f8aa37\u002Finclude\u002Fstratforge\u002Findicators\u002Frsi.hpp)\n- [StratForge Line](https:\u002F\u002Fgithub.com\u002FStratCraftsAI\u002FStratForge\u002Fblob\u002Fd25404dcf2c3842ba304ddc60ac19cfec1f8aa37\u002Finclude\u002Fstratforge\u002Fcore\u002Fline.hpp)\n"]