Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by jcl. 04/20/24 08:52
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
5 registered members (7th_zorro, Aku_Aku, henrybane, flink, 1 invisible), 712 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
Calculate daily indicator in intra day script #461912
08/29/16 10:43
08/29/16 10:43
Joined: Aug 2016
Posts: 61
D
dr_panther Offline OP
Junior Member
dr_panther  Offline OP
Junior Member
D

Joined: Aug 2016
Posts: 61
How can I calculate a daily indicator in a intra day script.

I tried this:

Code:
BarPeriod = 60;
TimeFrame = frameSync(24); 
ATR = ATR(10) ;
TimeFrame =  frameSync(1);
// more hourly stuff



and get the error: Error 041: Inconsistent series!

Any help apriciated.
dr_panther

Re: Calculate daily indicator in intra day script [Re: dr_panther] #461951
08/30/16 17:46
08/30/16 17:46
Joined: Aug 2016
Posts: 61
D
dr_panther Offline OP
Junior Member
dr_panther  Offline OP
Junior Member
D

Joined: Aug 2016
Posts: 61
Here is a full code, please can someone give me a hint, what I am doing wrong.

Code:
static int debug = 1;
 
var dailyATR() {
  TimeFrame = 4; // when this line is commented, it works fine
  var atr10=ATR (10);
    
  if(debug && Bar > LookBack) 
     debug = msg("\ndailATR()\nATR10 %f\nTimeFrame %d\nStartDate: %d\nStop:%.4f \nTrail: %.4f,\nBarPeriod %.0f\nLoopback %d", 
	 atr10, TimeFrame, StartDate , Stop, Trail, BarPeriod, LookBack);
  return atr10;	
}

function run()
{

//set(LOGFILE);
set(STEPWISE);
StartDate = 20160101;
EndDate = 20160825;
StartWeek = 10000;
Stop = PIP*25;
Trail = PIP*25;
BarPeriod = 60;
LookBack = 60*4 ;


asset("EUR/USD");

TimeFrame =  1;
 

vars Price = series(price());
 
if (hour() == 0){

 	var  dailyATR = dailyATR(); 
   
	var hourlyATR=ATR (10);

	if(debug && Bar > LookBack) 
	     debug = msg("\nrun()\nATR10_daily %f\nATR10_hourly %f\nTimeFrame %d\nStartDate: %d\nStop:%.4f \nTrail: %.4f,\nBarPeriod %.0f\nLoopback %d", 
		 dailyATR ,hourlyATR, TimeFrame, StartDate , Stop, Trail, BarPeriod, LookBack);
	}

}


Re: Calculate daily indicator in intra day script [Re: dr_panther] #461953
08/30/16 19:18
08/30/16 19:18
Joined: Aug 2016
Posts: 61
D
dr_panther Offline OP
Junior Member
dr_panther  Offline OP
Junior Member
D

Joined: Aug 2016
Posts: 61
Answering my own question, as it seems to be a general problem, I still don't understand.
However I had to move the calculation of the ATR outside of the if
clause. Can someone comment, why this is needed.

Code:
static int debug = 1;
 
var dailyATR() {
  TimeFrame = 4;  
  var atr10=ATR (10);
  return atr10;	
}

function run()
{

//set(LOGFILE);
set(STEPWISE);
StartDate = 20160101;
EndDate = 20160825;
StartWeek = 10000;
Stop = PIP*25;
Trail = PIP*25;
BarPeriod = 60;
LookBack = 60*4 ;

asset("EUR/USD");

var  dailyATR = dailyATR(); 
TimeFrame =  1;
var hourlyATR=ATR (10); 
if (hour() == 0){
	if(debug && Bar > LookBack) 
	     debug = msg("\nrun()\nATR10_daily %f\nATR10_hourly %f\nTimeFrame %d\nStartDate: %d\nStop:%.4f \nTrail: %.4f,\nBarPeriod %.0f\nLoopback %d", 
		 dailyATR ,hourlyATR, TimeFrame, StartDate , Stop, Trail, BarPeriod, LookBack);
	}

}


Re: Calculate daily indicator in intra day script [Re: dr_panther] #461954
08/30/16 19:44
08/30/16 19:44
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
"ATR(int TimePeriod): var
Average True Range. A measure of price volatility; useful for calculating stop loss or profit target distances. Formula: ATR = (ATR1 * (TimePeriod-1) + max(High,Close)-min(Low,Close)) / TimePeriod, where ATR1 is the ATR from the last bar. Uses the current asset prices. The function internally creates series when TimeFrame is > 1, and must then be called in a fixed order in the script."


Re: Calculate daily indicator in intra day script [Re: jcl] #461955
08/30/16 19:53
08/30/16 19:53
Joined: Aug 2016
Posts: 61
D
dr_panther Offline OP
Junior Member
dr_panther  Offline OP
Junior Member
D

Joined: Aug 2016
Posts: 61
what is meant by fixed order, sorry if this question is stupid, but I don't get it.

Re: Calculate daily indicator in intra day script [Re: dr_panther] #461960
08/31/16 08:35
08/31/16 08:35
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
It means that if you have series A,B,C, you must call them always in the same order: first A, then B, then C. Not sometimes A and sometimes B and sometimes nothing, as in your original script where you did not call the ATR in every run. The error messages and their reasons are listed in the manual: http://manual.zorro-project.com/errors.htm


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1