diff --git a/src/MarketTechnicals.jl b/src/MarketTechnicals.jl index 15e9848..5bf2d1d 100644 --- a/src/MarketTechnicals.jl +++ b/src/MarketTechnicals.jl @@ -5,10 +5,10 @@ module MarketTechnicals using TimeSeries export sma, ema, - bollingerbands, truerange, atr, # keltnerbands, + bollingerbands, truerange, atr, keltnerbands, obv, vwap, doji, - rsi, macd, # cci, + rsi, macd, cci, floorpivots, woodiespivots, abs, µprice diff --git a/src/momentum.jl b/src/momentum.jl index 0d85eb8..5b9d033 100644 --- a/src/momentum.jl +++ b/src/momentum.jl @@ -37,6 +37,18 @@ end macd{T}(ta::TimeArray{T,1}) = macd(ta, 12, 26, 9) +function cci{T,N}(ohlc::TimeArray{T,N}, n::Int) + price = (ohlc["High"] + ohlc["Low"] + ohlc["Close"])/3 + psma = sma(price, n) + avepdev = sma((price-psma), n) + + vals = (price - psma) / avepdev / 0.015 + + TimeArray(vals.timestamp, vals.values, ["cci"]) +end + +cci{T,N}(ohlc::TimeArray{T,N}, n::Int) = cci(ohlc, 20) + # function cci(df::DataFrame, n::Int, c::Float64) # # df = copy(df) diff --git a/src/volatility.jl b/src/volatility.jl index 9f40710..6d093ca 100644 --- a/src/volatility.jl +++ b/src/volatility.jl @@ -24,6 +24,24 @@ end atr{T,N}(ta::TimeArray{T,N}) = atr(ta, 14) +function keltnerbands{T,N}(ohlc::TimeArray{T,N}, n::Int) + hi = ohlc["High"]; lo = ohlc["Low"]; cl = ohlc["Close"] + typ = (hi + lo + cl)/3 + rng = hi - lo + rma = sma(rng, n) + + kma = sma(typ, n) + tstamps = kma.timestamp[1:end] + + kma = TimeArray(tstamps, kma.values, ["kma"]) + kup = TimeArray(tstamps, (kma+rma).values, ["kup"]) + kdn = TimeArray(tstamps, (kma-rma).values, ["kdn"]) + + merge(kma, merge(kup, kdn)) +end + +keltnerbands{T,N}(ohlc::TimeArray{T,N}, n::Int) = keltnerbands(ohlc, 10) + # function keltnerbands{T,N}(hi::Array{SeriesPair{T,N},1}, # lo::Array{SeriesPair{T,N},1}, # cl::Array{SeriesPair{T,N},1}, n::Int)