Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia add indicator to candlestick chart

I'm new to Julia and I'm trying to add a technical indicator (let it be a simple moving average) to my candlestick chart. How should I do that?

using Plots, MarketData, TimeSeries
gr()

ta = yahoo(:GOOG, YahooOpt(period1 = now() - Month(1)))
display(plot(ta, seriestype= :candlestick))
readline()
like image 940
Fatafim Avatar asked Feb 05 '26 05:02

Fatafim


1 Answers

The general answer to your question is that Plots uses the bang (!) naming convention to naming functions which mutate an existing plot object. Therefore if you want to add something to another plot, you should call plot! (or scatter!, bar!, etc.) after your first plot call.

In your case, the high level solution would therefore be:

plot(ta, st = :candlestick)
plot!(my_indicator_data)

Now you're saying you want a moving average, so here's an example:

julia> plot(ta, st = :candlestick; xlabel = "Trading Day", ylabel = "Price", 
            xrot = 45, bottom_margin = 4Plots.mm)

julia> using RollingFunctions

julia> plot!(runmean(values((ta.High .+ ta.Low) ./ 2), 5)) # using mid-price

which will give you

enter image description here

you might want to double check that this is right, it looks to me like the average line is offset by one day, which might be down to some trickery TimeSeries is doing to the xticks.

like image 185
Nils Gudat Avatar answered Feb 09 '26 10:02

Nils Gudat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!