Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, Aku_Aku, 1 invisible), 579 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Get length of a series() #486636
09/13/22 09:28
09/13/22 09:28
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

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:

Code
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: NorbertSz] #486637
09/13/22 09:35
09/13/22 09:35
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Try this:

int Length = *(int*)&(asd+1);

Untested, so please post here if it does not work.

Re: Get length of a series() [Re: jcl] #486638
09/13/22 10:05
09/13/22 10:05
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
Not working, compile error:
Code
error C2102: '&' requires l-value

Re: Get length of a series() [Re: NorbertSz] #486642
09/13/22 11:50
09/13/22 11:50
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Yes, I've just seen that the lenght cannot be retrieved from the var pointer offset, but needs an extra variable. This will be implemented in the next version.

Re: Get length of a series() [Re: jcl] #486643
09/13/22 12:22
09/13/22 12:22
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
Nice, thank you!

Re: Get length of a series() [Re: NorbertSz] #486645
09/13/22 14:22
09/13/22 14:22
Joined: Apr 2022
Posts: 21
H
HamzaAhmed Offline
Newbie
HamzaAhmed  Offline
Newbie
H

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: NorbertSz] #486652
09/13/22 16:02
09/13/22 16:02
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Or you can use C++ scripts instead and use std::vector<var> directly!

That said, series() is already optimized, and getting its length would indeed be a very useful feature, especially when backtesting many assets with different start dates.

Re: Get length of a series() [Re: AndrewAMD] #486657
09/14/22 06:56
09/14/22 06:56
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

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
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
I see in the beta news: SeriesLength. Do you mean this feature?

SeriesLength
int, r/o, containing the number of elements of the date series returned by the last series() call.
https://zorro-project.com/manual/en/series.htm

With 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:

Code
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:

Code
vars a = series(0, 100);
int length = a.length();


Or like this:

Code
vars a = series(0, 100);
int length = getSeriesLength(a);

Last edited by NorbertSz; 09/15/22 11:18.
Re: Get length of a series() [Re: NorbertSz] #486663
09/15/22 13:19
09/15/22 13:19
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
series() is already context-based, and so is SeriesLength.

A C++ script writer can write one function that returns a struct/tuple of vars and int by wrapping series() and SeriesLength.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1