本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("[ad] MFI + CHOP", shorttitle = "MFI + CHOP", overlay = false, precision = 2, timeframe = "", timeframe_gaps = true)
// Standard oscillators on a shared scale, without rescaling their values.
// MFI: Gene Quong and Avrum Soudack. CHOP: E. W. Dreiss.
int mfiLength = input.int(14, "MFI length", minval = 1, group = "MFI")
float mfiSource = input.source(hlc3, "Source", group = "MFI")
float mfiUpper = input.float(80.0, "Upper level", minval = 0, maxval = 100, group = "MFI")
float mfiLower = input.float(20.0, "Lower level", minval = 0, maxval = 100, group = "MFI")
int chopLength = input.int(14, "CHOP length", minval = 2, group = "CHOP")
float chopUpper = input.float(61.8, "Upper level", minval = 0, maxval = 100, group = "CHOP")
float chopLower = input.float(38.2, "Lower level", minval = 0, maxval = 100, group = "CHOP")
bool showBackground = input.bool(true, "Zone backgrounds", group = "Appearance")
bool showMidline = input.bool(true, "Midline at 50", group = "Appearance")
float mfi = ta.mfi(mfiSource, mfiLength)
float priceRange = ta.highest(high, chopLength) - ta.lowest(low, chopLength)
float trueRangeSum = math.sum(ta.atr(1), chopLength)
// CHOP is undefined when the price range is zero.
float chop = priceRange > 0 and trueRangeSum > 0 ? 100 * math.log10(trueRangeSum / priceRange) / math.log10(chopLength) : na
plot(mfi, "MFI", color = #7E57C2, linewidth = 1)
plot(chop, "CHOP", color = #2962FF, linewidth = 1)
mfiTop = hline(mfiUpper, "MFI upper level", color = #787B86, linestyle = hline.style_dashed)
mfiBottom = hline(mfiLower, "MFI lower level", color = #787B86, linestyle = hline.style_dashed)
chopTop = hline(chopUpper, "CHOP upper level", color = color.new(#787B86, 20), linestyle = hline.style_dashed)
chopBottom = hline(chopLower, "CHOP lower level", color = color.new(#787B86, 20), linestyle = hline.style_dashed)
hline(50, "Midline at 50", color = color.new(#787B86, 50), linestyle = hline.style_dotted, display = showMidline ? display.all : display.none)
fill(mfiTop, mfiBottom, color = showBackground ? color.new(#7E57C2, 90) : na, title = "MFI zone")
fill(chopTop, chopBottom, color = showBackground ? color.new(#2962FF, 92) : na, title = "CHOP zone")