mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 12:08:05 +00:00
SIMD Refactor: Merge simd-dev into dev (#55)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat> Co-authored-by: Warp <agent@warp.dev>
This commit is contained in:
co-authored by
Claude Opus 4.5
aider
Warp
parent
5bcdf8d614
commit
86fe32a682
@@ -0,0 +1,76 @@
|
||||
# Reversals
|
||||
|
||||
> "Pivot point is hypothesis, not prophecy. Mathematics identifies levels where crowd psychology may shift. Market decides whether to respect calculation or ignore it entirely."
|
||||
|
||||
Tools indicating potential reversals, support/resistance, or pivot points. These indicators identify price levels where trend exhaustion or continuation decisions occur.
|
||||
|
||||
## Implementation Status
|
||||
|
||||
| Indicator | Full Name | Status | Description |
|
||||
| :--- | :--- | :---: | :--- |
|
||||
| FRACTALS | Williams Fractals | 📋 | Five-bar pattern identifying local peaks/troughs; marks support/resistance levels. |
|
||||
| PIVOT | Pivot Points (Classic) | 📋 | Standard floor trader pivots with 7 levels (PP, R1-R3, S1-S3). |
|
||||
| PIVOTCAM | Camarilla Pivot Points | 📋 | Mean-reversion pivots with 9 levels; R3/S3 are key reversal zones. |
|
||||
| PIVOTDEM | DeMark Pivot Points | 📋 | Minimalist trend-following pivots with only 3 levels and conditional logic. |
|
||||
| PIVOTEXT | Extended Traditional Pivots | 📋 | Extended pivots with 11 levels (R1-R5, S1-S5) for volatile markets. |
|
||||
| PIVOTFIB | Fibonacci Pivot Points | 📋 | Fibonacci-ratio based pivots; Golden Ratio (61.8%) at R2/S2. |
|
||||
| PIVOTWOOD | Woodie's Pivot Points | 📋 | Weighted close pivots (2× close weight) for intraday trading. |
|
||||
| PSAR | Parabolic Stop And Reverse | 📋 | Trailing stop indicator that accelerates with trend; provides entry/exit signals via SAR dots. |
|
||||
| SWINGS | Swing High/Low Detection | 📋 | Identifies significant price reversals and swing points using configurable lookback. |
|
||||
|
||||
## Selection Guide
|
||||
|
||||
**For intraday trading:** Classic PIVOT provides baseline levels. PIVOTWOOD emphasizes closing price for day-session context. PIVOTCAM targets mean-reversion at R3/S3 zones.
|
||||
|
||||
**For swing trading:** PIVOTFIB uses Fibonacci ratios aligned with retracement analysis. PIVOTEXT provides extended levels for multi-day moves. FRACTALS marks structural highs/lows.
|
||||
|
||||
**For trend-following:** PSAR provides trailing stop with acceleration. PIVOTDEM uses conditional logic based on prior bar relationship. SWINGS identifies trend reversal points.
|
||||
|
||||
**For volatile markets:** PIVOTEXT with 11 levels captures extreme moves. PIVOTCAM's outer levels (R4/S4) act as volatility breakout zones.
|
||||
|
||||
## Pivot Point Comparison
|
||||
|
||||
| System | Levels | Formula Basis | Trading Style |
|
||||
| :--- | :---: | :--- | :--- |
|
||||
| Classic | 7 | (H+L+C)/3 | General purpose |
|
||||
| Woodie | 7 | (H+L+2C)/4 | Intraday, close-weighted |
|
||||
| Camarilla | 9 | Range × multipliers | Mean-reversion |
|
||||
| DeMark | 3 | Conditional on O/C relationship | Trend-following |
|
||||
| Fibonacci | 7 | PP ± (H-L) × Fib ratios | Retracement alignment |
|
||||
| Extended | 11 | Classic + outer levels | High volatility |
|
||||
|
||||
## Pivot Level Calculations
|
||||
|
||||
| Level | Classic | Woodie | Camarilla |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| R4 | — | — | C + (H-L) × 1.5/2 |
|
||||
| R3 | 2×PP - 2×L | — | C + (H-L) × 1.25/4 |
|
||||
| R2 | PP + (H-L) | PP + (H-L) | C + (H-L) × 1.1/6 |
|
||||
| R1 | 2×PP - L | 2×PP - L | C + (H-L) × 1.1/12 |
|
||||
| PP | (H+L+C)/3 | (H+L+2C)/4 | — |
|
||||
| S1 | 2×PP - H | 2×PP - H | C - (H-L) × 1.1/12 |
|
||||
| S2 | PP - (H-L) | PP - (H-L) | C - (H-L) × 1.1/6 |
|
||||
| S3 | 2×PP - 2×H | — | C - (H-L) × 1.25/4 |
|
||||
| S4 | — | — | C - (H-L) × 1.5/2 |
|
||||
|
||||
## Reversal Pattern Types
|
||||
|
||||
| Pattern | Indicator | Bars Required | Signal Type |
|
||||
| :--- | :--- | :---: | :--- |
|
||||
| Williams Fractal Up | FRACTALS | 5 | Resistance marked at middle high |
|
||||
| Williams Fractal Down | FRACTALS | 5 | Support marked at middle low |
|
||||
| Swing High | SWINGS | Configurable | Local maximum confirmation |
|
||||
| Swing Low | SWINGS | Configurable | Local minimum confirmation |
|
||||
| SAR Flip | PSAR | 1 | Trend reversal signal |
|
||||
|
||||
## PSAR Mechanics
|
||||
|
||||
Parabolic SAR uses acceleration factor that increases with each new extreme:
|
||||
|
||||
| Parameter | Default | Range | Effect |
|
||||
| :--- | :---: | :--- | :--- |
|
||||
| Initial AF | 0.02 | 0.01-0.05 | Starting sensitivity |
|
||||
| AF Step | 0.02 | 0.01-0.05 | Acceleration rate |
|
||||
| Max AF | 0.20 | 0.10-0.30 | Maximum sensitivity |
|
||||
|
||||
Higher AF values create tighter stops (more whipsaws, earlier exits). Lower AF values create wider stops (fewer signals, later exits).
|
||||
@@ -0,0 +1,35 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Williams Fractals", "FRACTALS", overlay=true)
|
||||
|
||||
//@function Detects Williams Fractal patterns (5-bar pattern)
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/fractals.md
|
||||
//@returns Tuple [up_fractal, down_fractal] with fractal values (na if no fractal)
|
||||
fractals() =>
|
||||
bool is_up_fractal = false
|
||||
bool is_down_fractal = false
|
||||
|
||||
if bar_index >= 4
|
||||
is_up_fractal := high[2] > high[4] and high[2] > high[3] and high[2] > high[1] and high[2] > high[0]
|
||||
is_down_fractal := low[2] < low[4] and low[2] < low[3] and low[2] < low[1] and low[2] < low[0]
|
||||
|
||||
float up_fractal_value = is_up_fractal ? high[2] : na
|
||||
float down_fractal_value = is_down_fractal ? low[2] : na
|
||||
|
||||
[up_fractal_value, down_fractal_value]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_show_up = input.bool(true, "Show Up Fractals", tooltip="Display bearish fractals (resistance)")
|
||||
i_show_down = input.bool(true, "Show Down Fractals", tooltip="Display bullish fractals (support)")
|
||||
i_color_up = input.color(color.red, "Up Fractal Color")
|
||||
i_color_down = input.color(color.green, "Down Fractal Color")
|
||||
|
||||
// Calculation
|
||||
[up_fractal, down_fractal] = fractals()
|
||||
|
||||
// Plot fractal markers
|
||||
plotshape(i_show_up and not na(up_fractal) ? up_fractal : na, "Up Fractal", style=shape.triangledown, location=location.absolute, color=i_color_up, size=size.small, offset=-2)
|
||||
plotshape(i_show_down and not na(down_fractal) ? down_fractal : na, "Down Fractal", style=shape.triangleup, location=location.absolute, color=i_color_down, size=size.small, offset=-2)
|
||||
@@ -0,0 +1,50 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Pivot Points (Classic)", "PIVOT", overlay=true)
|
||||
|
||||
//@function Calculates classic/standard/floor pivot points
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/pivot.md
|
||||
//@param tf Timeframe for pivot calculation ("D", "W", "M")
|
||||
//@returns Tuple [pp, r1, r2, r3, s1, s2, s3] with pivot levels
|
||||
//@references Floor traders, standard pivot point formula
|
||||
pivot(simple string tf) =>
|
||||
[hi, lo, cl] = request.security(syminfo.tickerid, tf, [high[1], low[1], close[1]], lookahead=barmerge.lookahead_on)
|
||||
if na(hi) or na(lo) or na(cl)
|
||||
[na, na, na, na, na, na, na]
|
||||
else
|
||||
float pp = (hi + lo + cl) / 3.0
|
||||
float r1 = 2.0 * pp - lo
|
||||
float s1 = 2.0 * pp - hi
|
||||
float r2 = pp + (hi - lo)
|
||||
float s2 = pp - (hi - lo)
|
||||
float r3 = hi + 2.0 * (pp - lo)
|
||||
float s3 = lo - 2.0 * (hi - pp)
|
||||
[pp, r1, r2, r3, s1, s2, s3]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_timeframe = input.timeframe("D", "Pivot Timeframe", options=["D", "W", "M"])
|
||||
i_show_pp = input.bool(true, "Show Pivot Point")
|
||||
i_show_r1 = input.bool(true, "Show R1")
|
||||
i_show_r2 = input.bool(true, "Show R2")
|
||||
i_show_r3 = input.bool(true, "Show R3")
|
||||
i_show_s1 = input.bool(true, "Show S1")
|
||||
i_show_s2 = input.bool(true, "Show S2")
|
||||
i_show_s3 = input.bool(true, "Show S3")
|
||||
i_color_pp = input.color(color.yellow, "PP Color")
|
||||
i_color_r = input.color(color.red, "Resistance Color")
|
||||
i_color_s = input.color(color.green, "Support Color")
|
||||
|
||||
// Calculation
|
||||
[pp, r1, r2, r3, s1, s2, s3] = pivot(i_timeframe)
|
||||
|
||||
// Plot
|
||||
plot(i_show_pp ? pp : na, "PP", color=i_color_pp, linewidth=2, style=plot.style_stepline)
|
||||
plot(i_show_r1 ? r1 : na, "R1", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r2 ? r2 : na, "R2", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r3 ? r3 : na, "R3", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s1 ? s1 : na, "S1", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s2 ? s2 : na, "S2", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s3 ? s3 : na, "S3", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
@@ -0,0 +1,57 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Pivot Points (Camarilla)", "PIVOTCAM", overlay=true)
|
||||
|
||||
//@function Calculates Camarilla pivot points with 8 levels for short-term trading
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/pivotcam.md
|
||||
//@param tf Timeframe for pivot calculation ("D", "W", "M")
|
||||
//@returns Tuple [pp, r1, r2, r3, r4, s1, s2, s3, s4] with pivot levels
|
||||
//@references Nick Scott, Camarilla equation
|
||||
pivotcam(simple string tf) =>
|
||||
[hi, lo, cl] = request.security(syminfo.tickerid, tf, [high[1], low[1], close[1]], lookahead=barmerge.lookahead_on)
|
||||
if na(hi) or na(lo) or na(cl)
|
||||
[na, na, na, na, na, na, na, na, na]
|
||||
else
|
||||
float pp = (hi + lo + cl) / 3.0
|
||||
float hl_range = hi - lo
|
||||
float r1 = cl + hl_range * 1.0833 / 12.0
|
||||
float s1 = cl - hl_range * 1.0833 / 12.0
|
||||
float r2 = cl + hl_range * 1.1666 / 12.0
|
||||
float s2 = cl - hl_range * 1.1666 / 12.0
|
||||
float r3 = cl + hl_range * 1.2500 / 12.0
|
||||
float s3 = cl - hl_range * 1.2500 / 12.0
|
||||
float r4 = cl + hl_range * 1.5000 / 12.0
|
||||
float s4 = cl - hl_range * 1.5000 / 12.0
|
||||
[pp, r1, r2, r3, r4, s1, s2, s3, s4]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_timeframe = input.timeframe("D", "Pivot Timeframe", options=["D", "W", "M"])
|
||||
i_show_pp = input.bool(true, "Show Pivot Point")
|
||||
i_show_r1 = input.bool(true, "Show R1")
|
||||
i_show_r2 = input.bool(true, "Show R2")
|
||||
i_show_r3 = input.bool(true, "Show R3")
|
||||
i_show_r4 = input.bool(true, "Show R4")
|
||||
i_show_s1 = input.bool(true, "Show S1")
|
||||
i_show_s2 = input.bool(true, "Show S2")
|
||||
i_show_s3 = input.bool(true, "Show S3")
|
||||
i_show_s4 = input.bool(true, "Show S4")
|
||||
i_color_pp = input.color(color.yellow, "PP Color")
|
||||
i_color_r = input.color(color.red, "Resistance Color")
|
||||
i_color_s = input.color(color.green, "Support Color")
|
||||
|
||||
// Calculation
|
||||
[pp, r1, r2, r3, r4, s1, s2, s3, s4] = pivotcam(i_timeframe)
|
||||
|
||||
// Plot
|
||||
plot(i_show_pp ? pp : na, "PP", color=i_color_pp, linewidth=2, style=plot.style_stepline)
|
||||
plot(i_show_r1 ? r1 : na, "R1", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r2 ? r2 : na, "R2", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r3 ? r3 : na, "R3", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r4 ? r4 : na, "R4", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s1 ? s1 : na, "S1", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s2 ? s2 : na, "S2", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s3 ? s3 : na, "S3", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s4 ? s4 : na, "S4", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
@@ -0,0 +1,45 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Pivot Points (DeMark)", "PIVOTDEM", overlay=true)
|
||||
|
||||
//@function Calculates DeMark pivot points with conditional open/close logic
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/pivotdem.md
|
||||
//@param tf Timeframe for pivot calculation ("D", "W", "M")
|
||||
//@returns Tuple [pp, r1, s1] with pivot levels (only 3 levels)
|
||||
//@references Tom DeMark, conditional pivot formula
|
||||
pivotdem(simple string tf) =>
|
||||
[hi, lo, op, cl] = request.security(syminfo.tickerid, tf, [high[1], low[1], open[1], close[1]], lookahead=barmerge.lookahead_on)
|
||||
if na(hi) or na(lo) or na(op) or na(cl)
|
||||
[na, na, na]
|
||||
else
|
||||
float x = 0.0
|
||||
if cl < op
|
||||
x := hi + 2.0 * lo + cl
|
||||
else if cl > op
|
||||
x := 2.0 * hi + lo + cl
|
||||
else
|
||||
x := hi + lo + 2.0 * cl
|
||||
float pp = x / 4.0
|
||||
float r1 = x / 2.0 - lo
|
||||
float s1 = x / 2.0 - hi
|
||||
[pp, r1, s1]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_timeframe = input.timeframe("D", "Pivot Timeframe", options=["D", "W", "M"])
|
||||
i_show_pp = input.bool(true, "Show Pivot Point")
|
||||
i_show_r1 = input.bool(true, "Show R1")
|
||||
i_show_s1 = input.bool(true, "Show S1")
|
||||
i_color_pp = input.color(color.yellow, "PP Color")
|
||||
i_color_r = input.color(color.red, "Resistance Color")
|
||||
i_color_s = input.color(color.green, "Support Color")
|
||||
|
||||
// Calculation
|
||||
[pp, r1, s1] = pivotdem(i_timeframe)
|
||||
|
||||
// Plot
|
||||
plot(i_show_pp ? pp : na, "PP", color=i_color_pp, linewidth=2, style=plot.style_stepline)
|
||||
plot(i_show_r1 ? r1 : na, "R1", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s1 ? s1 : na, "S1", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
@@ -0,0 +1,63 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Pivot Points (Extended)", "PIVOTEXT", overlay=true)
|
||||
|
||||
//@function Calculates extended traditional pivot points with R4-R5 and S4-S5 levels
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/pivotext.md
|
||||
//@param tf Timeframe for pivot calculation ("D", "W", "M")
|
||||
//@returns Tuple [pp, r1, r2, r3, r4, r5, s1, s2, s3, s4, s5] with pivot levels
|
||||
//@references Extended floor trader pivot formula
|
||||
pivotext(simple string tf) =>
|
||||
[hi, lo, cl] = request.security(syminfo.tickerid, tf, [high[1], low[1], close[1]], lookahead=barmerge.lookahead_on)
|
||||
if na(hi) or na(lo) or na(cl)
|
||||
[na, na, na, na, na, na, na, na, na, na, na]
|
||||
else
|
||||
float pp = (hi + lo + cl) / 3.0
|
||||
float hl_range = hi - lo
|
||||
float r1 = 2.0 * pp - lo
|
||||
float s1 = 2.0 * pp - hi
|
||||
float r2 = pp + hl_range
|
||||
float s2 = pp - hl_range
|
||||
float r3 = hi + 2.0 * (pp - lo)
|
||||
float s3 = lo - 2.0 * (hi - pp)
|
||||
float r4 = hi + 3.0 * (pp - lo)
|
||||
float s4 = lo - 3.0 * (hi - pp)
|
||||
float r5 = hi + 4.0 * (pp - lo)
|
||||
float s5 = lo - 4.0 * (hi - pp)
|
||||
[pp, r1, r2, r3, r4, r5, s1, s2, s3, s4, s5]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_timeframe = input.timeframe("D", "Pivot Timeframe", options=["D", "W", "M"])
|
||||
i_show_pp = input.bool(true, "Show Pivot Point")
|
||||
i_show_r1 = input.bool(true, "Show R1")
|
||||
i_show_r2 = input.bool(true, "Show R2")
|
||||
i_show_r3 = input.bool(true, "Show R3")
|
||||
i_show_r4 = input.bool(true, "Show R4")
|
||||
i_show_r5 = input.bool(true, "Show R5")
|
||||
i_show_s1 = input.bool(true, "Show S1")
|
||||
i_show_s2 = input.bool(true, "Show S2")
|
||||
i_show_s3 = input.bool(true, "Show S3")
|
||||
i_show_s4 = input.bool(true, "Show S4")
|
||||
i_show_s5 = input.bool(true, "Show S5")
|
||||
i_color_pp = input.color(color.yellow, "PP Color")
|
||||
i_color_r = input.color(color.red, "Resistance Color")
|
||||
i_color_s = input.color(color.green, "Support Color")
|
||||
|
||||
// Calculation
|
||||
[pp, r1, r2, r3, r4, r5, s1, s2, s3, s4, s5] = pivotext(i_timeframe)
|
||||
|
||||
// Plot
|
||||
plot(i_show_pp ? pp : na, "PP", color=i_color_pp, linewidth=2, style=plot.style_stepline)
|
||||
plot(i_show_r1 ? r1 : na, "R1", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r2 ? r2 : na, "R2", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r3 ? r3 : na, "R3", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r4 ? r4 : na, "R4", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r5 ? r5 : na, "R5", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s1 ? s1 : na, "S1", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s2 ? s2 : na, "S2", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s3 ? s3 : na, "S3", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s4 ? s4 : na, "S4", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s5 ? s5 : na, "S5", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
@@ -0,0 +1,51 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Pivot Points (Fibonacci)", "PIVOTFIB", overlay=true)
|
||||
|
||||
//@function Calculates Fibonacci pivot points using Fibonacci ratios
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/pivotfib.md
|
||||
//@param tf Timeframe for pivot calculation ("D", "W", "M")
|
||||
//@returns Tuple [pp, r1, r2, r3, s1, s2, s3] with pivot levels
|
||||
//@references Fibonacci retracement levels applied to pivot points
|
||||
pivotfib(simple string tf) =>
|
||||
[hi, lo, cl] = request.security(syminfo.tickerid, tf, [high[1], low[1], close[1]], lookahead=barmerge.lookahead_on)
|
||||
if na(hi) or na(lo) or na(cl)
|
||||
[na, na, na, na, na, na, na]
|
||||
else
|
||||
float pp = (hi + lo + cl) / 3.0
|
||||
float hl_range = hi - lo
|
||||
float r1 = pp + 0.382 * hl_range
|
||||
float s1 = pp - 0.382 * hl_range
|
||||
float r2 = pp + 0.618 * hl_range
|
||||
float s2 = pp - 0.618 * hl_range
|
||||
float r3 = pp + 1.000 * hl_range
|
||||
float s3 = pp - 1.000 * hl_range
|
||||
[pp, r1, r2, r3, s1, s2, s3]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_timeframe = input.timeframe("D", "Pivot Timeframe", options=["D", "W", "M"])
|
||||
i_show_pp = input.bool(true, "Show Pivot Point")
|
||||
i_show_r1 = input.bool(true, "Show R1 (38.2%)")
|
||||
i_show_r2 = input.bool(true, "Show R2 (61.8%)")
|
||||
i_show_r3 = input.bool(true, "Show R3 (100%)")
|
||||
i_show_s1 = input.bool(true, "Show S1 (38.2%)")
|
||||
i_show_s2 = input.bool(true, "Show S2 (61.8%)")
|
||||
i_show_s3 = input.bool(true, "Show S3 (100%)")
|
||||
i_color_pp = input.color(color.yellow, "PP Color")
|
||||
i_color_r = input.color(color.red, "Resistance Color")
|
||||
i_color_s = input.color(color.green, "Support Color")
|
||||
|
||||
// Calculation
|
||||
[pp, r1, r2, r3, s1, s2, s3] = pivotfib(i_timeframe)
|
||||
|
||||
// Plot
|
||||
plot(i_show_pp ? pp : na, "PP", color=i_color_pp, linewidth=2, style=plot.style_stepline)
|
||||
plot(i_show_r1 ? r1 : na, "R1", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r2 ? r2 : na, "R2", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r3 ? r3 : na, "R3", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s1 ? s1 : na, "S1", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s2 ? s2 : na, "S2", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s3 ? s3 : na, "S3", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
@@ -0,0 +1,50 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Pivot Points (Woodie)", "PIVOTWOOD", overlay=true)
|
||||
|
||||
//@function Calculates Woodie's pivot points with weighted closing price
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/pivotwood.md
|
||||
//@param tf Timeframe for pivot calculation ("D", "W", "M")
|
||||
//@returns Tuple [pp, r1, r2, r3, s1, s2, s3] with pivot levels
|
||||
//@references Ken Woodie, weighted close formula
|
||||
pivotwood(simple string tf) =>
|
||||
[hi, lo, cl] = request.security(syminfo.tickerid, tf, [high[1], low[1], close[1]], lookahead=barmerge.lookahead_on)
|
||||
if na(hi) or na(lo) or na(cl)
|
||||
[na, na, na, na, na, na, na]
|
||||
else
|
||||
float pp = (hi + lo + 2.0 * cl) / 4.0
|
||||
float r1 = 2.0 * pp - lo
|
||||
float s1 = 2.0 * pp - hi
|
||||
float r2 = pp + (hi - lo)
|
||||
float s2 = pp - (hi - lo)
|
||||
float r3 = hi + 2.0 * (pp - lo)
|
||||
float s3 = lo - 2.0 * (hi - pp)
|
||||
[pp, r1, r2, r3, s1, s2, s3]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_timeframe = input.timeframe("D", "Pivot Timeframe", options=["D", "W", "M"])
|
||||
i_show_pp = input.bool(true, "Show Pivot Point")
|
||||
i_show_r1 = input.bool(true, "Show R1")
|
||||
i_show_r2 = input.bool(true, "Show R2")
|
||||
i_show_r3 = input.bool(true, "Show R3")
|
||||
i_show_s1 = input.bool(true, "Show S1")
|
||||
i_show_s2 = input.bool(true, "Show S2")
|
||||
i_show_s3 = input.bool(true, "Show S3")
|
||||
i_color_pp = input.color(color.yellow, "PP Color")
|
||||
i_color_r = input.color(color.red, "Resistance Color")
|
||||
i_color_s = input.color(color.green, "Support Color")
|
||||
|
||||
// Calculation
|
||||
[pp, r1, r2, r3, s1, s2, s3] = pivotwood(i_timeframe)
|
||||
|
||||
// Plot
|
||||
plot(i_show_pp ? pp : na, "PP", color=i_color_pp, linewidth=2, style=plot.style_stepline)
|
||||
plot(i_show_r1 ? r1 : na, "R1", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r2 ? r2 : na, "R2", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_r3 ? r3 : na, "R3", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s1 ? s1 : na, "S1", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s2 ? s2 : na, "S2", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
plot(i_show_s3 ? s3 : na, "S3", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
||||
@@ -0,0 +1,78 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Parabolic SAR", "PSAR", overlay=true)
|
||||
|
||||
//@function Calculates Parabolic Stop And Reverse (SAR)
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/psar.md
|
||||
//@param af_start Initial acceleration factor (Wilder's original: 0.02)
|
||||
//@param af_increment Acceleration factor increment per new extreme (Wilder's original: 0.02)
|
||||
//@param af_max Maximum acceleration factor (Wilder's original: 0.20)
|
||||
//@returns SAR value (stop level for current trend)
|
||||
//@optimized Minimal state variables, O(1) per bar
|
||||
psar(simple float af_start=0.02, simple float af_increment=0.02, simple float af_max=0.20) =>
|
||||
if af_start <= 0 or af_start > af_max
|
||||
runtime.error("Start AF must be > 0 and <= Max AF")
|
||||
if af_increment <= 0
|
||||
runtime.error("AF increment must be > 0")
|
||||
if af_max <= af_start
|
||||
runtime.error("Max AF must be > Start AF")
|
||||
var bool is_long = true
|
||||
var float sar = low
|
||||
var float ep = high
|
||||
var float af = af_start
|
||||
if bar_index == 0
|
||||
is_long := close > open
|
||||
sar := is_long ? low : high
|
||||
ep := is_long ? high : low
|
||||
af := af_start
|
||||
else
|
||||
float new_sar = sar + af * (ep - sar)
|
||||
bool reverse = false
|
||||
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 := true
|
||||
is_long := false
|
||||
new_sar := ep
|
||||
ep := low
|
||||
af := af_start
|
||||
else
|
||||
if high > ep
|
||||
ep := high
|
||||
af := math.min(af + af_increment, af_max)
|
||||
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 := true
|
||||
is_long := true
|
||||
new_sar := ep
|
||||
ep := high
|
||||
af := af_start
|
||||
else
|
||||
if low < ep
|
||||
ep := low
|
||||
af := math.min(af + af_increment, af_max)
|
||||
sar := new_sar
|
||||
sar
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_af_start = input.float(0.02, "Start AF", minval=0.001, maxval=1.0, step=0.001)
|
||||
i_af_increment = input.float(0.02, "AF Increment", minval=0.001, maxval=1.0, step=0.001)
|
||||
i_af_max = input.float(0.20, "Max AF", minval=0.001, maxval=1.0, step=0.01)
|
||||
|
||||
// Calculation
|
||||
psar = psar(i_af_start, i_af_increment, i_af_max)
|
||||
psar_above = psar > close ? psar : na
|
||||
psar_below = psar < close ? psar : na
|
||||
|
||||
// Plot
|
||||
plot(psar_above, "PSAR Above", color=color.red, style=plot.style_linebr, linewidth=2)
|
||||
plot(psar_below, "PSAR Below", color=color.green, style=plot.style_linebr, linewidth=2)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Swing High/Low Detection", "SWINGS", overlay=true)
|
||||
|
||||
//@function Detects swing highs and swing lows using lookback period
|
||||
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/reversals/swings.md
|
||||
//@param lookback Number of bars on each side to confirm swing point
|
||||
//@param source_high Price series for swing high detection (typically high)
|
||||
//@param source_low Price series for swing low detection (typically low)
|
||||
//@returns Tuple [swing_high, swing_low] with swing point values (na if no swing)
|
||||
swings(simple int lookback, series float source_high, series float source_low) =>
|
||||
if lookback <= 0
|
||||
runtime.error("Lookback must be greater than 0")
|
||||
if lookback > 100
|
||||
runtime.error("Lookback exceeds maximum of 100")
|
||||
bool is_swing_high = true
|
||||
bool is_swing_low = true
|
||||
if bar_index < lookback * 2
|
||||
is_swing_high := false
|
||||
is_swing_low := false
|
||||
else
|
||||
float center_high = source_high[lookback]
|
||||
float center_low = source_low[lookback]
|
||||
for i = 1 to lookback
|
||||
if source_high[lookback - i] > center_high or source_high[lookback + i] > center_high
|
||||
is_swing_high := false
|
||||
if source_low[lookback - i] < center_low or source_low[lookback + i] < center_low
|
||||
is_swing_low := false
|
||||
float swing_high_value = is_swing_high ? source_high[lookback] : na
|
||||
float swing_low_value = is_swing_low ? source_low[lookback] : na
|
||||
[swing_high_value, swing_low_value]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_lookback = input.int(5, "Lookback Period", minval=1, maxval=100, tooltip="Number of bars on each side to confirm swing point")
|
||||
i_source_high = input.source(high, "Source High", tooltip="Price series for swing high detection")
|
||||
i_source_low = input.source(low, "Source Low", tooltip="Price series for swing low detection")
|
||||
i_show_high = input.bool(true, "Show Swing High Lines")
|
||||
i_show_low = input.bool(true, "Show Swing Low Lines")
|
||||
i_color_high = input.color(color.red, "Swing High Color")
|
||||
i_color_low = input.color(color.green, "Swing Low Color")
|
||||
|
||||
// Calculation
|
||||
[swing_high, swing_low] = swings(i_lookback, i_source_high, i_source_low)
|
||||
|
||||
// Track last confirmed swing points
|
||||
var float last_swing_high = na
|
||||
var float last_swing_low = na
|
||||
|
||||
// Update swing levels
|
||||
if not na(swing_high)
|
||||
last_swing_high := swing_high
|
||||
|
||||
if not na(swing_low)
|
||||
last_swing_low := swing_low
|
||||
|
||||
// Plot swing levels as continuous lines
|
||||
plot(i_show_high ? last_swing_high : na, "Swing High", color=i_color_high, linewidth=2, style=plot.style_line)
|
||||
plot(i_show_low ? last_swing_low : na, "Swing Low", color=i_color_low, linewidth=2, style=plot.style_line)
|
||||
Reference in New Issue
Block a user