Gamestudio Links
Zorro Links
Newest Posts
How to install R ?
by Clifford_B. 10/16/19 18:05
Indices & metals easier to trade than FX???
by StefanCGN. 10/15/19 16:19
Can't plot daily high & low
by Zheka. 10/14/19 18:39
TWS "Market closed" fix
by jcl. 10/14/19 15:09
2xCapital slider to increase size
by jcl. 10/14/19 14:03
Imgui Lite-c Development
by txesmi. 10/13/19 09:40
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
10 registered members (Phrendo, AndrewAMD, Clifford_B, 3run, Dooley, sdh309795gaas, Superku, Shutch, kvm, 1 invisible), 625 guests, and 31 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Clifford_B, Paulius, Junker, FrankW, TedMar
18307 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: 65
AZ
C
chsmac85 Offline OP
Junior Member
chsmac85  Offline OP
Junior Member
C

Joined: Oct 2018
Posts: 65
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: 65
AZ
C
chsmac85 Offline OP
Junior Member
chsmac85  Offline OP
Junior Member
C

Joined: Oct 2018
Posts: 65
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: 769
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 769
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: 65
AZ
C
chsmac85 Offline OP
Junior Member
chsmac85  Offline OP
Junior Member
C

Joined: Oct 2018
Posts: 65
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: 769
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 769
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: 65
AZ
C
chsmac85 Offline OP
Junior Member
chsmac85  Offline OP
Junior Member
C

Joined: Oct 2018
Posts: 65
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!


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1