簡體   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