mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-20 11:38:05 +00:00
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
Deep review of all indicator categories verified .md headers against .cs WarmupPeriod, parameters, inputs, and outputs. Fixes include warmup corrections, parameter documentation, output type accuracy, and Pine Script alignment.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
| ---------------- | -------------------------------- |
|
||||
| **Category** | Reversal |
|
||||
| **Inputs** | OHLCV bar (TBar) |
|
||||
| **Parameters** | `period` (default DefaultPeriod), `multiplier` (default DefaultMultiplier) |
|
||||
| **Parameters** | `period` (default 22), `multiplier` (default 3.0) |
|
||||
| **Outputs** | Single series (Chandelier) |
|
||||
| **Output range** | Varies (see docs) |
|
||||
| **Warmup** | `period + 1` bars |
|
||||
@@ -12,7 +12,7 @@
|
||||
### TL;DR
|
||||
|
||||
- The Chandelier Exit computes ATR-based trailing stop levels that hang from the highest high (for longs) or rise from the lowest low (for shorts) ov...
|
||||
- Parameterized by `period` (default defaultperiod), `multiplier` (default defaultmultiplier).
|
||||
- Parameterized by `period` (default 22), `multiplier` (default 3.0).
|
||||
- Output range: Varies (see docs).
|
||||
- Requires `period + 1` bars of warmup before first valid output (IsHot = true).
|
||||
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Chandelier Exit (CHANDELIER)", "CHANDELIER", overlay=true)
|
||||
|
||||
//@function Chandelier Exit — ATR-based trailing stops that hang from the highest high
|
||||
// (ExitLong) or rise from the lowest low (ExitShort) over a lookback period.
|
||||
// Uses SMA-seeded Wilder's RMA for ATR, matching Skender/TradingView convention.
|
||||
//@param period Lookback for ATR and rolling HH/LL (default 22)
|
||||
//@param multiplier ATR scaling factor (default 3.0)
|
||||
//@returns [exitLong, exitShort] — two overlay stop levels
|
||||
//@reference Charles Le Beau; Alexander Elder, "Come Into My Trading Room" (2002)
|
||||
//@optimized O(1) per bar using ta.rma, ta.highest, ta.lowest
|
||||
chandelier(simple int period = 22, simple float multiplier = 3.0) =>
|
||||
if period < 1
|
||||
runtime.error("Period must be >= 1")
|
||||
if multiplier <= 0
|
||||
runtime.error("Multiplier must be > 0")
|
||||
|
||||
// True Range
|
||||
float tr = na(close[1]) ? high - low : math.max(high - low, math.max(math.abs(high - close[1]), math.abs(low - close[1])))
|
||||
|
||||
// Wilder's ATR (RMA = EMA with alpha = 1/period, SMA-seeded)
|
||||
float atr = ta.rma(tr, period)
|
||||
|
||||
// Rolling extremes over the lookback window
|
||||
float hh = ta.highest(high, period)
|
||||
float ll = ta.lowest(low, period)
|
||||
|
||||
// Chandelier exits
|
||||
float exit_long = hh - multiplier * atr
|
||||
float exit_short = ll + multiplier * atr
|
||||
|
||||
[exit_long, exit_short]
|
||||
|
||||
// ── Inputs ──
|
||||
int i_period = input.int(22, "Period", minval=1)
|
||||
float i_multiplier = input.float(3.0, "Multiplier", minval=0.01, step=0.1)
|
||||
|
||||
// ── Calculation ──
|
||||
[exit_long, exit_short] = chandelier(i_period, i_multiplier)
|
||||
|
||||
// ── Plot ──
|
||||
plot(exit_long, "Exit Long", color=color.green, linewidth=2)
|
||||
plot(exit_short, "Exit Short", color=color.red, linewidth=2)
|
||||
@@ -4,7 +4,7 @@
|
||||
| ---------------- | -------------------------------- |
|
||||
| **Category** | Reversal |
|
||||
| **Inputs** | OHLCV bar (TBar) |
|
||||
| **Parameters** | `atrPeriod` (default DefaultAtrPeriod), `multiplier` (default DefaultMultiplier), `stopPeriod` (default DefaultStopPeriod) |
|
||||
| **Parameters** | `atrPeriod` (default 10), `multiplier` (default 1.0), `stopPeriod` (default 9) |
|
||||
| **Outputs** | Single series (Ckstop) |
|
||||
| **Output range** | Varies (see docs) |
|
||||
| **Warmup** | `atrPeriod + stopPeriod` bars |
|
||||
@@ -12,7 +12,7 @@
|
||||
### TL;DR
|
||||
|
||||
- The Chande Kroll Stop computes adaptive trailing stop levels using ATR-smoothed volatility envelopes around rolling extremes.
|
||||
- Parameterized by `atrperiod` (default defaultatrperiod), `multiplier` (default defaultmultiplier), `stopperiod` (default defaultstopperiod).
|
||||
- Parameterized by `atrPeriod` (default 10), `multiplier` (default 1.0), `stopPeriod` (default 9).
|
||||
- Output range: Varies (see docs).
|
||||
- Requires `atrPeriod + stopPeriod` bars of warmup before first valid output (IsHot = true).
|
||||
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Chande Kroll Stop (CKSTOP)", "CKSTOP", overlay=true)
|
||||
|
||||
//@function Chande Kroll Stop — adaptive trailing stop using ATR-smoothed volatility
|
||||
// envelopes around rolling extremes, then smoothed through a second window.
|
||||
// Stage 1: first_high_stop = HH(p) - m*ATR, first_low_stop = LL(p) + m*ATR
|
||||
// Stage 2: StopShort = highest(first_high_stop, x), StopLong = lowest(first_low_stop, x)
|
||||
//@param atr_period ATR and first-stop extreme lookback (default 10)
|
||||
//@param multiplier ATR scaling factor (default 1.0)
|
||||
//@param stop_period Second smoothing window (default 9)
|
||||
//@returns [stop_long, stop_short] — two overlay stop levels
|
||||
//@reference Chande & Kroll, "The New Technical Trader" (1994)
|
||||
//@optimized O(1) per bar using ta.rma, ta.highest, ta.lowest
|
||||
ckstop(simple int atr_period = 10, simple float multiplier = 1.0, simple int stop_period = 9) =>
|
||||
if atr_period < 1
|
||||
runtime.error("ATR period must be >= 1")
|
||||
if multiplier <= 0
|
||||
runtime.error("Multiplier must be > 0")
|
||||
if stop_period < 1
|
||||
runtime.error("Stop period must be >= 1")
|
||||
|
||||
// True Range
|
||||
float tr = na(close[1]) ? high - low : math.max(high - low, math.max(math.abs(high - close[1]), math.abs(low - close[1])))
|
||||
|
||||
// ATR via Wilder's RMA
|
||||
float atr = ta.rma(tr, atr_period)
|
||||
|
||||
// Stage 1: First stops (volatility envelope)
|
||||
float hh = ta.highest(high, atr_period)
|
||||
float ll = ta.lowest(low, atr_period)
|
||||
float first_high_stop = hh - multiplier * atr
|
||||
float first_low_stop = ll + multiplier * atr
|
||||
|
||||
// Stage 2: Smoothed stops over stop_period
|
||||
float stop_short = ta.highest(first_high_stop, stop_period)
|
||||
float stop_long = ta.lowest(first_low_stop, stop_period)
|
||||
|
||||
[stop_long, stop_short]
|
||||
|
||||
// ── Inputs ──
|
||||
int i_atr_period = input.int(10, "ATR Period", minval=1)
|
||||
float i_multiplier = input.float(1.0, "Multiplier", minval=0.01, step=0.1)
|
||||
int i_stop_period = input.int(9, "Stop Period", minval=1)
|
||||
|
||||
// ── Calculation ──
|
||||
[stop_long, stop_short] = ckstop(i_atr_period, i_multiplier, i_stop_period)
|
||||
|
||||
// ── Plot ──
|
||||
plot(stop_long, "Stop Long", color=color.green, linewidth=2)
|
||||
plot(stop_short, "Stop Short", color=color.red, linewidth=2)
|
||||
@@ -1,6 +1,6 @@
|
||||
// FRACTALS: Williams Fractals
|
||||
// Five-bar pattern identifying local highs (up fractals) and local lows (down fractals).
|
||||
// Created by Larry Williams (1995, "Trading Chaos").
|
||||
// Created by Bill Williams (1995, "Trading Chaos").
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
| ---------------- | -------------------------------- |
|
||||
| **Category** | Reversal |
|
||||
| **Inputs** | OHLCV bar (TBar) |
|
||||
| **Parameters** | `afStart` (default DefaultAfStart), `afIncrement` (default DefaultAfIncrement), `afMax` (default DefaultAfMax) |
|
||||
| **Parameters** | `afStart` (default 0.02), `afIncrement` (default 0.02), `afMax` (default 0.20) |
|
||||
| **Outputs** | Single series (Psar) |
|
||||
| **Output range** | Varies (see docs) |
|
||||
| **Warmup** | `1` bars |
|
||||
@@ -12,7 +12,7 @@
|
||||
### TL;DR
|
||||
|
||||
- The Parabolic Stop And Reverse (PSAR) is a trend-following overlay indicator created by J.
|
||||
- Parameterized by `afstart` (default defaultafstart), `afincrement` (default defaultafincrement), `afmax` (default defaultafmax).
|
||||
- Parameterized by `afStart` (default 0.02), `afIncrement` (default 0.02), `afMax` (default 0.20).
|
||||
- Output range: Varies (see docs).
|
||||
- Requires `1` bars of warmup before first valid output (IsHot = true).
|
||||
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Parabolic SAR Extended (SAREXT)", "SAREXT", overlay=true)
|
||||
|
||||
//@function Parabolic SAR Extended — asymmetric PSAR with separate long/short AF parameters,
|
||||
// auto-detect or forced initial direction, and an offset applied on reversal.
|
||||
// Output is sign-encoded: positive SAR = long mode, negative SAR = short mode.
|
||||
//@param start_value Initial direction: >0 force long, <0 force short, 0 auto-detect from DM
|
||||
//@param offset_on_reverse Gap added to SAR on reversal (default 0)
|
||||
//@param af_init_long Initial AF for long positions (default 0.02)
|
||||
//@param af_long AF increment per new EP in long (default 0.02)
|
||||
//@param af_max_long Maximum AF for long (default 0.20)
|
||||
//@param af_init_short Initial AF for short positions (default 0.02)
|
||||
//@param af_short AF increment per new EP in short (default 0.02)
|
||||
//@param af_max_short Maximum AF for short (default 0.20)
|
||||
//@returns Sign-encoded SAR value (positive = long, negative = short)
|
||||
//@reference J. Welles Wilder Jr., "New Concepts in Technical Trading Systems" (1978)
|
||||
//@optimized O(1) per bar, state-machine with asymmetric acceleration factors
|
||||
sarext(simple float start_value = 0.0, simple float offset_on_reverse = 0.0,
|
||||
simple float af_init_long = 0.02, simple float af_long = 0.02, simple float af_max_long = 0.20,
|
||||
simple float af_init_short = 0.02, simple float af_short = 0.02, simple float af_max_short = 0.20) =>
|
||||
if af_init_long <= 0 or af_long <= 0 or af_max_long <= af_init_long
|
||||
runtime.error("Long AF parameters invalid")
|
||||
if af_init_short <= 0 or af_short <= 0 or af_max_short <= af_init_short
|
||||
runtime.error("Short AF parameters invalid")
|
||||
if offset_on_reverse < 0
|
||||
runtime.error("Offset must be >= 0")
|
||||
|
||||
var bool is_long = true
|
||||
var float sar = low
|
||||
var float ep = high
|
||||
var float af = af_init_long
|
||||
|
||||
if bar_index == 0
|
||||
// Bar 0: collect first bar data
|
||||
is_long := true
|
||||
sar := high
|
||||
ep := low
|
||||
af := af_init_short
|
||||
float(na)
|
||||
else if bar_index == 1
|
||||
// Bar 1: determine initial direction
|
||||
if start_value > 0
|
||||
is_long := true
|
||||
sar := math.min(low[1], low)
|
||||
ep := math.max(high[1], high)
|
||||
af := af_init_long
|
||||
else if start_value < 0
|
||||
is_long := false
|
||||
sar := math.max(high[1], high)
|
||||
ep := math.min(low[1], low)
|
||||
af := af_init_short
|
||||
else
|
||||
// Auto-detect from DM
|
||||
float plus_dm = high - high[1]
|
||||
float minus_dm = low[1] - low
|
||||
if plus_dm > minus_dm and plus_dm > 0
|
||||
is_long := true
|
||||
sar := math.min(low[1], low)
|
||||
ep := math.max(high[1], high)
|
||||
af := af_init_long
|
||||
else
|
||||
is_long := false
|
||||
sar := math.max(high[1], high)
|
||||
ep := math.min(low[1], low)
|
||||
af := af_init_short
|
||||
is_long ? sar : -sar
|
||||
else
|
||||
// Bar 2+: standard SAR state machine with asymmetric AF
|
||||
float new_sar = sar + af * (ep - sar)
|
||||
if is_long
|
||||
new_sar := math.min(new_sar, low[1])
|
||||
if bar_index > 1
|
||||
new_sar := math.min(new_sar, low[2])
|
||||
if low <= new_sar
|
||||
// Reverse to short
|
||||
is_long := false
|
||||
new_sar := ep + offset_on_reverse
|
||||
ep := low
|
||||
af := af_init_short
|
||||
else
|
||||
if high > ep
|
||||
ep := high
|
||||
af := math.min(af + af_long, af_max_long)
|
||||
else
|
||||
new_sar := math.max(new_sar, high[1])
|
||||
if bar_index > 1
|
||||
new_sar := math.max(new_sar, high[2])
|
||||
if high >= new_sar
|
||||
// Reverse to long
|
||||
is_long := true
|
||||
new_sar := ep - offset_on_reverse
|
||||
ep := high
|
||||
af := af_init_long
|
||||
else
|
||||
if low < ep
|
||||
ep := low
|
||||
af := math.min(af + af_short, af_max_short)
|
||||
sar := new_sar
|
||||
is_long ? sar : -sar
|
||||
|
||||
// ── Inputs ──
|
||||
float i_start = input.float(0.0, "Start Value (0=auto)")
|
||||
float i_offset = input.float(0.0, "Offset on Reverse", minval=0)
|
||||
float i_af_init_long = input.float(0.02, "AF Init Long", minval=0.001, step=0.001)
|
||||
float i_af_long = input.float(0.02, "AF Long", minval=0.001, step=0.001)
|
||||
float i_af_max_long = input.float(0.20, "AF Max Long", minval=0.01, step=0.01)
|
||||
float i_af_init_short = input.float(0.02, "AF Init Short", minval=0.001, step=0.001)
|
||||
float i_af_short = input.float(0.02, "AF Short", minval=0.001, step=0.001)
|
||||
float i_af_max_short = input.float(0.20, "AF Max Short", minval=0.01, step=0.01)
|
||||
|
||||
// ── Calculation ──
|
||||
float result = sarext(i_start, i_offset, i_af_init_long, i_af_long, i_af_max_long,
|
||||
i_af_init_short, i_af_short, i_af_max_short)
|
||||
|
||||
float sar_val = math.abs(nz(result))
|
||||
bool is_long = nz(result) > 0
|
||||
float sar_above = not is_long ? sar_val : na
|
||||
float sar_below = is_long ? sar_val : na
|
||||
|
||||
// ── Plot ──
|
||||
plot(sar_above, "SAREXT Above", color=color.red, style=plot.style_linebr, linewidth=2)
|
||||
plot(sar_below, "SAREXT Below", color=color.green, style=plot.style_linebr, linewidth=2)
|
||||
@@ -4,7 +4,7 @@
|
||||
| ---------------- | -------------------------------- |
|
||||
| **Category** | Reversal |
|
||||
| **Inputs** | OHLCV bar (TBar) |
|
||||
| **Parameters** | `lookback` (default DefaultLookback) |
|
||||
| **Parameters** | `lookback` (default 5) |
|
||||
| **Outputs** | Single series (Swings) |
|
||||
| **Output range** | Varies (see docs) |
|
||||
| **Warmup** | 1 bar |
|
||||
@@ -12,7 +12,7 @@
|
||||
### TL;DR
|
||||
|
||||
- Swing High/Low detection identifies local price extremes using a configurable lookback window.
|
||||
- Parameterized by `lookback` (default defaultlookback).
|
||||
- Parameterized by `lookback` (default 5).
|
||||
- Output range: Varies (see docs).
|
||||
- Requires 1 bar of warmup before first valid output (IsHot = true).
|
||||
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
|
||||
|
||||
Reference in New Issue
Block a user