DEFPARAM CumulateOrders = False
DEFPARAM PRELOADBARS = 10000
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
Horaire = time >= 000000 and time <= 200000
CloturePartielle = 1
PositionsizeA = 1
PositionsizeV = 1
IF CloturePartielle THEN
PositionsizeA = 4
PositionsizeV = 3
ENDIF
MM = Average[63,3](totalprice)
Newhighest=0
FOR a = 0 TO 1 DO
IF DHigh(a)>Newhighest or Newhighest=0 THEN
Newhighest = DHigh(a)
ENDIF
NEXT
Newlowest=0
FOR b = 0 TO 1 DO
IF DLow(b)<Newlowest or Newlowest=0 THEN
Newlowest = DLow(b)
ENDIF
NEXT
Milieu = (Newhighest+Newlowest)/2
Surachat = average[13,7]((Newhighest+Milieu)/2)
Survente = average[13,7]((Newlowest+Milieu)/2)
CA = (MM > Surachat) and (close crosses over Milieu)
CV = (MM < Survente) and (close crosses under Milieu)
// Long Entries
IF Horaire AND CA AND not daysForbiddenEntry AND NOT SHORTONMARKET THEN
BUY PositionsizeA CONTRACTS AT MARKET
ENDIF
IF CloturePartielle THEN
IF LONGONMARKET THEN
SELL 1 CONTRACTS AT TRADEPRICE + 63*pointsize LIMIT
ENDIF
IF LONGONMARKET THEN
SELL 1 CONTRACTS AT TRADEPRICE + 27*pointsize LIMIT
ENDIF
IF LONGONMARKET THEN
SELL 1 CONTRACTS AT TRADEPRICE + 24*pointsize LIMIT
ENDIF
ENDIF
// Short Entries
IF Horaire AND CV AND not daysForbiddenEntry AND NOT LONGONMARKET THEN
SELLSHORT PositionsizeV CONTRACTS AT MARKET
ENDIF
IF CloturePartielle THEN
IF SHORTONMARKET THEN
EXITSHORT 1 CONTRACTS AT TRADEPRICE - 22*pointsize LIMIT
ENDIF
IF SHORTONMARKET THEN
EXITSHORT 1 CONTRACTS AT TRADEPRICE - 70*pointsize LIMIT
ENDIF
ENDIF
//MFE
//trailing stop
trailingstop = 21
//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
//SET TARGET pPROFIT 46
SET STOP pLOSS 150