Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Indicators is a [Julia](https://julialang.org) package offering efficient implem
- VMA (variable-length moving average)
- Chaikin Money Flow
- Ultimate Oscillator
- OBV (on-balance volume)
- Too many more to name...always happy to hear suggestions though!

### Done
Expand All @@ -98,6 +97,7 @@ Indicators is a [Julia](https://julialang.org) package offering efficient implem
- ~~MMA (modified moving average)~~
- ~~ZLEMA (zero lag exponential moving average)~~
- ~~VWMA (volume-weighted moving average)~~
- ~~OBV (on-balance volume)~~

# Examples
#### Randomly generated data:
Expand Down
2 changes: 1 addition & 1 deletion src/Indicators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Indicators
wilder_sum, mode, diffn,
sma, trima, wma, ema, mma, kama, mama, hma, swma, dema, tema, alma, zlema, vwma, vwap, hama,
mlr_beta, mlr_slope, mlr_intercept, mlr, mlr_se, mlr_ub, mlr_lb, mlr_bands, mlr_rsq,
aroon, donch, ichimoku, momentum, roc, macd, rsi, adx, psar, kst, wpr, cci, stoch, smi,
aroon, donch, ichimoku, momentum, roc, macd, rsi, adx, psar, kst, wpr, cci, stoch, smi, obv,
bbands, tr, atr, keltner,
crossover, crossunder,
renko, heikinashi,
Expand Down
23 changes: 23 additions & 0 deletions src/mom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,26 @@ function smi(hlc::AbstractMatrix{T}; n::Int64=13, nFast::Int64=2, nSlow::Int64=2
out[:,2] = maSig(out[:,1], n=nSig)
return out
end

"""
```
obv(cv::AbstractMatrix{T})::Array{Float64}
```

OBV (on-balance volume)
"""
function obv(cv::AbstractMatrix{T})::Array{Float64} where {T<:Real}
n = size(cv, 1)
out = zeros(T, n)
@inbounds for i = 2:n
if cv[:,1][i] > cv[:,1][i-1]
out[i] = out[i-1] + cv[:,2][i]
elseif cv[:,1][i] < cv[:,1][i-1]
out[i] = out[i-1] - cv[:,2][i]
else
out[i] = out[i-1]
end
end
return out
end

1 change: 1 addition & 0 deletions src/temporal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ smi(X::TS; args...) = hlc_fun(X, smi, [:SMI,:Signal]; args...)
donch(X::TS; args...) = hl_fun(X, donch, [:Low,:Mid,:High]; args...)
ichimoku(X::TS; args...) = hlc_fun(X, ichimoku, [:Tenkan,:Kijun,:SenkouA,:SenkouB,:Chikou]; args...)
aroon(X::TS; args...) = hl_fun(X, aroon, [:AroonUp,:AroonDn,:AroonOsc]; args...)
obv(X::TS; args...) = cv_fun(X, obv, [:OBV]; args...)

##### vol.jl ######
bbands(X::TS; args...) = close_fun(X, bbands, [:LB,:MA,:UB]; args...)
Expand Down
7 changes: 7 additions & 0 deletions test/mom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
@test size(tmp, 1) == N
@test size(tmp, 2) == 2
@test sum(isnan.(tmp)) != N
tmp = obv(Y)
@test size(tmp, 1) == N
@test size(tmp, 2) == 1
@test sum(isnan.(tmp)) != N
end
@testset "Temporal" begin
x = TS(cumsum(randn(N)))
Expand Down Expand Up @@ -131,5 +135,8 @@
tmp = smi(Z)
@test size(tmp, 1) == N
@test size(tmp, 2) == 2
tmp = obv(Y)
@test size(tmp, 1) == N
@test size(tmp, 2) == 1
end
end