繁体   English   中英

Pine 脚本 - 未声明的标识符

[英]Pine Script - Undeclared identifier

当我在 TradingView 上运行脚本时,我总是收到错误“第 70 行:未声明的标识符 'DIPlus_Smoothed'”

        //@version=5
indicator(title='WSTF ADX + EMA Angle', shorttitle='WSTF ADX + EMA Angle', overlay=false)

//*************** Moving Average *****************

ma_trend_slow = ta.ema(close, 200)
ma_trend_fast = ta.ema(close, 150)

//*************** Moving Average *****************

lookback1 = input(5, 'Lookback 1')
malen1 = input(100, 'MA Length')
type1 = input.string('EMA', '1st MA Type', options=['SMA', 'EMA', 'HMA', 'VWMA', 'LSMA'])
f_hma(_src, _length) =>
    _return = ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length)))
    _return
price = close
price1 = if type1 == 'SMA'
    ta.sma(price, malen1)
else
    if type1 == 'EMA'
        ta.ema(price, malen1)
    else
        if type1 == 'VWMA'
            ta.vwma(price, malen1)
        else
            if type1 == 'LSMA'
                ta.linreg(price, malen1, 0)
            else
                f_hma(price, malen1)


roc1 = ta.roc(price1, lookback1)

macolor = roc1 > 0 ? color.new(color.green, 80) : roc1 < 0 ? color.new(color.red, 80) : color.new(color.black, 80)

//************************************** ADX ***************************************
len = input(title='Length', defval=14)
len_LT = input(title='Length LT', defval=29)
th_b = input(title='threshold bottom', defval=15)
th_t = input(title='threshold top', defval=40)
lensma = input(title='Len SMA', defval=10)


TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))
DirectionalMovementPlus = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0

var SmoothedTrueRange=TrueRange
var SmoothedDirectionalMovementPlus=DirectionalMovementPlus
var SmoothedDirectionalMovementMinus=DirectionalMovementMinus

SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus:= nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus:= nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100

DX = math.abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100
ADX = ta.sma(DX, len)

DIMinus_Smoothed = ta.sma(DIMinus, lensma)
DIPLus_Smoothed = ta.sma(DIPlus, lensma)

plot(DIMinus_Smoothed, color=color.red)
plot(DIPLus_Smoothed, color=color.green)

bullsig = ta.crossover(DIPLus_Smoothed, DIMinus_Smoothed) and roc1 > 0
bearsig = ta.crossover(DIMinus_Smoothed, DIPlus_Smoothed) and roc1 < 0

//plotshape(bullsig, style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.small)

bgcolor(macolor)

//*************************

如果我删除第 70 行,并且仅使用“bullsig”运行代码,我根本不会收到错误...我尝试了很多东西并进行了很多研究,但我无法找到解决方案至今。

也许有人可以帮忙?

pine-script是一种区分大小写的语言。

DIPLus_Smoothed = ta.sma(DIPlus, lensma)
bearsig = ta.crossover(DIMinus_Smoothed, DIPlus_Smoothed) and roc1 < 0

您定义的是带有大写LDIPLus_Smoothed 您使用的是带有小写lDIPlus_Smoothed

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM