diff --git a/src/data.jl b/src/data.jl index a929252..687b204 100644 --- a/src/data.jl +++ b/src/data.jl @@ -157,12 +157,12 @@ function update!(chart::Chart, c::Candle) if chart.ts != floor(c.ts, chart.tf) # timeframe boundary case chart.ts = floor(c.ts, chart.tf) - chart.candle = merge_candle!(missing, c) + chart.candle = Candle(c.ts, c.o, c.h, c.l, c.c, c.v) # clone tf boundary candle to start fresh candle aggregation push_new_candle!(chart, c) else # normal case chart.candle = merge_candle!(chart.candle, c) - update_last_candle!(chart, c) + update_last_candle!(chart, chart.candle) end end @@ -215,3 +215,29 @@ function chart(name, tf; indicators::Vector=[], visuals::Vector{<:Dict}=Vector{D candle = missing return Chart(;name, tf, df, indicators, visuals, ts, candle) end + +""" random_candles(tf, n; start) + +This belongs somewhere in ~/hak/trading, but it can live here for now. +""" +function random_candles(tf, n; + start = round(now(), tf), + open = 1000.00, + volatility = -0.05:0.01:0.05) + start + res = [] + for i in 0:n-1 + t = start + (i * tf) + v = rand(volatility, 3) + close = open + (open * v[1]) + high = open + (open * abs(v[2])) + low = close - (close * abs(v[3])) + # @info "vals" open high low close + c = Candle(t, open, high, low, close, (100 * v[1]) + 100) + push!(res, c) + open = close + end + res +end + +export random_candles