Lookback error? (noob alert)

Posted By: BobbyT

Lookback error? (noob alert) - 07/03/17 17:42

I have written the below ultra-simple strategy to get familiar with zorro (never mind the commented lines lines they are there for me to play with and have no impact on the issue at hand).
Code:
function CheckRSI() 
{
	TimeFrame = 1; //multiplier for BarPeriod, set BarPeriod = 1 then set TimeFrame = x for different timeframes of the same function
	vars Close = series(priceClose()); //sets up a price series based on the current asset/TimeFrame (used for indi)
	//vars RSIsignal = series(RSI(Close, optimize(14,2,34,2))); 
	vars RSIsignal = series(RSI(Close, 14)); //create the indicator series (period can be optimised later)
	//var RSIthreshHigh = optimize(75,55,100,5); 
	var RSIthreshHigh = 75; //set an upper threshold (can be optimised later)
	//var RSIthreshLow = optimize(25,0,45,5); 
	var RSIthreshLow = 25; //set an lower threshold (can be optimised later)
	
	//trade decision
	if(crossOver(RSIsignal, RSIthreshLow))
		reverseShort(1); //close short trades and open a long position
	if(crossUnder(RSIsignal, RSIthreshHigh))
		reverseLong(1); //close long trades and open a short position	
}

//~equivalent to MQL4 OnTick()
function run()
{
	//set(PARAMETERS);  // generate and use optimized parameters
	BarPeriod = 60;
	LookBack = 34; //set to the worst case scenario, RSI period is 14 so this is easy for now
	StartDate = 2010;
	EndDate = 2015;
	//NumWFOCycles = 10; // activate WFO
	
	//carry out trade decisions/operations
	CheckRSI();	
	
	//plot the results
	set(LOGFILE);
	//PlotWidth = 600;
	//PlotHeight1 = 300;
	plot("Signal",series(RSI(series(priceClose()), 14)),NEW,RED);
	plot("Threshold1",75,0,BLACK);
	plot("Threshold2",25,0,BLACK);
	set(PLOTNOW);
}



When I run this script it seems that both the RSI period and LookBack period are doing whatever they please and ignore their set values. Here is the output from the zorro terminal.
Code:
basketWorkup compiling..........
Lookback set to 55 bars
Test: basketWorkup AUD/CAD 2010..2015
Error 014: Function RSI Timeperiod 54 > LookBack 34!
Error 014: Function RSI Timeperiod 54 > LookBack 34!
Error 030 - Check lookback, settings, asset order
Chart...Error 047: No bars to plot! ok



I don't get it. It's likely a real noob oversight but I have gone over the code a number of times and compared it to the workshop examples and for the life of me can't put my finger on what's wrong here. Any help would be greatly appreciated.

Cheers,
BobbyT
Posted By: GreenBoat

Re: Lookback error? (noob alert) - 07/04/17 05:49

Try to set LookBack to something higher, f.i. LookBack = 100
Posted By: jcl

Re: Lookback error? (noob alert) - 07/04/17 09:37

Or do not set Lookback at all - normally Zorro knows what lookback period you need. RSI 14 does not mean that the lookback period can be 14.
Posted By: BobbyT

Re: Lookback error? (noob alert) - 07/04/17 15:53

Hi guys,

Yes, setting it to a higher period does indeed fix the issue.

What has got me really confused though is this line in the zorro terminal:

Code:
Error 014: Function RSI Timeperiod 54 > LookBack 34!



Why am I being told the RSI time period is 54 when it is set as 14.
Indeed, setting a longer lookback or not setting one at all allows the script to run error free but...the above quoted message has me wondering if it is even running with the right indicator variables.

Any clues as to the source of 'RSI timeperiod 54' message?

Cheers,
BobbyT
Posted By: jcl

Re: Lookback error? (noob alert) - 07/04/17 16:59

54 is simply the lookback period needed for a RSI(14). The period is greater than 14 because the RSI is a cumulative indicator.
Posted By: BobbyT

Re: Lookback error? (noob alert) - 07/04/17 17:12

Even if it is cumulative shouldn't it only need RSIperiod worth of data to calculate it's first value. At worst I could see it requiring 2*RSIperiod so it can step over a full window to get rid of any 'noise' in the early values.

Again my coding experience lies mostly in R and MQL4 and this kind of behavior is not seen there. I'm just a little confused smirk

Is there some way to calculate what an indicators lookback requirements will be relative to it's settings (so that I can deal with this when it comes up again)?

Cheers,
BobbyT
Posted By: jcl

Re: Lookback error? (noob alert) - 07/04/17 17:29

Not always in a simple way, but in the case of RSI it is easy. Just add 14 and 40. Look for details in the manual under "Unstable Period": http://manual.zorro-project.com/lookback.htm

Posted By: BobbyT

Re: Lookback error? (noob alert) - 07/04/17 17:42

Awesome. Thanks JCL. Looks like I need to RFTM a bit more closely. It's easy to get blindsided when you're trying to address a stack of things at the same time.

That's great that that has been addressed automatically by the terminal. It's something that often requires a bit of tweaking in other platforms to get past that unstable period.

Big ups laugh

Cheers,
BobbyT
© 2024 lite-C Forums