admin管理员组

文章数量:1310420

I am new to PineScript. I made a simple library to calculate standard Chaikin Money Flow value, to reuse it both in a custom indicator and within a strategy.

This is the library code

//@version=6

// @description Simple library for standard Chaikin Money Flow calculation.
library("CMFLib")


export GrayZoneTreshold() => 0.05
export LightTrendZoneTreshold() => 0.25
export StrongTrendZoneTreshold() => 0.4

// @function standard CMF calculation
// @param length CMF periods
// @returns Chaikin Money Flow value
export cmf(int length) =>
    var cumVol = 0.
    cumVol += nz(volume)
    if barstate.islast and cumVol == 0
        runtime.error("No volume is provided by the data vendor.")
    ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume
    mf = math.sum(ad, length) / math.sum(volume, length)

    mf

export signal(float mf) => ta.ema(mf, 5)

export checkBullSignal(float mf) =>
    mf_sma= signal(mf)

    fastMFBull = mf_sma[2] < -GrayZoneTreshold() and mf_sma > GrayZoneTreshold()
    slowMFBull = mf_sma[7] < -GrayZoneTreshold() and mf_sma > GrayZoneTreshold()

    bullishSignal = (fastMFBull or slowMFBull)

    bullishSignal

export checkBearSignal(float mf) =>
    mf_sma= signal(mf)

    fastMFBear = mf_sma[2] > GrayZoneTreshold() and mf_sma < -GrayZoneTreshold()
    slowMFBear = mf_sma[7] > GrayZoneTreshold() and mf_sma < -GrayZoneTreshold()

    bearSignal = fastMFBear or slowMFBear

    bearSignal

It was working some days ago, but today in the indicator I get the error:

Undeclared identifier 'CMFLib'.

Following is the indicator code.

import matteo_delloioio/CMFLib/2


//@version=6
indicator(title="My Chaikin Money Flow", shorttitle="MyCMF", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

length = input.int(20, minval=1)
mf = CMFLib.cmf(length)
// mf = CMFLib.cmf(length)

plot(mf, color=color.green, title="MF")

hline(0, color=color.gray, title="Zero", linestyle=hline.style_dashed)
hline(CMFLib.GrayZoneTreshold(), color=color.gray, title="Gray Zone +", linestyle=hline.style_dotted)
hline(CMFLib.LightTrendZoneTreshold(), color=color.green, title="Bullish Zone -", linestyle=hline.style_dotted)
hline(CMFLib.StrongTrendZoneTreshold(), color=color.lime, title="Strong Bullish Zone", linestyle=hline.style_dotted)
hline(-CMFLib.GrayZoneTreshold(), color=color.gray, title="Gray Zone -", linestyle=hline.style_dotted)
hline(-CMFLib.LightTrendZoneTreshold(), color=color.orange, title="Bearish Zone", linestyle=hline.style_dotted)
hline(-CMFLib.StrongTrendZoneTreshold(), color=color.red, title="Strong Bearish Zone", linestyle=hline.style_dotted)

bullishSignal = CMFLib.checkBullSignal(mf)
bearSignal = CMFLib.checkBearSignal(mf)

plotshape(bullishSignal ? mf : na, location=location.absolute, style=shape.triangleup, size=size.small, color=color.green)
plotshape(bearSignal ? mf : na, location=location.absolute, style=shape.triangledown, size=size.small, color=color.red)

Any advice?

I am new to PineScript. I made a simple library to calculate standard Chaikin Money Flow value, to reuse it both in a custom indicator and within a strategy.

This is the library code

//@version=6

// @description Simple library for standard Chaikin Money Flow calculation.
library("CMFLib")


export GrayZoneTreshold() => 0.05
export LightTrendZoneTreshold() => 0.25
export StrongTrendZoneTreshold() => 0.4

// @function standard CMF calculation
// @param length CMF periods
// @returns Chaikin Money Flow value
export cmf(int length) =>
    var cumVol = 0.
    cumVol += nz(volume)
    if barstate.islast and cumVol == 0
        runtime.error("No volume is provided by the data vendor.")
    ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume
    mf = math.sum(ad, length) / math.sum(volume, length)

    mf

export signal(float mf) => ta.ema(mf, 5)

export checkBullSignal(float mf) =>
    mf_sma= signal(mf)

    fastMFBull = mf_sma[2] < -GrayZoneTreshold() and mf_sma > GrayZoneTreshold()
    slowMFBull = mf_sma[7] < -GrayZoneTreshold() and mf_sma > GrayZoneTreshold()

    bullishSignal = (fastMFBull or slowMFBull)

    bullishSignal

export checkBearSignal(float mf) =>
    mf_sma= signal(mf)

    fastMFBear = mf_sma[2] > GrayZoneTreshold() and mf_sma < -GrayZoneTreshold()
    slowMFBear = mf_sma[7] > GrayZoneTreshold() and mf_sma < -GrayZoneTreshold()

    bearSignal = fastMFBear or slowMFBear

    bearSignal

It was working some days ago, but today in the indicator I get the error:

Undeclared identifier 'CMFLib'.

Following is the indicator code.

import matteo_delloioio/CMFLib/2


//@version=6
indicator(title="My Chaikin Money Flow", shorttitle="MyCMF", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

length = input.int(20, minval=1)
mf = CMFLib.cmf(length)
// mf = CMFLib.cmf(length)

plot(mf, color=color.green, title="MF")

hline(0, color=color.gray, title="Zero", linestyle=hline.style_dashed)
hline(CMFLib.GrayZoneTreshold(), color=color.gray, title="Gray Zone +", linestyle=hline.style_dotted)
hline(CMFLib.LightTrendZoneTreshold(), color=color.green, title="Bullish Zone -", linestyle=hline.style_dotted)
hline(CMFLib.StrongTrendZoneTreshold(), color=color.lime, title="Strong Bullish Zone", linestyle=hline.style_dotted)
hline(-CMFLib.GrayZoneTreshold(), color=color.gray, title="Gray Zone -", linestyle=hline.style_dotted)
hline(-CMFLib.LightTrendZoneTreshold(), color=color.orange, title="Bearish Zone", linestyle=hline.style_dotted)
hline(-CMFLib.StrongTrendZoneTreshold(), color=color.red, title="Strong Bearish Zone", linestyle=hline.style_dotted)

bullishSignal = CMFLib.checkBullSignal(mf)
bearSignal = CMFLib.checkBearSignal(mf)

plotshape(bullishSignal ? mf : na, location=location.absolute, style=shape.triangleup, size=size.small, color=color.green)
plotshape(bearSignal ? mf : na, location=location.absolute, style=shape.triangledown, size=size.small, color=color.red)

Any advice?

Share Improve this question edited Feb 3 at 14:33 TylerH 21.1k77 gold badges79 silver badges112 bronze badges asked Feb 3 at 7:56 jojojojo 1702 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

It seems that it's coming from hline() when passing -CMFLib.* price parameters (which accepts an input int/float). Perhaps, you can export negative float values.

本文标签: pine scriptTradingView PineScript v6 import library error Undeclared identifier 39CMFLib39Stack Overflow