ta-lib-rt
ta-lib-rt copied to clipboard
Changing lookback period while having data
Hello,
Is there a way to change a lookback period (such as optInTimePeriod while already posted data. I am in a situation that I set the period say to 30 but then I get only 20 data points, I will not get more, and would like to tell talib to use whatever data it already has and not to wait for the last 10 data points.
Thank you, Pavel
Hi, You may destroy the state with old optInTimePeriod, then create a new state and reprocess all received data again. Or you may even call a regular TA-Lib function for whole received data to process it at one function call.
TA-Lib isn't storing data internally - user must prepare an array of input values and allocate array of output values. Then TA-Lib process input array and write results to the output array. TA-Lib RT's state functions accepts a single input value and return a single output value and expected to be called in a loop. Some of indicators (like rolling functions) might have a piece of data buffer allocated in their state objects which might contain a piece of recently processed input values. Or something else. This buffer size is usually not bigger than lookback value. And some indicators doesn't have this buffer at all in their state objects.
This means in general if you need to change optInTimePeriod value - you must reprocess whole received data from very beginning. And if you didn't store received data as backup somewhere while using a state functions - then in general it won't be possible to do. In some cases part of received data (may be even all of it for 20 points and 30-day period case) could be still retrieved from state object, but this will be a hackery and very specific case dependant.
Just so you know I did not write this code just translated it from C to C#. Here are the steps used to create this I just needed a C# version of it for a trade engine.
- downloaded ta-lib https://www.ta-lib.org/hdr_dw.html2) built it using cmake https://cmake.org/3) compiled it as a dot net project in "DEBUG" mode. (NOTE : You must use DEBUG mode or the variable names disappear)4) installed dot net reflector in Visual studio and decompiled it https://www.red-gate.com/products/dotnet-development/reflector/ 5) wrote a custom app to break the 100k lines of a single file of code into individual routines.6) manually cleaned up the code.
David
On Saturday, May 14, 2022, 04:34:10 AM EDT, Alexander Trufanov ***@***.***> wrote:
Hi, You may destroy the state with old optInTimePeriod, then create a new state and reprocess all received data again. Or you may even call a regular TA-Lib function for whole received data to process it at one function call.
TA-Lib isn't storing data internally - user must prepare an array of input values and allocate array of output values. Then TA-Lib process input array and write results to the output array. TA-Lib RT's state functions accepts a single input value and return a single output value and expected to be called in a loop. Some of indicators (like rolling functions) might have a piece of data buffer allocated in their state objects which might contain a piece of recently processed input values. Or something else. This buffer size is usually not bigger than lookback value. And some indicators doesn't have this buffer at all in their state objects.
This means in general if you need to change optInTimePeriod value - you must reprocess whole received data from very beginning. And if you didn't store received data as backup somewhere while using a state functions - then in general it won't be possible to do. In some cases part of received data (may be even all of it for 20 points and 30-day period case) could be still retrieved from state object, but this will be a hackery and very specific case dependant.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Pavel Please explain and include code, and which TA function you are asking about, there are roughly 150 in the library.
As a guess ....
In many cases, the current value is calculated on past values, and they require more data than the chart you are creating, or data you are using shows. To use your numbers (30, 20, 10). Lets say, you want data from an simple MA of 10 for 20 data points, that requires 30 HLOC (high low open close) of data. The first data point your are calculating requires 10 bars, and then you require the next 20 bars for your use. ex 10 TP Moving average -10......0......10......20 ^ Your usable data starts at 0, with 20 being what ever "current time" you are calculating. David
On Friday, May 13, 2022, 06:08:03 PM EDT, sunpavlik ***@***.***> wrote:
Hello,
Is there a way to change a lookback period (such as optInTimePeriod while already posted data. I am in a situation that I set the period say to 30 but then I get only 20 data points, I will not get more, and would like to tell talib to use whatever data it already has and not to wait for the last 10 data points.
Thank you, Pavel
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>