Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (PeroPero), 788 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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.

Re: Get length of a series() [Re: AndrewAMD] #486664
09/15/22 16:24
09/15/22 16:24
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
Yes I can wrap it. Or I can store and get the length of the series with a pointer map, like this:

Code
#include <map>
#include <zorro.h>

using namespace std;

int getSeriesLength(var* s);
map<int, int> seriesLength;

DLLFUNC void run(){
	BarPeriod = 60;
	LookBack = 100;
	asset("EUR/USD");
	
	vars price60 = series(price(0), 20);
	seriesLength.insert(pair<int, int>((int)price60, 20));
	TimeFrame = 4;
	vars price240 = series(price(0), 5);
	seriesLength.insert(pair<int, int>((int)price240, 5));
	
	if (!is(LOOKBACK)){
		printf("\n%d %d", getSeriesLength(price60), getSeriesLength(price240));
		quit(0);
	}
}

int getSeriesLength(var* s){
	return seriesLength.at((int)s);
}


I'm just saying it would be nice if series could store its own length natively, therefore we don't need to handle that information with these tricks.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1