Thank you to andy6t6 for use of ‘Time Period Hi / Lo’ idea.
Thank you to Nicolas for use of ‘MFE Trailing Stop’.
I have ‘squeezed more out of it’, but I de-optimised somewhat.
If you can improve, add to or change for the better then let us all know please?
Cheers
GraHal
//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
Hello GraHal.
My first instant thoughts are that with such differences in the stoploss and trailing stop variables between long and short positions that it might be rather over fitted. Walk forward with a dummy variable seems to confirm this (for what walk forward testing is worth on such short periods and short time frames). I guess only true real life forward testing will tell us whether it is or not.