Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (opm), 778 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Spreads and Zscores? #477450
06/27/19 20:59
06/27/19 20:59
Joined: Jun 2019
Posts: 14
B
bondo1 Offline OP
Newbie
bondo1  Offline OP
Newbie
B

Joined: Jun 2019
Posts: 14
Hey all,

Just recently got my subscription for Zorro S and am excited to port over some things I had, but I'm a super new programmer (only experience is with Tradingview's Pinescript and MC Easylanguage) so some of the syntax is causing me to hang up.

Couple of questions; I was playing around with spread creation by doing simple subtraction but can't seem to get the script to run, instead I get an error. For example, if I were to create a spread of EURUSD to GBPUSD, I wrote this;

-----------------------------------------------------------------------------
//Defining a 1 minute period
BarPeriod = 1;

//Defining the two assets used in spread calculation
asset("EURUSD");
vars APrice = series(priceClose()) ;

asset("GBPUSD");
vars BPrice = series(priceClose());

//Calculate spread
vars BSpread = series(APrice - BPrice);

//Plot the spread
plot("Spread",BSpread,NEW,PURPLE);
-----------------------------------------------------------------------------

When I go to run this, I get an error saying;

Error in 'line 17:
Syntax error: Wrong type SUB:POINTER:POINTER:POINTER
< vars BSpread = series(APrice - BPrice); >


From what I understand from the manual, it's saying it expected subtraction but I gave it three pointers? Not sure if I'm interpreting this correctly, can I get clarification here?

Then, I tried changing the spread calculation code to read;

//Calculate spread
vars BSpread = series(APrice[0] - BPrice[0]);

Using this, I produced no errors and was able to graph the spread. The issue here is, I'm also not sure how to interpret what my results were. My goal was to create a running series of the difference between the current closing prices between
two assets. Did this code work because the [0] indicates that I'm using only the most recent value of each asset at the time of calculation? I know that in Easylanguage the [number] refers to the counter, but I just wanted to make sure. Normally in Easylanguage,
I could do something like;

//Calculate spread
BSpread = APrice - BPrice

and I'd get the calculation without errors.

------------------------------------------------------------------------------

Second;

When I try to plot the zscore of my defined spread, I'm also producing an error similar to the subtraction error. I tried to follow the syntax in the manual here > https://manual.zorro-project.com/norm.htm

----------------------------------------------------------------------------- [Here's the code for it]

//Plot zscore of spread
plot("ZSCORE",zscore(BSpread,12),NEW,RED);

-----------------------------------------------------------------------------

The error I'm getting is;

Error in 'line 27:
Syntax error: Wrong type CONV:POINTER::DOUBLE
< plot("ZSCORE",zscore(BSpread,120),NEW,RED); >


Just to annotate, I tried to plot the zscore of the BSpread, over a time period of 120 minutes (with the number being arbitrary, just trying to get this thing to plot).

Also to note, the BSpread that I'm referring to is the BSpread from the above code. Running the script with or without the brackets produces the same error.

-----------------------------------------------------------------------------

Can anyone explain to me what I'm doing wrong/how to interpret some of these errors? I've combed through the forums and other resources but I'm still lost. I was able to pick up Easylanguage/Pinescript by learning off of public code, but
since there's a lack of that relating to specifically Zorro, I'm having some trouble.










Re: Spreads and Zscores? [Re: bondo1] #477451
06/27/19 21:22
06/27/19 21:22
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
This is wrong:

vars BSpread = series(APrice - BPrice);

Correct would be this:

var BSpread = APrice - BPrice;

Also wrong:

vars APrice = series(priceClose()) ;

Correct:

var APrice = priceClose();

Remove all those "series" and your code is a lot better. Use no functions if you do not know what they do and how to use them.

Re: Spreads and Zscores? [Re: bondo1] #477452
06/27/19 21:48
06/27/19 21:48
Joined: Jun 2019
Posts: 14
B
bondo1 Offline OP
Newbie
bondo1  Offline OP
Newbie
B

Joined: Jun 2019
Posts: 14
Hi Spirit,

Thanks for the corrections, I tried them out line by line (plotted APrice, BPrice, BSpread etc) without the series bits and the script runs!

About that last part, do you know where I could find more information on when to use series or not? I checked the manual for examples, and sometimes I found scripts that had series in them (see here: http://manual.zorro-project.com/tutorial_var.htm)
and also on forum posts that had code (for example here: https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=443791#Post443791) and (here: https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=476248#Post476248).

**To note, I've also been using the manual, specifically this to > (http://manual.zorro-project.com/funclist.htm) but still trying to understand when to/when not to use.

Also, thanks to whoever moved the thread, I wasn't sure where to put it but hopefully this helps any new people with this stuff!

Last edited by bondo1; 06/27/19 21:56.
Re: Spreads and Zscores? [Re: bondo1] #477453
06/27/19 22:30
06/27/19 22:30
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Originally Posted by bondo1
About that last part, do you know where I could find more information on when to use series or not? I checked the manual for examples, and sometimes I found scripts that had series in them (see here: http://manual.zorro-project.com/tutorial_var.htm)
and also on forum posts that had code (for example here: https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=443791#Post443791) and (here: https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=476248#Post476248).
It's simple:
  • If you only need the value in this bar, do not use series.
  • If you will need to retrieve an older value (i.e. a value from bar 4 while in bar 0), use series.
  • For example, a SMA Period = 5 calculation calculates an average of bars 0 thru 4, so it requires a price series as an input, but its output is a var. But if that needs to be a series for yet another calculation, you can plug it into a series.

Re: Spreads and Zscores? [Re: bondo1] #477457
06/28/19 03:43
06/28/19 03:43
Joined: Jun 2019
Posts: 14
B
bondo1 Offline OP
Newbie
bondo1  Offline OP
Newbie
B

Joined: Jun 2019
Posts: 14
^ this makes sense, I re-read the manual bit and I think understand.

Thanks for breaking it down like that, very helpful for a new programmer like myself : D


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1