Syntax error - series with math operations

Posted By: chsmac85

Syntax error - series with math operations - 01/14/19 23:47

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();
}

Posted By: jrath

Re: Syntax error - series with math operations - 01/15/19 02:16

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();
}

Posted By: chsmac85

Re: Syntax error - series with math operations - 01/15/19 13:39

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.
Posted By: AndrewAMD

Re: Syntax error - series with math operations - 01/15/19 14:32

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.
Posted By: chsmac85

Re: Syntax error - series with math operations - 01/15/19 14:35

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].
Posted By: AndrewAMD

Re: Syntax error - series with math operations - 01/15/19 14:46

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
Posted By: chsmac85

Re: Syntax error - series with math operations - 01/15/19 16:16

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!
© 2024 lite-C Forums