Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (alibaba, howardR, basik85278), 756 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Lookback error? (noob alert) #466814
07/03/17 17:42
07/03/17 17:42
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
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

Re: Lookback error? (noob alert) [Re: BobbyT] #466825
07/04/17 05:49
07/04/17 05:49
Joined: Nov 2016
Posts: 66
GreenBoat Offline
Junior Member
GreenBoat  Offline
Junior Member

Joined: Nov 2016
Posts: 66
Try to set LookBack to something higher, f.i. LookBack = 100

Re: Lookback error? (noob alert) [Re: GreenBoat] #466829
07/04/17 09:37
07/04/17 09:37
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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.

Re: Lookback error? (noob alert) [Re: jcl] #466840
07/04/17 15:53
07/04/17 15:53
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
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

Re: Lookback error? (noob alert) [Re: BobbyT] #466845
07/04/17 16:59
07/04/17 16:59
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
54 is simply the lookback period needed for a RSI(14). The period is greater than 14 because the RSI is a cumulative indicator.

Re: Lookback error? (noob alert) [Re: jcl] #466846
07/04/17 17:12
07/04/17 17:12
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
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

Re: Lookback error? (noob alert) [Re: BobbyT] #466848
07/04/17 17:29
07/04/17 17:29
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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


Re: Lookback error? (noob alert) [Re: jcl] #466851
07/04/17 17:42
07/04/17 17:42
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
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


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1