Skip to content

Commit

Permalink
Implement visualization for ATR
Browse files Browse the repository at this point in the history
I can't believe this was the first multi-input indicator I added.
  • Loading branch information
g-gundam committed Dec 20, 2024
1 parent 6720f0c commit 78d874e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ golden_cross_chart |> visualize |> lwc_show
- [ ] ALMA
- [ ] AO
- [ ] Aroon
- [ ] ATR
- [ ] [ATR](https://www.tradingview.com/support/solutions/43000501823-average-true-range-atr/)
- [x] BB
- [ ] BOP
- [ ] CCI
Expand Down
23 changes: 23 additions & 0 deletions src/ATR.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
denominated_price(atr::ATR) = false

"""$(TYPEDSIGNATURES)
Visualize ATR using 1 lwc_line.
"""
function visualize(atr::ATR, opts::Union{AbstractDict,Nothing}, df::DataFrame)
name = indicator_fields(atr)[1]
kwargs = Dict(
:label_name => "ATR $(atr.period)",
:line_color => "#1B9AAA",
:line_width => 3
)
if opts !== nothing
merge!(kwargs, opts)
end
atr = replace_missing_with(0, df[!, name])
return lwc_line(
df.ts,
atr;
kwargs...
)
end
1 change: 1 addition & 0 deletions src/TechnicalIndicatorCharts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ function visualize(chart::Chart;
)
end

include("ATR.jl")
include("BB.jl")
include("DEMA.jl")
include("EMA.jl")
Expand Down
18 changes: 18 additions & 0 deletions test/ATR.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using TechnicalIndicatorCharts

@testset "ATR" begin
if !isdefined(Main, :sample_candles)
include("helper/main.jl")
end
chart = Chart(
"TEST", Minute(1),
indicators=[ATR{OHLCV{DateTime,Float64,Float64}}(;period=5)],
visuals=[nothing]
)
candles = sample_candles()
for c in candles
update!(chart, c)
end
@test visualize(chart) isa Any
# If it gets this far, we can instantiate, update, and visualize.
end

0 comments on commit 78d874e

Please sign in to comment.