Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/20/24 06:09
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
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
2 registered members (flink, Edgar_Herrera), 695 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
query past values #475089
11/22/18 16:59
11/22/18 16:59
Joined: Jun 2018
Posts: 16
P
Paul_der_Zweite Offline OP
Newbie
Paul_der_Zweite  Offline OP
Newbie
P

Joined: Jun 2018
Posts: 16
Sorry i'm a newbie ...
I have a small problem, which is probably very easy to solve:

How can I query past values, here the indicator value KAMA from before n candles correctly and then use it again?
My state of knowledge: I define a series (here: vars kama = KAMA(Price,10) and can then address a certain point in time n (shift or candles in the past) with series[n] (here: kama[n]).

The following part of my script:
Code:
vars Price = series(priceClose());
vars kama = KAMA(Price,10);
var close_kama(int n)
 {
	return  kama[n] / priceClose(n);
 }

vars cycle = DominantPeriod(Price,100);
var cycle_multi = 2;
var close_res(int n)
{
	return priceClose(n) / HH(cycle[n]*cycle_multi,n+1);
}

var close_sup(int n)
{
	return priceClose(n) / LL(cycle[n]*cycle_multi,1);
}


causes the following error:
Code:
Error 111: Crash in function: close_kama() at bar 0



What am I doing wrong?
Everything?
grin

Re: query past values [Re: Paul_der_Zweite] #475090
11/22/18 17:52
11/22/18 17:52
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
Wrap your indicators in a series, like you did with Price.
Like so,

series(KAMA(Price,10));

Re: query past values [Re: Dalla] #475091
11/22/18 18:51
11/22/18 18:51
Joined: Jun 2018
Posts: 16
P
Paul_der_Zweite Offline OP
Newbie
Paul_der_Zweite  Offline OP
Newbie
P

Joined: Jun 2018
Posts: 16
Hi, thank you so much for your answer:

I changed the script as follows:
Code:
vars Price = series(priceClose());
vars kama = series(KAMA(Price,10));
var close_kama(int n)
 {
	return  kama[n] / priceClose(n);
 }

vars cycle = series(DominantPeriod(Price,100));
var cycle_multi = 2;
var close_res(int n)
{
	return priceClose(n) / HH(cycle[n]*cycle_multi,n+1);
}

var close_sup(int n)
{
	return priceClose(n) / LL(cycle[n]*cycle_multi,n+1);
}


But the error output remains the same.

Last edited by Paul_der_Zweite; 11/22/18 18:52.
Re: query past values [Re: Paul_der_Zweite] #475094
11/22/18 22:05
11/22/18 22:05
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
Can you paste all of your code? there is no run function here

Re: query past values [Re: Dalla] #475095
11/22/18 23:14
11/22/18 23:14
Joined: Jun 2018
Posts: 16
P
Paul_der_Zweite Offline OP
Newbie
Paul_der_Zweite  Offline OP
Newbie
P

Joined: Jun 2018
Posts: 16
Sure, here's the whole script:
Code:
#include <r.h>

vars Price = series(priceClose());
vars kama = series(KAMA(Price,10));
var close_kama(int n)
 {
	return  kama[n] / priceClose(n);
 }

vars cycle = series(DominantPeriod(Price,100));
var cycle_multi = 2;
var close_res(int n)
 {
	return priceClose(n) / HH(cycle[n]*cycle_multi,n+1);
 }

var close_sup(int n)
 {
	return priceClose(n) / LL(cycle[n]*cycle_multi,n+1);
 }
///////////////////////////////////////////////////////////////////////
function run()
{
	StartDate = 20160101;
	BarPeriod = 120;
	LookBack = 100;
	WFOPeriod = 22*288;
	DataSplit = 90;
	NumCores = -1;
	if(is(TRADEMODE|TESTMODE))
		Hedge = 5; 
		else
		Hedge = 2;  // full hedging in train mode

	
	set(RULES|LOGFILE|TESTNOW|PLOTNOW);
	//set(PARAMETERS|LOGFILE|TESTNOW|PLOTNOW);

	//LifeTime = 140;
	
	//Capital = 1000;		// reinvestment mode
	//Margin = 0.01 * OptimalF * Capital * sqrt(1 + ProfitClosed/Capital);
	//Stop = MedPrice(1) + 3 * ATR(14); 
	//TakeProfit = 3 * ATR(14);
	//TrailStep = 3 * ATR(14);
  	//Trail = ATR(14);
	//TrailLock = 80;
	
  
///////////////////////////////////////////////////////////	
	if(adviseLong(NEURAL,0,
		close_kama(1),close_kama(2),close_kama(3),close_kama(4),
		close_res(1),close_res(2),close_res(3),close_res(4),
		close_sup(1),close_sup(2),close_sup(3),close_sup(4)) > 0.5) 
		enterLong();

		if(adviseShort() > 0.5) 
		   enterShort();

	PlotWidth = 800;
	PlotHeight1 = 340;
	ColorUp = ColorDn = ColorWin = ColorLoss = 0;
}


Re: query past values [Re: Paul_der_Zweite] #475120
11/23/18 19:56
11/23/18 19:56
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
You need to place your series inside the run function, that's the function that will run on every bar.

Re: query past values [Re: Dalla] #475145
11/25/18 17:34
11/25/18 17:34
Joined: Jun 2018
Posts: 16
P
Paul_der_Zweite Offline OP
Newbie
Paul_der_Zweite  Offline OP
Newbie
P

Joined: Jun 2018
Posts: 16
Mmh, the basic idea of the script or the basic structure comes from financial-hacker.com. The original script can be downloaded there [x] and looks like this:

Code:
///////////////////////////////////////////////////////////////////////
#include <r.h>

var change(int n)
{
	return scale((priceClose(0) - priceClose(n))/priceClose(0),100)/100;
}

var range(int n)
{
	return scale((HH(n) - LL(n))/priceClose(0),100)/100;
}

///////////////////////////////////////////////////////////////////////

function run()
{
	StartDate = 20140601;
	BarPeriod = 60;	// 1 hour
	LookBack = 100;

	WFOPeriod = 252*24; // 1 year
	DataSplit = 90;
	NumCores = -1;

	set(RULES|LOGFILE|TESTNOW|PLOTNOW);
	Spread = RollLong = RollShort = Commission = Slippage = 0;
	LifeTime = 3;
	if(Train) Hedge = 2;
	
///////////////////////////////////////////////////////////	
	if(adviseLong(NEURAL+BALANCED,0,
		change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4)) > 0.5) 
		enterLong();
	if(adviseShort() > 0.5) 
		enterShort();

	PlotWidth = 800;
	PlotHeight1 = 340;
	ColorUp = ColorDn = ColorWin = ColorLoss = 0;
}



The corresponding part of the script runs in a run function, but some functions are outside this function, but are queried from it.
Not okay?

Not okay?


[x] http://financial-hacker.com/scripts2016.zip

Re: query past values [Re: Paul_der_Zweite] #475149
11/25/18 22:20
11/25/18 22:20
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Not okay. Do not use series() outside of run(). Use it inside run() instead.

Re: query past values [Re: AndrewAMD] #475166
11/26/18 12:11
11/26/18 12:11
Joined: Jun 2018
Posts: 16
P
Paul_der_Zweite Offline OP
Newbie
Paul_der_Zweite  Offline OP
Newbie
P

Joined: Jun 2018
Posts: 16
Okay, thank you very much for your answers. I got it. grin


Moderated by  Petra 

Gamestudio download | chip programmers | 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