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/1902:1601/15/1902:16
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/1914:3201/15/1914:32
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/1914:4601/15/1914:46
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!