-
Notifications
You must be signed in to change notification settings - Fork 62
MFI Indicator #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
MFI Indicator #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,3 +319,39 @@ function smi(hlc::Matrix{T}; n::Int64=13, nFast::Int64=2, nSlow::Int64=25, nSig: | |
out[:,2] = maSig(out[:,1], n=nSig) | ||
return out | ||
end | ||
|
||
|
||
""" | ||
MFI (Money Flow Index) gives almost the same results as tradingview.com | ||
""" | ||
function MFI_logic(x::Array{T}; n::Int64=14, args...)::Array{T} where {T<:Real} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function naming convention is all lowercase, e.g. |
||
@assert n<size(x,1) && n>0 "Argument n is out of bounds." | ||
N = size(x,1) | ||
ups = zeros(N) | ||
dns = zeros(N) | ||
zro = 0.0 | ||
dx = [NaN; ndims(x[:,2]) > 1 ? diff(x[:,2], dims=1) : diff(x[:,2])] | ||
@inbounds for i=2:N | ||
if dx[i] > zro | ||
ups[i] = x[i,3] | ||
elseif dx[i] < zro | ||
dns[i] = x[i,3] | ||
end | ||
end | ||
rs = sma(ups[1:end], n=n;) ./ sma(dns[1:end], n=n;) | ||
return 100.0 .- 100.0 ./ (1.0 .+ rs) | ||
end | ||
|
||
##### X::TS should contain traditional OHLC+Volume too | ||
function MFI(X::TS, flds::Vector{Symbol}; args...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about naming convention. The MFI method that takes a |
||
if size(X,2) > 1 && has_close(X) | ||
typical_price = sum(X[[:high, :low, :close]].values, dims = 2)/3 | ||
close = X[:close].values | ||
volume = X[:volume].values | ||
rmf = typical_price.*volume | ||
return ts(MFI_logic([close typical_price rmf]; args...), X.index, flds) | ||
#return ts(MFI_logic(X.values; args...), X.index, flds) | ||
else | ||
error("Must be univariate or contain Close/Settle/Last.") | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation comments should follow the same convention as other functions (function signature in triple-backticks followed by indicator name/interpretation two lines below).