Help with "syntax error, unexpected identificator" please

Questions about MultiCharts and user contributed studies.
Adam333
Posts: 20
Joined: 05 Oct 2010

Help with "syntax error, unexpected identificator" please

Postby Adam333 » 05 Oct 2010

My Code:

Code: Select all

inputs:  SMAFilter( 34 ), ShortEMA( 12 ), LongEMA( 35 ), ShortTermSlopeDays(15), LongTermSlopeDays(245),
     ATRStop(1.83), ATRLength(14), ProfitTarget(14000), RiskPerTrade(0.03);
variables:  MacdMA( 0 ), SMA( 0 ), ShortTermSlope( 0 ), LongTermSlope( 0 ), EquityAtRisk( 0 );
array: MacdLine[ ] ( 0 );
array_setmaxindex[ MacdLine, ShortEMA + 1 ]

//Calculate long and short term slope filters
ShortTermSlope = LinearRegSlope( Close, ShortTermSlopeDays)
LongTermSlope = LinearRegSlope( Close, LongTermSlopeDays)


Error:
05.10.10 10:04:33
------ Build started: ------
Study: "Guinness" (Signal)
Please wait ....
------ Compiled with error(s): ------
syntax error, unexpected 'identificator'
errLine 8, errColumn 0, errLineEnd 8, errColumnEnd 0
causal study: (Function)


Any advice and/or guidance on solving this compiling error would be greatly appreciated.

FYI: Line 8 is "ShortTermSlope = LinearRegSlope( Close, ShortTermSlopeDays)"

Thanks in advance,
Adam

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 485 times

Re: Help with "syntax error, unexpected identificator" pleas

Postby Dave Masalov » 06 Oct 2010

Dear Adam,

Please try to use this code:

Code: Select all

inputs: SMAFilter( 34 ), ShortEMA( 12 ), LongEMA( 35 ), ShortTermSlopeDays(15), LongTermSlopeDays(245),
ATRStop(1.83), ATRLength(14), ProfitTarget(14000), RiskPerTrade(0.03);
variables: MacdMA( 0 ), SMA( 0 ), ShortTermSlope( 0 ), LongTermSlope( 0 ), EquityAtRisk( 0 );
array: MacdLine[ ] ( 0 );
array_setmaxindex( MacdLine, ShortEMA + 1 );

//Calculate long and short term slope filters
ShortTermSlope = LinearRegSlope( Close, ShortTermSlopeDays);
LongTermSlope = LinearRegSlope( Close, LongTermSlopeDays);

Adam333
Posts: 20
Joined: 05 Oct 2010

Re: Help with "syntax error, unexpected identificator" pleas

Postby Adam333 » 06 Oct 2010

Thanks very much Dave. It now works. However, I am not sure exactly what you changed. The only thing I can think of is spacing after "inputs:" and "variables:" ???

Adam333
Posts: 20
Joined: 05 Oct 2010

Re: Help with "syntax error, unexpected identificator" pleas

Postby Adam333 » 06 Oct 2010

Dave is there a good source for descriptions and solutions to common compiliing errors?

I made it more than half way through my strategy before becoming stuck on another compiling error. Your assistance is greatly appreciated. Thanks

My Code:
//If one of the below conditions are true, place buy or sell at open order with broker.
condition1 = MacdLine cross above MacdMA AND //FYI: Re error this is Line 38
longTermSlope > 0 AND
Close > SMA AND
marketposition <> 1;

condition2 = MacdLine cross below MacdMA AND
longTermSlope < 0 AND
Close < SMA AND
marketposition <> -1;

if condition1 then Buy at Next Bar Open;

if condition2 then Sell at Next Bar Open;

Compiling Error:
06.10.10 10:27:00
------ Build started: ------
Study: "Guinness" (Signal)
Please wait ....
------ Compiled with error(s): ------
syntax error, expecting 'bars'
errLine 38, errColumn 0, errLineEnd 38, errColumnEnd 0
causal study: (Function)


Thanks,
Adam

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 485 times

Re: Help with "syntax error, unexpected identificator" pleas

Postby Dave Masalov » 06 Oct 2010

MacdLine - is an array. The following line cannot be compiled:

Code: Select all

condition2 = MacdLine cross below MacdMA

Cross
---
Usage
E1 Cross Direction E2
or:
Plot1 Cross Direction Plot2

Where: E - a numerical expression

Adam333
Posts: 20
Joined: 05 Oct 2010

Re: Help with "syntax error, unexpected identificator" pleas

Postby Adam333 » 06 Oct 2010

Dave,

I have changed MacdLine to a numeric variable; however, I still get the same error. I also tried "plot1 crosses above plot2" with no luck.

My Code:
inputs: SMAFilter( 34 ), ShortEMA( 12 ), LongEMA( 35 ), ShortTermSlopeDays(15), LongTermSlopeDays(245), ATRStop(1.83), ATRLength(14), ProfitTarget(0.14), RiskPerTrade(0.03);
variables: MacdLine( 0 ), MacdMA( 0 ), SMA( 0 ), ShortTermSlope( 0 ), LongTermSlope( 0 ), ATR( 0 );
//array: MacdLine[ ] ( 0 );
//array_setmaxindex( MacdLine, ShortEMA + 1 );

//Calculate long and short term slope filters
ShortTermSlope = LinearRegSlope( Close, ShortTermSlopeDays);
LongTermSlope = LinearRegSlope( Close, LongTermSlopeDays);

//Caculate ATR for ATR trailing stop
ATR = AvgTrueRange( ATRLength );

//Calculate indicator values used for entry signal
MacdLine = MACD( Close, ShortEMA, LongEMA ) ;
Plot1( MacdLine, "MacdLine" );
MacdMA = XAverage( MacdLine, ShortEMA ) ;
Plot2( MacdMA, "MacdMA" );

//Caculate and plot simple moving average
SMA = Average( Close, SMAFilter );
Plot3( SMA, "SMA" );

//If one of the below conditions are true, place buy or sell at open order with broker.

condition1 = MacdLine cross above MacdMA AND //FYI: this is Line 39
longTermSlope > 0 AND
Close > SMA AND
marketposition <> 1;

condition2 = MacdLine cross below MacdMA AND
longTermSlope < 0 AND
Close < SMA AND
marketposition <> -1;

if condition1 then Buy at Next Bar Open;

if condition2 then Sell at Next Bar Open;


Error:
------ Build started: ------
Study: "Guinness" (Signal)
Please wait ....
------ Compiled with error(s): ------
syntax error, expecting 'bars'
errLine 39, errColumn 0, errLineEnd 39, errColumnEnd 0
causal study: (Function)

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 485 times

Re: Help with "syntax error, unexpected identificator" pleas

Postby Dave Masalov » 07 Oct 2010

Dear Adam,

You are using Plot an Buy keywords in the same study. This is not possible. You cannot use Plot in a signal and Buy in an indicator. Please create two identical studies - indicator with Plot lines and signal with Buy lines.

Adam333
Posts: 20
Joined: 05 Oct 2010

Re: Help with "syntax error, unexpected identificator" pleas

Postby Adam333 » 07 Oct 2010

Ahh did not know that. Thanks Dave. I have removed all the plots from the study and the debugging saga continues with little direction from the debugger. I am now getting the following error:


07.10.10 09:20:45
------ Build started: ------
Study: "Guinness" (Signal)
Please wait ....
------ Compiled with error(s): ------
syntax error, expecting 'bars'
errLine 0, errColumn 0, errLineEnd 0, errColumnEnd 0
causal study: (Function)


How does one know where to look for the issue with an error report like that? errLine 0?


Return to “MultiCharts”