3 registered members (7th_zorro, Aku_Aku, 1 invisible),
579
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Get length of a series()
#486636
09/13/22 09:28
09/13/22 09:28
|
Joined: Jan 2022
Posts: 58
NorbertSz
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2022
Posts: 58
|
Dear all, Is there a solution for getting the length of a series()? I have multiple series with different lengths, and a function is iterating through the series. It would be nice if I would not needed to store and pass the length as function parameter, just get that inside the function. For example like the C++ <vector> does: vars asd = series (0, 100);
if (asd.length() == 100) printf("yep, it's 100");
doSomethingWithEveryElement(asd);
...
void doSomethingWithEveryElement(vars* s){
for (int i = 0; i < (*s).length(); i++){
doSomething((*s)[i]);
}
}
Last edited by NorbertSz; 09/13/22 09:37.
|
|
|
Re: Get length of a series()
[Re: jcl]
#486643
09/13/22 12:22
09/13/22 12:22
|
Joined: Jan 2022
Posts: 58
NorbertSz
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2022
Posts: 58
|
|
|
|
Re: Get length of a series()
[Re: NorbertSz]
#486645
09/13/22 14:22
09/13/22 14:22
|
Joined: Apr 2022
Posts: 21
HamzaAhmed
Newbie
|
Newbie
Joined: Apr 2022
Posts: 21
|
Shouldn't Dynamic arrays by Andrew Dolder help your case. Dynamic arrays Library by Andrew Dolder for dynamic arrays in lite-C using std::vectors. Dynamic Arrays
|
|
|
Re: Get length of a series()
[Re: AndrewAMD]
#486657
09/14/22 06:56
09/14/22 06:56
|
Joined: Jan 2022
Posts: 58
NorbertSz
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2022
Posts: 58
|
Yes, I switched to C++ in the last few weeks: using OOP, destructor, function overloading and vectors were huge improvements in my code. It became much cleaner and easier. But in this specific case it's about the prices. I have multiple price series() in different TimeFrames, and different lengths. And as I see the series() is perfect for storing the prices, because - the automatic shifting on new Bar
- changing the pointer on Asset change
- the built-in indicators and functions are also using series
So I want to keep the prices in series() instead of Dynamic Arrays or vectors. But thank you for the ideas!
Last edited by NorbertSz; 09/14/22 07:03.
|
|
|
Re: Get length of a series()
[Re: jcl]
#486661
09/15/22 08:50
09/15/22 08:50
|
Joined: Jan 2022
Posts: 58
NorbertSz
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2022
Posts: 58
|
I see in the beta news: SeriesLength. Do you mean this feature? SeriesLengthint, r/o, containing the number of elements of the date series returned by the last series() call. https://zorro-project.com/manual/en/series.htmWith this way I still need to store the series length somewhere. Because what if I want to get the length of a series, but not the last one I called by the command series()? Or do some calculations with multiple series? For example like this:
double doSomething(var* series){
for (int i = 0; i<(*series).length(); i++){
//...calc something
}
}
double doSomethingElse(var* series, var* series2){
for (int i = 0; i<(*series).length(); i++){
for (int j = 0; j<(*series2).length(); j++){
//...calc something with (*series)[i] and (*series2)[j]
}
}
}
...
function run(){
...
priceM1 = series(priceClose(0), 100);
TimeFrame = 5;
priceM5 = series(priceClose(0), 250);
double result = 0;
double someThing1 = doSomething(&priceM1);
if (someThing1 >= 0.5){
double someThing2 = doSomething(&priceM5);
if (someThing2 >= 0.5){
result = doSomethingElse(&priceM1, &priceM5);
}
}
...
}
It would be nice if I could ask exactly from the series itself. For example like this: vars a = series(0, 100);
int length = a.length(); Or like this: vars a = series(0, 100);
int length = getSeriesLength(a);
Last edited by NorbertSz; 09/15/22 11:18.
|
|
|
|