Reputation: 170
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?
Upvotes: 0
Views: 60
Reputation: 178
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.
Upvotes: 1