15 Reactive State engine with TA module problem

I want to use indicators like bBands (bollinger bands) from TA module. When I use it with  createReactiveStateEngine  it gives me error Error Message:A metric should return a scalar or an array with the same length as the input.


Please help me.


Input table columns -> symbol, ts, open, high, low, close

metrics=bBands(close, timePeriod, nbdevUp, nbdevDn, maType)

return 3 factors

output table columns-> symbol, factor0, factor1, factor2

then why error ? please help me.


Code:-

use ta

dummy = streamTable(10000:0, `symbol`ts`open`high`low`close,[SYMBOL,TIMESTAMP,DOUBLE,DOUBLE,DOUBLE,DOUBLE])


colNames = ["symbol"].append!("factor"+string(0..2))

colTypes = [SYMBOL].append!(take(DOUBLE, 3))

resultTable = streamTable(10000:0, colNames, colTypes)

engine1 = createReactiveStateEngine(name="demo1", metrics=<bBands(close,5,2,1,5)>, dummyTable=dummy, outputTable=resultTable, keyColumn="symbol")

attachments-2021-09-Z5ZcaWtB613a0b4e39005.PNG


edit 1:

with help from Shena Mao I write code successfully. But when I entered the OHLC values in table, the reactive engine didn't fetch any results. Very strange ! Please reply as soon as possible ! Thank you.

Code:








attachments-2021-09-t0gcX3Gp613af6acc37ad.PNG

edit 3:-

adjusted the code slightly as under, it gave me results but results seems broken.


attachments-2021-09-gAi9HSg2613b12e86784f.PNG

edit 4 :-

tried defining bBands as Xiaohua Zhou suggested me. And it worked !! Thank you Xiaohua Zhou for your efforts !






attachments-2021-09-t16gc3oN613b951aaa316.PNG

please give me some time I will check with all indicators that I need and reply to this thread. Great work Xiaohua Zhou & Shena Mao ! Thank you both of you.

edit 5:-

I have made list of all Indicators I need for custom State Function. They are as under. Basically I want to use this strategy for my project https://chartink.com/screener/copy-double-volume-dhamaka-pro-444

Please help me define these Indicators as Custom State function so I can use them with Reactive State Engine.

ADX

ADX DI Positive

ADX DI Negative

Slow Stochastic %K

MACD

MFi

Cci

StochRsi

Rsi

VWAP

Parabolic Sar

Supertrend

Thank you and reply as soon as possible !

请先 登录 后评论

2 个回答

Xiaohua Zhou

bBands in TA module is not a state function. Therefore can't directly use in reactive engine.

I slightly modify the code and adapt it to a state function as follows:

@state
def bBands(close, timePeriod, nbdevUp, nbdevDn){
    mid = mavg(close, timePeriod)
    md = mstdp(close, timePeriod)
    return (mid + nbdevUp * md, mid, mid - nbdevDn * md)
}

Here I assume you are using simple moving average.

请先 登录 后评论
Shena Mao

Hi Vishvesh, glad to see you are using our ReactiveStateEngine.

the function "bBands" should return 3 columns, however, here it is a tuple which contains 3 vectors. Actually, we want each vector to be a column in the result table,right? Simply rewrite like this:

engine1 = createReactiveStateEngine(name="demo1", metrics=[<bBands(close,5,2,1,5)[0]>,<bBands(close,5,2,1,5)[1]>,<bBands(close,5,2,1,5)[2]>], dummyTable=dummy, outputTable=resultTable, keyColumn="symbol")

and then, it works! :-)

请先 登录 后评论
  • 3 关注
  • 0 收藏,1580 浏览
  • Vishvesh Upadhyay 提出于 2021-09-09 21:23

相似问题