DEFPARAM CumulateOrders = True // Cumulating positions activated
// Definition of code parameters
SL = AverageTrueRange[14](close) * 2.0
PT = SL * 1.5
STEPFACTOR1 = 0.5
STEPFACTOR2 = 0.25
//VWAP calculation
//
NoSunday = 0 //1=skip Sunday's
IF (BarIndex = 0) OR (OpenDay <> OpenDay[1]) THEN
SumVolPrice = 0
SumVol = 0
ENDIF
IF Volume > 0 THEN
IF (OpenDayOfWeek <> 0) OR (OpenDayOfWeek = 0 AND Not NoSunday) THEN
SumVolPrice = SumVolPrice + (Volume * close)
SumVol = SumVol + Volume
VWAP = SumVolPrice / SumVol
ENDIF
ENDIF
indicator1 = MACDline[5,35,5](close)
indicator2 = MACDSignal[5,35,5](close)
timeframe(DEFAULT)
// Conditions to enter long positions
IF close > VWAP AND indicator1 CROSSES OVER indicator2 THEN
BUY 10 CONTRACT AT MARKET
ENDIF
IF close < VWAP AND indicator1 CROSSES UNDER indicator2 THEN
SELLSHORT 10 CONTRACT AT MARKET
// Stops and targets
SET STOP pTRAILING SL
SET TARGET pPROFIT PT
//====== Trailing Stop mechanism - start =====
trailingstart = (stepfactor1 * SL )
trailingstep = (stepfactor2 * SL )
//resetting variables when no trades are on market
if not onmarket then
priceexit = 0
endif
//case LONG order
if longonmarket then
//first move (breakeven)
IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN
priceexit = tradeprice(1) + trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = close-priceexit >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit + trailingstep*pointsize
ENDIF
ENDIF
ENDIF
//case SHORT order
if shortonmarket then
//first move (breakeven)
IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN
priceexit = tradeprice(1) - trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = priceexit-close >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit - trailingstep*pointsize
ENDIF
ENDIF
ENDIF
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
ENDIF
//====== Trailing Stop mechanism - end =====
Could you please, check this code.
ENDIF is missing between lines 29 and 30.
DEFPARAM CumulateOrders = True // Cumulating positions activated
// Definition of code parameters
SL = AverageTrueRange[14](close) * 2.0
PT = SL * 1.5
STEPFACTOR1 = 0.5
STEPFACTOR2 = 0.25
//VWAP calculation
//
NoSunday = 0 //1=skip Sunday's
IF (BarIndex = 0) OR (OpenDay <> OpenDay[1]) THEN
SumVolPrice = 0
SumVol = 0
ENDIF
IF Volume > 0 THEN
IF (OpenDayOfWeek <> 0) OR (OpenDayOfWeek = 0 AND Not NoSunday) THEN
SumVolPrice = SumVolPrice + (Volume * close)
SumVol = SumVol + Volume
VWAP = SumVolPrice / SumVol
ENDIF
ENDIF
indicator1 = MACDline[5,35,5](close)
indicator2 = MACDSignal[5,35,5](close)
timeframe(DEFAULT)
// Conditions to enter long positions
IF close > VWAP AND indicator1 CROSSES OVER indicator2 THEN
BUY 10 CONTRACT AT MARKET
ENDIF
IF close < VWAP AND indicator1 CROSSES UNDER indicator2 THEN
SELLSHORT 10 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET STOP pTRAILING SL
SET TARGET pPROFIT PT
//====== Trailing Stop mechanism - start =====
trailingstart = (stepfactor1 * SL )
trailingstep = (stepfactor2 * SL )
//resetting variables when no trades are on market
if not onmarket then
priceexit = 0
endif
//case LONG order
if longonmarket then
//first move (breakeven)
IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN
priceexit = tradeprice(1) + trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = close-priceexit >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit + trailingstep*pointsize
ENDIF
ENDIF
ENDIF
//case SHORT order
if shortonmarket then
//first move (breakeven)
IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN
priceexit = tradeprice(1) - trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = priceexit-close >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit - trailingstep*pointsize
ENDIF
ENDIF
ENDIF
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
ENDIF
//====== Trailing Stop mechanism - end =====