本文介绍了MFI - 调整 pos 和 neg 资金流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码

length = input(title="Length", type=input.integer, defval=14, minval=1, maxval=2000)
src = hlc3
mfipos = sum(volume * (change(src) <= 0 ? 0 : src), length)
mfineg = sum(volume * (change(src) >= 0 ? 0 : src), length)

_rsi(mfipos, mfineg) =>
    if mfipos == 0
        100
    if mfineg == 0
        0
    100.0 - (100.0 / (1.0 + mfipos / mfineg))
mf = _rsi(mfipos, mfineg)

plot(mfipos, color=#FF7000, linewidth=2, title='MFI pos')
plot(mfineg, color=#0088FA, linewidth=2, title='MFI neg')

MFI 是有界的.Pos 和 Neg 资金流向图不绘制以下价格图.

MFI is bounded.Pos and Neg money flow plot do not plot following price graph.

推荐答案

资金流向指数是一个从 0 到 100 的有界函数.为了正确绘制正负资金流向,我需要标准化最小值和最大值.

The Money Flow Index is a bounded function from 0 to 100. In order to properly have the Positive and Negative money flow be plotted as I wanted, I needed to normalize the min and max values.

结果:

//Normal MFI calculation
length = input(title="Length", type=input.integer, defval=14, minval=1, maxval=2000)
src = hlc3
mfiPositive = sum(volume * (change(src) <= 0 ? 0 : src), length)
mfiNegative = sum(volume * (change(src) >= 0 ? 0 : src), length)

//MFI variables to normalize data to be plotted
mfiLow = lowest(length)
mfiHigh = highest(length)
min_mfiPos = lowest(mfiPositive, length)
min_mfiNeg = lowest(mfiNegative, length)
max_mfiPos = highest(mfiPositive, length)
max_mfiNeg = highest(mfiNegative, length)

mfiPosNorm = mfiHigh + (mfiPositive - min_mfiPos) * (mfiHigh - mfiLow) / (max_mfiPos - min_mfiPos)
mfiNegNorm = mfiHigh + (mfiNegative - min_mfiNeg) * (mfiHigh - mfiLow) / (max_mfiNeg - min_mfiNeg)
_rsi(mfiPositive, mfiNegative) =>
    if mfiNegative == 0
        100
    if mfiPositive == 0
        0
    100 - (100 / (1.0 + mfiPositive / mfiNegative))
mf = _rsi(mfiPositive, mfiNegative)
plot(mfiPosNorm, color=colorNavy, linewidth=2, title='MFI Positive Money Flow')
plot(mfiNegNorm, color=colorFuchsia, linewidth=2, title='MFI Negative Money Flow')

这篇关于MFI - 调整 pos 和 neg 资金流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 15:18