mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-07-29 18:17:43 +00:00
23 lines
572 B
Plaintext
23 lines
572 B
Plaintext
// Licensed under the Apache License, Version 2.0
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("True Range", "TR", overlay=false)
|
|
|
|
//@function Calculates the True Range
|
|
//@returns True Range value for the current bar
|
|
tr() =>
|
|
float prevClose = nz(close[1], close)
|
|
float tr1 = high - low
|
|
float tr2 = math.abs(high - prevClose)
|
|
float tr3 = math.abs(low - prevClose)
|
|
float trueRange = math.max(tr1, math.max(tr2, tr3))
|
|
trueRange
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
// Calculation
|
|
trValue = tr()
|
|
|
|
// Plot
|
|
plot(trValue, "TR", color=color.yellow, linewidth=2)
|