DEFPARAM CumulateOrders = FALSE
ONCE l = 2
ONCE p = 4
ONCE tra = 25
TradingTime=Time>=090000and Time<=210000
// LONG
indicator1 = Volume
indicator2 = ExponentialAverage[14](Volume)
c1 = (indicator1 >= indicator2)
c2 = (indicator1 CROSSES UNDER indicator2)
IF ( close > open and close[1] > open[1] ) and c1 and TradingTime and Not LongOnMarket Then
BUY 1 CONTRACTS AT MARKET
SET STOP LOSS l*AverageTrueRange[10](close)
SET TARGET PROFIT p*AverageTrueRange[12](close)
ENDIF
IF LongOnMarket AND c2 AND PositionPerf > 0 THEN
SELL AT MARKET
ENDIF
//trailing stop
trailingstop = tra
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif