mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-07-29 10:07:43 +00:00
86fe32a682
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>
30 lines
1.0 KiB
Plaintext
30 lines
1.0 KiB
Plaintext
// The MIT License (MIT)
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("Midpoint (MIDPOINT)", "MIDPOINT", overlay=true)
|
|
|
|
//@function Calculates the midpoint of the highest high and lowest low over a specified period
|
|
//@doc https://github.com/mihakralj/pinescript/blob/main/indicators/numerics/midpoint.md
|
|
//@param src Source series to calculate midpoint for
|
|
//@param len Lookback period for finding highest and lowest values
|
|
//@returns float The midpoint value (highest + lowest) * 0.5 over the period
|
|
//@optimized Uses multiplication instead of division for performance
|
|
midpoint(series float src, simple int len) =>
|
|
if len <= 0
|
|
runtime.error("Length must be greater than 0")
|
|
float highest_val = ta.highest(src, len)
|
|
float lowest_val = ta.lowest(src, len)
|
|
(highest_val + lowest_val) * 0.5
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
// Inputs
|
|
i_source = input.source(close, "Source")
|
|
i_length = input.int(14, "Length", minval=1)
|
|
|
|
// Calculation
|
|
result = midpoint(i_source, i_length)
|
|
|
|
// Plot
|
|
plot(result, "Midpoint", color=color.yellow, linewidth=2)
|