ERROR: "A table column must have a specific type and can't use a tuple (ANY vector) as column"

I have defined this function, but when I use it on a table using sql it gives me error: "A table column must have a specific type and can't use a tuple (ANY vector) as column"

using version 1.30.16

I need help very urgently. Please reply as soon as possible.


def atr(high,low,close,atr_tp){

mf_atr = 2 * atr_tp - 1

cp = prev(close)

tr = rowMax(abs(high-low),abs(high-cp),abs(low-cp))

atr = ema(tr, mf_atr)

return (tr,atr)

}

tmp = table(100:0,`date`symbol`open`high`low`close`volume,[DATE,SYMBOL,DOUBLE ,DOUBLE,DOUBLE ,DOUBLE ,DOUBLE ] )

select *, atr(high,low,close,atr_tp) from tmp

// here it will give an error "A table column must have a specific type and can't use a tuple (ANY vector) as column"


I tried using MACD function defined in  https://github.com/dolphindb/DolphinDBModules/blob/master/ta/src/ta.dos

It will give the same error.

def macd(close, fastPeriod, slowPeriod, signalPeriod){

n = close.size()

b = ifirstNot(close)

if (fastPeriod == 0 && slowPeriod == 0) {

inSlowPeriod = 26

if(b < 0 || b + inSlowPeriod + signalPeriod - 2 > n) 

return (array(DOUBLE, n, n, NULL), array(DOUBLE, n, n, NULL), array(DOUBLE, n, n, NULL))

initFast = close.subarray((b+14):(b+26)).avg()

fastResult = iterate(initFast, 0.85, close. subarray(b+26:) * 0.15)

initSlow = close.subarray(:b+26).avg()

slowResult = iterate(initSlow, 0.925, close. subarray(b+26:) * 0.075)

diff = array(DOUBLE, b + 25, n, NULL).append!(initFast-initSlow).append!(fastResult - slowResult)

}

else {

inSlowPeriod = max(fastPeriod, slowPeriod)

inFastPeriod = min(fastPeriod, slowPeriod)

diffPeriod = inSlowPeriod - inFastPeriod

if(b < 0 || b + inSlowPeriod + signalPeriod - 2 > n) 

return (array(DOUBLE, n, n, NULL), array(DOUBLE, n, n, NULL), array(DOUBLE, n, n, NULL))

diffResult = ema(close.subarray(b+diffPeriod:), inFastPeriod) - ema(close.subarray(b:), inSlowPeriod)[diffPeriod:]

diff = array(DOUBLE, b+diffPeriod, n, NULL).append!(diffResult)

}

dea = ema(diff, signalPeriod)

diff[:(b + inSlowPeriod + signalPeriod-2)] = NULL

return (diff, dea, diff - dea)

}

请先 登录 后评论

1 个回答

mhxiang
select *, atr(high,low,close,atr_tp) as `name1`name2 from tmp
select *, macd(close,5,9,) as `name1`name2`name3 from tmp
请先 登录 后评论
  • 1 关注
  • 0 收藏,1073 浏览
  • Vishvesh Upadhyay 提出于 2022-02-16 21:44

相似问题