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")
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:
edit 3:-
adjusted the code slightly as under, it gave me results but results seems broken.
edit 4 :-
tried defining bBands as Xiaohua Zhou suggested me. And it worked !! Thank you Xiaohua Zhou for your efforts !
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 !