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
Syntax error - series with math operations #475945
01/14/19 23:47
01/14/19 23:47
Joined: Oct 2018
Posts: 70
AZ
C
chsmac85 Offline OP
Junior Member
chsmac85  Offline OP
Junior Member
C

Joined: Oct 2018
Posts: 70
AZ
I can't get past the following as I keep getting a syntax error. It should be a fairly simple mean reversion script but I can't figure out what is the syntactical error in the declaration of my absolute price difference variable.

Code:
function run()
{
  vars Close = series(priceClose());
  vars SMA200 = series(SMA(Close,200));
  vars SMA20 = series(SMA(Close,20));
  vars Price_diff200 = series((abs(Close - SMA200) / float(Close)) * 100.0);
  

  
  if(Price_diff200 > 2.0)
	  if(SMA20 < SMA200)
		  enterLong();
      else if(SMA20 > SMA200)
			enterShort();
}


Re: Syntax error - series with math operations [Re: chsmac85] #475948
01/15/19 02:16
01/15/19 02:16
Joined: Nov 2016
Posts: 69
USA
J
jrath Offline
Junior Member
jrath  Offline
Junior Member
J

Joined: Nov 2016
Posts: 69
USA
This is my guess but dont trust me I am new at this:

Code:
function run()
{
  vars Close = series(priceClose());
  vars SMA200 = series(SMA(Close,200));
  vars SMA20 = series(SMA(Close,20));
  vars Price_diff200 = series(abs((*Close - *SMA200)/ (*Close))  * 100.0);
  

  
  if(*Price_diff200 > 2.0)
	  if(SMA20 < SMA200)
		  enterLong();
      else if(SMA20 > SMA200)
			enterShort();
}


Re: Syntax error - series with math operations [Re: jrath] #475953
01/15/19 13:39
01/15/19 13:39
Joined: Oct 2018
Posts: 70
AZ
C
chsmac85 Offline OP
Junior Member
chsmac85  Offline OP
Junior Member
C

Joined: Oct 2018
Posts: 70
AZ
Thanks, Jrath! That compiled! I tried reading up to find out the issue and it seems to have to do with C running out of characters and the ambiguity between a pointer and multiplication function call.

Re: Syntax error - series with math operations [Re: chsmac85] #475958
01/15/19 14:32
01/15/19 14:32
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
You should try to learn how pointers work.

vars is a pointer to a var array.

Code:
typedef var* vars;


For example, Close is a vars.

To get its first value, you can't use Close. Instead, you must use *Close or Close[0], whichever is more readable.

Re: Syntax error - series with math operations [Re: AndrewAMD] #475959
01/15/19 14:35
01/15/19 14:35
Joined: Oct 2018
Posts: 70
AZ
C
chsmac85 Offline OP
Junior Member
chsmac85  Offline OP
Junior Member
C

Joined: Oct 2018
Posts: 70
AZ
Hi Andrew,
Thanks for the insight!
Why would I want to get the first value when doing array operations? I was trying to do a multiplication on the elementwise values of the array.

ex. [2,3,4,5,6,7] * 2 = [4,6,8,10,12,14].

Re: Syntax error - series with math operations [Re: chsmac85] #475961
01/15/19 14:46
01/15/19 14:46
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
I thought you're writing a **trading script**, not a matrix homework problem. wink

You're using run() and series(). These build up your array, so you are already doing that.

Read up:
https://zorro-project.com/manual/en/series.htm
https://zorro-project.com/manual/en/run.htm

Re: Syntax error - series with math operations [Re: AndrewAMD] #475963
01/15/19 16:16
01/15/19 16:16
Joined: Oct 2018
Posts: 70
AZ
C
chsmac85 Offline OP
Junior Member
chsmac85  Offline OP
Junior Member
C

Joined: Oct 2018
Posts: 70
AZ
Ha, not doing matrix homework problem. Just trying to follow the conversation. I first learned Python and then R. Things that work in those languages don't work and the compiler error wasn't helping direct me to a stack overflow or tutorial that I could quickly diagnose the error.

Also, because I'm not a coder by trade, I sometimes phrase things less precisely than I should.

Thanks for the help and I'll definitely read up on those two links!


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1