Error compiling code

Questions about MultiCharts and user contributed studies.
designer01
Posts: 80
Joined: 02 Feb 2010

Error compiling code

Postby designer01 » 02 Apr 2011

I am getting this error message
------ Compiled with error(s): ------
syntax error, unexpected 'identificator', expecting 'string constant'
errLine 44, errColumn 9, errLineEnd 44, errColumnEnd 9
causal study: (Function)

when I compile the code below...please advice. Thanks

Code: Select all

inputs:
ProfitTgt1( 1.5 ), // all % inputs are integers, where 1 = 1%
ProfitTgt2( 3.0 ),
ProfitTgt3( 4.0 ),

Tgt1PcntExit( 33.333 ),
Tgt2PcntExit( 33.333 ),
Tgt3PcntExit( 50 ),

StopLossTgt( 1.0 ),

NumShares( 600 ) ;

variables:
MP( 0 ),
StopLossPrice( 0 ),
Exit3Bar( 0 ),
Exit1( false ),
Exit2( false ) ;

// Get the current market position: -1 = Short; 0 = Flat ; 1 = Long
MP = MarketPosition ;

// Create dummy entries to test scaling out exits. Enter on first bar or 5 bars after
// last exit.
//if CurrentBar = 1 or ( TotalTrades > 0 and BarsSinceExit(1) >= 5 ) then
//Buy NumShares shares at next bar at market ;

// If the enter price > 0 then we are in a position.
if EntryPrice > 0 then
begin

// If the stop loss price is zero then set it to the initial stoploss target below
// the entry price
if StopLossPrice = 0 then
StopLossPrice = EntryPrice * ( 1 - ( StopLossTgt / 100 ) ) ;

// If the first profit target exit has not yet occurred and the current bar high
// is greater than or equal to the first profit target, then exit a percentage of
// the Initial position. Adjust the stop loss price to break even - the entry price.
if Exit1 = false and High >= EntryPrice * ( 1 + ( ProfitTgt1 / 100 ) ) then
begin
Exit1 = true ;
Sell ( Tgt1PcntExit /100 ) * NumShares Shares Total at next bar at market ;
StopLossPrice = EntryPrice ;
end

// If the second profit target exit has not yet occurred and the current bar high
// is greater than or equal to the second profit target, then exit a percentage of
// the initial position. Adjust the stop loss price to the current bar close.
else if Exit2 = false and High >= EntryPrice * ( 1 + ( ProfitTgt2 / 100 ) ) then
begin
Exit2 = true ;
Sell ( Tgt2PcntExit / 100 ) * NumShares Shares Total at next bar at market ;
StopLossPrice = Close ;
end

// If the third profit target exit has not yet occurred and the current bar high
// is greater than or equal to the third profit target, then exit a percentage of
// the CURRENT (not Initial) position.
else if Exit3Bar = 0 and High >= EntryPrice * ( 1 + ( ProfitTgt3 / 100 ) ) then
begin
Sell ( Tgt3PcntExit / 100 ) * CurrentShares Shares Total at next bar at market ;
Exit3Bar = CurrentBar + 3 ;
end ;

// Dummy exit to exit remaining shares 3 bars after third profit target hit so that we
// can enter again to test the scaled out exits.
if Exit3Bar = CurrentBar then
Sell at next bar at market ;

end ;

// If the market position of the prior bar is not zero (in a position) and the current market position
// is zero then we have just exited a trade - reset all the exit variables and stop loss price for
// the next entry and exits.
if MP[1] <> 0 and MP = 0 then
begin
Exit1 = false ;
Exit2 = false ;
Exit3Bar = 0 ;
StopLossPrice = 0 ;
end ;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Error compiling code

Postby TJ » 02 Apr 2011

I am getting this error message
------ Compiled with error(s): ------
syntax error, unexpected 'identificator', expecting 'string constant'
errLine 44, errColumn 9, errLineEnd 44, errColumnEnd 9
causal study: (Function)

when I compile the code below...please advice. Thanks.

syntax error at Line 44.
Sell ( Tgt1PcntExit /100 ) * NumShares Shares Total at next bar at market ;

Please consult the EasyLanguage manual on how to structure the order.

designer01
Posts: 80
Joined: 02 Feb 2010

Re: Error compiling code

Postby designer01 » 03 Apr 2011

Sell ( Tgt1PcntExit /100 ) * NumShares Shares Total at next bar at market ;
I can not figure out what's wrong with this code line. It is the right order of operations bu it is not complying.
Thanks

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Error compiling code

Postby TJ » 03 Apr 2011

Sell ( Tgt1PcntExit /100 ) * NumShares Shares Total at next bar at market ;
I can not figure out what's wrong with this code line. It is the right order of operations bu it is not complying.
Thanks
what does the manual say?

User avatar
piranhaxp
Posts: 241
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 30 times

Re: Error compiling code

Postby piranhaxp » 04 Apr 2011

Designer01,

operations/calculations in an order statement are not allowed. Define it in a variable and change your code, like :

Code: Select all


var: VarLX1(0); /// or like you want ....

/// and further ........

if Exit1 = false and High >= EntryPrice * ( 1 + ( ProfitTgt1 / 100 ) ) then
begin
Exit1 = true ;
VarLX1 = ( Tgt1PcntExit /100 ) * NumShares;
Sell Var1LX1 Shares next bar at market ;
StopLossPrice = EntryPrice ;
end .........
But I would never use the same variable for your 3 exits. Hope this helps ....

So your code should look like this :

Code: Select all


inputs:
ProfitTgt1( 1.5 ), // all % inputs are integers, where 1 = 1%
ProfitTgt2( 3.0 ),
ProfitTgt3( 4.0 ),

Tgt1PcntExit( 33.333 ),
Tgt2PcntExit( 33.333 ),
Tgt3PcntExit( 50 ),

StopLossTgt( 1.0 ),

NumShares( 600 ) ;

variables:
MP( 0 ),
StopLossPrice( 0 ),
Exit3Bar( 0 ),
Exit1( false ),
Exit2( false ),
VarLX1(0) ,
VarLX2(0),
VarLX3(0);

// Get the current market position: -1 = Short; 0 = Flat ; 1 = Long
MP = MarketPosition ;

// Create dummy entries to test scaling out exits. Enter on first bar or 5 bars after
// last exit.
//if CurrentBar = 1 or ( TotalTrades > 0 and BarsSinceExit(1) >= 5 ) then
//Buy NumShares shares at next bar at market ;

// If the enter price > 0 then we are in a position.
if EntryPrice > 0 then
begin

// If the stop loss price is zero then set it to the initial stoploss target below
// the entry price
if StopLossPrice = 0 then
StopLossPrice = EntryPrice * ( 1 - ( StopLossTgt / 100 ) ) ;

// If the first profit target exit has not yet occurred and the current bar high
// is greater than or equal to the first profit target, then exit a percentage of
// the Initial position. Adjust the stop loss price to break even - the entry price.
if Exit1 = false and High >= EntryPrice * ( 1 + ( ProfitTgt1 / 100 ) ) then
begin
Exit1 = true ;
VarLX1 = ( Tgt1PcntExit /100 ) * NumShares;
Sell VarLX1 Shares next bar at market ;
StopLossPrice = EntryPrice ;
end

// If the second profit target exit has not yet occurred and the current bar high
// is greater than or equal to the second profit target, then exit a percentage of
// the initial position. Adjust the stop loss price to the current bar close.
else if Exit2 = false and High >= EntryPrice * ( 1 + ( ProfitTgt2 / 100 ) ) then
begin
Exit2 = true ;
VarLX2 = ( Tgt2PcntExit / 100 ) * NumShares;
Sell VarLX2 Shares Total at next bar at market ;
StopLossPrice = Close ;
end

// If the third profit target exit has not yet occurred and the current bar high
// is greater than or equal to the third profit target, then exit a percentage of
// the CURRENT (not Initial) position.
else if Exit3Bar = 0 and High >= EntryPrice * ( 1 + ( ProfitTgt3 / 100 ) ) then
begin
VarLX3 = ( Tgt3PcntExit / 100 ) * CurrentShares;
Sell VarLX3 Shares Total at next bar at market ;
Exit3Bar = CurrentBar + 3 ;
end ;

// Dummy exit to exit remaining shares 3 bars after third profit target hit so that we
// can enter again to test the scaled out exits.
if Exit3Bar = CurrentBar then
Sell at next bar at market ;

end ;

// If the market position of the prior bar is not zero (in a position) and the current market position
// is zero then we have just exited a trade - reset all the exit variables and stop loss price for
// the next entry and exits.
if MP[1] <> 0 and MP = 0 then
begin
Exit1 = false ;
Exit2 = false ;
Exit3Bar = 0 ;
StopLossPrice = 0 ;
end ;

Regards.

designer01
Posts: 80
Joined: 02 Feb 2010

Re: Error compiling code

Postby designer01 » 05 Apr 2011

Thank you, It works great now. It is strange in TS it works without the variables being stated. That thru me off.

User avatar
piranhaxp
Posts: 241
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 30 times

Re: Error compiling code

Postby piranhaxp » 05 Apr 2011

Always a pleasure.

Mike


Return to “MultiCharts”