//Time Standard UCT + 0 (GMT)
DEFPARAM CUMULATEORDERS = False
DEFPARAM PRELOADBARS = 2000
//TIME PERIOD Hi / Lo
begintime=070000
endtime=083500
If barindex=tradeindex or time=begintime then
trading=0
endif
If time=endtime then
trading=1
endif
If time=begintime or(time > begintime and time[1]<begintime) then
myhigh=high[1]
mylow=low[1]
elsif time > begintime and time <= endtime then
myhigh=max(high,myhigh)
mylow=min(low,mylow)
endif
//GO LONG
If not longonmarket and trading and Close > ExponentialAverage[1250](close) then
buy 1 share at myhigh - 2*pointsize stop
endif
//EXIT LONG
If longonmarket then
SET STOP PLOSS 70
Trailingstop = 40
endif
//GO SHORT
If not shortonmarket and trading and Close < ExponentialAverage[1250](close) then
sellshort 1 share at myLow - 2*pointsize stop
endif
If shortonmarket then
SET STOP PLOSS 30
Trailingstop = 50
endif
//MFE TRAILING STOP FUNCTION
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
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)*0.2 //set the exit price at the MFE - trailing stop price level
endif
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)*0.2
//set the exit price at the MFE + trailing stop price level
endif
Endif
//Exit at Trailing Stop Max / Min Price Levels
if onmarket and priceexit>0 then
SELL AT priceexit STOP
EXITSHORT AT priceexit STOP
endif