You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating a new indicator and have copied parts from BBANDS. I am getting an error on one of the variables and I cannot seem to figure out why I am getting this error. Can you @mrjbq7 or @trufanov-nok can either of you help plz?
tempBuffer2 is the one that is causing the issue.
I am trying to have an equivalent of the following line of code:
You need to learn how arrays in C are designed. double* is a pointer in memory to a first double element of an array. And you can't just divide array by array or make any other operations over arrays - it won't work, they are not objects. You need to iterate both arrays in a loop and devide each element. It's not a TA-Lib related issue. it's a C knowlage related issue. You may better to ask on stackoverflow or something.
You are probably using ARRAY_REF. That's a template which is declared in ta_memory.h. And it's value is type *name. Which means ARRAY_REF(tempBuffer1); will be substituted by ARRAY_VTYPE_REF(double, name) and its turn by a double* tempBuffer1; during compilation by a C preprocessor. That only a pointer to a first element in array. Pointer to memory. But memory isn't allocated. So you need to use ARRAY_ALLOC(name,size) and ARRAY_FREE(name) templates instead to not only declare a pointer, but also allocate and deallocate a memory for an array at the end. name is tempBuffer1. The question is: what is the size? For ex., for tempBuffer1 I would try endIdx-startIdx-LOOKBACK_CALL(SMA)(optInTimePeriod);. Similar for a second buffer.
@trufanov-nok thank you. I was getting an error saying tempBuffer1 and 2 are uninitialized or something like that. I had to add the following code and it got rid of the error however I wanted to ask if this was the right thing to do or not.
ARRAY_REF(tempBuffer1);
ARRAY_REF(tempBuffer2);
Here is my full variable declaration:
/* insert local variable here */
ENUM_DECLARATION(RetCode) retCode;
int outBegIdx1, outBegIdx2;
int currentIdx, currentIdx1, currentIdx2;
int i;
ARRAY_REF(tempBuffer1);
ARRAY_REF(tempBuffer2);
ARRAY_ALLOC(tempBuffer1, optInTimePeriod);
ARRAY_ALLOC(tempBuffer2, optInTimePeriod);
I was able to build both and access to RVSTDEV from python, so the problem must be in environment.
The name of the function in your copy is different. Your screenshot says RCSTDEV. My function was called RVSTDEV. Do you have one with a similar name or did you change the name?
@trufanov-nok I got it to work. I renamed my function and compiled it again and it seems to be working. I think it was just getting confused with STDDEV. I renamed my function to RVSTDDEV instead RVSTDEV
@trufanov-nok I need to get a couple of indicators coded and its over my head. Are you able to help me get these indicators done in talib? I will pay you for it.
Just note that the archive of ta-lib sources which are automatically downloaded by the wrapper when it's installed via pip isn't suitable for a new indicator addition bcs of lacking some files. So you'll need a dump of a whole latest sourcecode trunk from sourceforge. This have some consequences which will be shown later.
After successful creation of a new C indicator and compilation of a C library, one need to install it with make install or something like that. Read in console and remember there include/ta-lib/ta_func.h is stored.
Doublecheck that your new indicator is declared in this ta_func.h header. If it's not - you did something wrong in the C code.
Find any otherta_func.h files in default folders of your system and delete them, bcs TA-lib's wrapper will automatically search this header in your system using default paths. If it find an old one before reach up-to-date one - it won't get any info about your new indicator. The default folders are '/usr/include', '/usr/local/include', '/opt/include', '/opt/local/include', '/opt/homebrew/include', 'c:\ta-lib\c\include'.
Get the latest sources of TA-Lib's wrapper for python from this github project. The package in system repositories won't work and you'll need exactly the latest sources as they contain some fixes.
Uninstall all other python wrappers of TA-lib with pip uninstall ta-lib. Execute it a few times until it report that no any TA-Lib packages are installed.
In python's wrapper folder edit files ./tools/generate_func.py and ./tools/generate_stream.py. In both comment out (with #) lines from talib import abstract then comment out:
This will disable usage of TA-Lib's python package in these scripts for generation of documentation for indicators. It won't work anyway as scripts will parse your new ta_func.h, and will try to get a documentation for a new indicator which is unknown yet for the wrapper installed in the system. And according to the 6 I advised to uninstall all wrappers anyway, so it won't work.
Launch python3 tools/generate_func.py. This will print a lot of text (which is actually a new content of a _func.pxi) to the console. Check the last lines. If there are any errors - most probably you failed to perform step 7. If __TA_FUNCTION_NAMES__ is empty (__TA_FUNCTION_NAMES__ = []) - script can't find any ta_func.h file. If it contains a list of indicators names, but there is no your new one - then script catch ups some old ta_func.h and you failed step 4.
If everything is okay, overwrite files talib/_func.pxi and talib/_stream.pxi with a new content generated by these scripts, with:
Unfortunately there are few other files that need to be patched to add info about your new indicator. And there is no script to autopatch them. These are declarations in _ta_lib.pxd and (optionally) groups description in __init__.py.
Also, TA-Lib's wrapper is designed to be used with an old version of TA-Lib 0.4.24, while sourceforge's trunk contain 0.4.25. It has 3 more indicators than previous one. Which means that along with your new indicator you'll need to add the info about these 3. Indicators are: ACCBANDS, AVGDEV, IMI. Scripts will grab their description from ta_func.h and update talib/_func.pxi and talib/_stream.pxi, but following is still need to be added into _ta_lib.pxd manually:
TA_RetCode TA_ACCBANDS(int startIdx, int endIdx, const double inHigh[], const double inLow[], const double inClose[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outRealUpperBand[], double outRealMiddleBand[], double outRealLowerBand[])
int TA_ACCBANDS_Lookback(int optInTimePeriod)
TA_RetCode TA_AVGDEV(int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[])
int TA_AVGDEV_Lookback(int optInTimePeriod)
TA_RetCode TA_IMI(int startIdx, int endIdx, const double inOpen[], const double inClose[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[])
int TA_IMI_Lookback(int optInTimePeriod)
Do not forget to add definitions of the function for your new indicator there too.
Perform python3 setup.py build. In case of any errors check the messages. If it's about your new indicator - the problem is on step 10.
Perform sudo python3 setup.py install to install the wrapper binary. Launch python3 and execute import talib to check if everything is ok. DO NOT DO THIS FROM WRAPPERS SOURCECODE FOLDER - it won't work as python will try to load a local copy and fail. You may print a list of talib functions available from python side with talib.__TA_FUNCTION_NAMES__ and get its version with talib.__version__ to make sure wrapper loads the right wrapper and library.
Revert the changes made at step 7 and repeat steps 9-12 again to generate .pxi files with additional documentation and correct default values. Note: step 12 is mandatory to be done before 13.
Activity
mrjbq7 commentedon Jun 24, 2022
Are you trying to divide a
doubleby adouble*?hhashim1 commentedon Jun 24, 2022
What is a
double*?This is what I am trying to do.
rawRelVol = (volume - Average(volume, length)) / StDev(volume, length)tempBuffer2is meant to be theStDevvalue that is returned.I have copied the
Stdevcode fromBBANDS.trufanov-nok commentedon Jun 24, 2022
You need to learn how arrays in C are designed.
double*is a pointer in memory to a first double element of an array. And you can't just divide array by array or make any other operations over arrays - it won't work, they are not objects. You need to iterate both arrays in a loop and devide each element. It's not a TA-Lib related issue. it's a C knowlage related issue. You may better to ask on stackoverflow or something.hhashim1 commentedon Jun 24, 2022
Ok, so I made some changes and added a loop to iterate however I have a different issue now. I don't know how else to initialize the variable.
The error is
Using uninitialized memory "tempBuffer1"andUsing uninitialized memory "tempBuffer2"Here is the code:
Here is the screenshot:

trufanov-nok commentedon Jun 24, 2022
You are probably using ARRAY_REF. That's a template which is declared in ta_memory.h. And it's value is
type *name. Which means ARRAY_REF(tempBuffer1); will be substituted byARRAY_VTYPE_REF(double, name)and its turn by adouble* tempBuffer1;during compilation by a C preprocessor. That only a pointer to a first element in array. Pointer to memory. But memory isn't allocated. So you need to useARRAY_ALLOC(name,size)andARRAY_FREE(name)templates instead to not only declare a pointer, but also allocate and deallocate a memory for an array at the end. name is tempBuffer1. The question is: what is the size? For ex., for tempBuffer1 I would tryendIdx-startIdx-LOOKBACK_CALL(SMA)(optInTimePeriod);. Similar for a second buffer.hhashim1 commentedon Jun 24, 2022
For lookback, here is what I have.
return LOOKBACK_CALL(SMA)(optInTimePeriod);Here are my inputs:
hhashim1 commentedon Jun 24, 2022
@trufanov-nok given the below psuedo code, how would you code it in talib?
trufanov-nok commentedon Jun 24, 2022
I'll answer tomorrow.
hhashim1 commentedon Jun 24, 2022
Thank you
trufanov-nok commentedon Jun 25, 2022
I would start with something like that (didn't test it):
hhashim1 commentedon Jun 27, 2022
@trufanov-nok thank you. I was getting an error saying
tempBuffer1and 2 are uninitialized or something like that. I had to add the following code and it got rid of the error however I wanted to ask if this was the right thing to do or not.Here is my full variable declaration:
trufanov-nok commentedon Jun 27, 2022
You're rignt.
ARRAY_REFis atype *name. TheARRAY_ALLOCis only aname = (type *)TA_Malloc( sizeof(type)*(size)). So both are required.hhashim1 commentedon Jun 27, 2022
Ok, thanks @trufanov-nok I do have another error that I dont know how to fix.
Also, while running
makeafter running./configure --prefix=/usr, I get the following error. I dont know if the two are related.Thoughts?
trufanov-nok commentedon Jun 27, 2022
could you upload a whole code at pastebin?
hhashim1 commentedon Jun 27, 2022
Here you go...
https://pastebin.com/daPXyTJ1
59 remaining items
trufanov-nok commentedon Jun 29, 2022
I was able to build both and access to RVSTDEV from python, so the problem must be in environment.
hhashim1 commentedon Jun 29, 2022
The name of the function in your copy is different. Your screenshot says
RCSTDEV. My function was calledRVSTDEV. Do you have one with a similar name or did you change the name?trufanov-nok commentedon Jun 29, 2022
I just made a mistake when call it. Then I call it with a right name.
hhashim1 commentedon Jun 29, 2022
Oh sorry...I didnt see that.
hhashim1 commentedon Jun 29, 2022
What do you suggest for how to fix this?
trufanov-nok commentedon Jun 29, 2022
find all libta_lib* files on your linux machine with
sudo find / -iname "libta_lib*"and list the resultshhashim1 commentedon Jun 29, 2022
trufanov-nok commentedon Jun 29, 2022
What says
sudo find / -iname "_ta_lib.cpython*.so"?hhashim1 commentedon Jun 29, 2022
trufanov-nok commentedon Jun 29, 2022
you copied it wrong or something..
hhashim1 commentedon Jun 30, 2022
Sorry I had a quote at the end. This list goes on though. Rest of the list is permission denied because its on the Windows drive.
hhashim1 commentedon Jun 30, 2022
@trufanov-nok I got it to work. I renamed my function and compiled it again and it seems to be working. I think it was just getting confused with
STDDEV. I renamed my function toRVSTDDEVinsteadRVSTDEVhhashim1 commentedon Aug 20, 2022
@trufanov-nok I need to get a couple of indicators coded and its over my head. Are you able to help me get these indicators done in talib? I will pay you for it.
hhashim1 commentedon Aug 21, 2022
@trufanov-nok thats great. Thank you. I will email you. You can delete your email address from the comment above now. I have copied it.
trufanov-nok commentedon Aug 25, 2022
I've just passed the whole way from making a new indicator to adding it to the python's wrapper so I can write a little guide about that:
and this thread. It's pretty relevant to original TA-Lib sourcecode.
Just note that the archive of ta-lib sources which are automatically downloaded by the wrapper when it's installed via
pipisn't suitable for a new indicator addition bcs of lacking some files. So you'll need a dump of a whole latest sourcecode trunk from sourceforge. This have some consequences which will be shown later.make installor something like that. Read in console and remember thereinclude/ta-lib/ta_func.his stored.ta_func.hheader. If it's not - you did something wrong in the C code.ta_func.hfiles in default folders of your system and delete them, bcs TA-lib's wrapper will automatically search this header in your system using default paths. If it find an old one before reach up-to-date one - it won't get any info about your new indicator. The default folders are'/usr/include', '/usr/local/include', '/opt/include', '/opt/local/include', '/opt/homebrew/include', 'c:\ta-lib\c\include'.pip uninstall ta-lib. Execute it a few times until it report that no any TA-Lib packages are installed../tools/generate_func.pyand./tools/generate_stream.py. In both comment out (with#) linesfrom talib import abstractthen comment out:then add after them:
This will disable usage of TA-Lib's python package in these scripts for generation of documentation for indicators. It won't work anyway as scripts will parse your new
ta_func.h, and will try to get a documentation for a new indicator which is unknown yet for the wrapper installed in the system. And according to the 6 I advised to uninstall all wrappers anyway, so it won't work.python3 tools/generate_func.py. This will print a lot of text (which is actually a new content of a_func.pxi) to the console. Check the last lines. If there are any errors - most probably you failed to perform step 7. If__TA_FUNCTION_NAMES__is empty (__TA_FUNCTION_NAMES__ = []) - script can't find anyta_func.hfile. If it contains a list of indicators names, but there is no your new one - then script catch ups some oldta_func.hand you failed step 4.talib/_func.pxiandtalib/_stream.pxiwith a new content generated by these scripts, with:_ta_lib.pxdand (optionally) groups description in__init__.py.Also, TA-Lib's wrapper is designed to be used with an old version of TA-Lib 0.4.24, while sourceforge's trunk contain 0.4.25. It has 3 more indicators than previous one. Which means that along with your new indicator you'll need to add the info about these 3. Indicators are:
ACCBANDS, AVGDEV, IMI. Scripts will grab their description fromta_func.hand updatetalib/_func.pxiandtalib/_stream.pxi, but following is still need to be added into_ta_lib.pxdmanually:Do not forget to add definitions of the function for your new indicator there too.
python3 setup.py build. In case of any errors check the messages. If it's about your new indicator - the problem is on step 10.sudo python3 setup.py installto install the wrapper binary. Launchpython3and executeimport talibto check if everything is ok. DO NOT DO THIS FROM WRAPPERS SOURCECODE FOLDER - it won't work as python will try to load a local copy and fail. You may print a list of talib functions available from python side withtalib.__TA_FUNCTION_NAMES__and get its version withtalib.__version__to make sure wrapper loads the right wrapper and library.