// extension JAP change buy price on Mondays for Friday High/Low
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
DEFPARAM FLATBEFORE = 001000
DEFPARAM FLATAFTER = 160000
DEFPARAM PRELOADBARS = 2000
LastEntryTime = 130000
//ignore saturday and Sunday trading TD=Trading Day
if DayOfWeek = 6 OR DayOfWeek = 7 THEN
TD = 0
else
TD = 1
endif
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
// Money Management
Capital = 3530
Risk = 0.01
StopLoss = 30 // VARY TO DETERMINE RISK
//Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
if PositionSize >= 5 Then
PositionSize = 5
endif
//prices to enter trades
if DayOfWeek = 1 Then
BuyPrice = (DHigh(2)+3*PointSize)
SellPrice = (DLow(2)-3*PointSize)
else
BuyPrice = (DHigh(1)+3*PointSize)
SellPrice = (DLow(1)-3*PointSize)
endif
// Conditions to enter long positions
indicator2 = MACD[8,25,3](close)
c2 = (indicator2 > 0)
indicator1 = TD
c1 = (indicator1=1)
IF TIME < LastEntryTime and c1 and c2 THEN
BUY PositionSize CONTRACTS AT BuyPrice STOP
ENDIF
// Conditions to enter short positions
indicator3 = MACD[8,25,3](close)
c3 = (indicator3 < 0)
IF TIME < LastEntryTime and c1 and c3 THEN
SELLSHORT PositionSize CONTRACTS AT SellPrice STOP
ENDIF
//trailing stop
trailingstop = 25
//case SHORT order
trailshort = 40
if shortonmarket then
MINPRICE = MIN(MINPRICE,Low) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailshort*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailshort*pointsize //set the exit price at the MFE + trailing stop price level
endif
if tradeprice(1)-MINPRICE<=trailshort*pointsize then
priceexit = tradeprice+trailshort*pointsize
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,High) //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
if MAXPRICE-tradeprice(1)<=trailingstop*pointsize then
priceexit = tradeprice-trailingstop*pointsize// ensures trailing stop is in place mJAP improvement
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif