Calculate daily indicator in intra day script

Posted By: dr_panther

Calculate daily indicator in intra day script - 08/29/16 10:43

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
Posted By: dr_panther

Re: Calculate daily indicator in intra day script - 08/30/16 17:46

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);
	}

}

Posted By: dr_panther

Re: Calculate daily indicator in intra day script - 08/30/16 19:18

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);
	}

}

Posted By: jcl

Re: Calculate daily indicator in intra day script - 08/30/16 19:44

"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."

Posted By: dr_panther

Re: Calculate daily indicator in intra day script - 08/30/16 19:53

what is meant by fixed order, sorry if this question is stupid, but I don't get it.
Posted By: jcl

Re: Calculate daily indicator in intra day script - 08/31/16 08:35

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
© 2024 lite-C Forums