Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 16,415 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Using price series without actually using series #484151
09/16/21 19:22
09/16/21 19:22
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
I often ran into problems with wrong series usage. I'm working on a script, which needs an indicator which is calculated from a price series only when a trade is entered. This gave me the idea, to just completely skip any series usage. The solution I came up with is this:

Code
var* NoSeries(int period, int mode, ...)
{
	int i;
	var* Series = zalloc(period*sizeof(var));
	for(i=0; i<period; i++)
	{
		if(mode == 0) Series[i] = price(i);
		if(mode == 1) Series[i] = priceOpen(i);
		if(mode == 2) Series[i] = priceHigh(i);
		if(mode == 3) Series[i] = priceLow(i);
		if(mode == 4) Series[i] = priceClose(i);
	}
	return Series;
}


function run() 
{
	LookBack = 100;
	BarPeriod = 60;
	asset("EUR/USD");
	
	
	//if(Init) mySeries = zalloc(100*sizeof(var));
	var ZorroEMA = EMA(series(price()), 30);
	

	var* test = NoSeries(70);
	
	
	var myEMA = EMA(test, 30);
	printf("\n%.5f, Zorro:%.5f", myEMA, ZorroEMA);
	
}


Notice that I implemented an option to chose between different price options.

Re: Using price series without actually using series [Re: Smon] #484153
09/16/21 22:10
09/16/21 22:10
Joined: Feb 2017
Posts: 1,806
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,806
Chicago
zalloc returns a temporary pointer. It expires if you call zalloc enough times. You don’t have this problem with series().

Re: Using price series without actually using series [Re: AndrewAMD] #484212
09/21/21 19:18
09/21/21 19:18
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
Oh yes, thank you! I think this should be fine with malloc(), right?

Re: Using price series without actually using series [Re: Smon] #484213
09/21/21 19:25
09/21/21 19:25
Joined: Feb 2017
Posts: 1,806
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,806
Chicago
Yes. As always, don’t forget to free().


Moderated by  Petra 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1