//-------------------------------------------------------------------------
// Main code : JAP Breakout 5 min open
//-------------------------------------------------------------------------
// JAP Breakout 5min
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
DEFPARAM FLATAFTER = 162000
DEFPARAM PRELOADBARS = 500
LastEntryTime = 083000
//market analysis starts at the 5 min. candle which closes at 8:00
StartTime = 080000
//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 = 4000
Risk = 0.03
StopLoss = 45 // VARY TO DETERMINE RISK
//Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
if PositionSize >= 10 Then
PositionSize = 10
endif
// variables set t personal preferences
OrderDistance = 2
//initialize variable once at beginning of trading system
ONCE StartTradingDay = -1
//The variables which can change during the day are initialized
//at the beginning of each new trading day
If (Time <= StartTime AND StartTradingDay <> 0) OR IntradayBarIndex = 0 THEN
BuyPrice = 0
SellPrice = 0
StartTradingDay = 0
ELSIF Time >= StartTime AND StartTradingDay = 0 AND TD = 1 THEN
//We store the index of the first bar of the trading day
IndexStartDay = IntradayBarIndex
StartTradingDay = 1
ELSIF StartTradingDay = 1 and Time <= LastEntryTime THEN
IF BuyPrice = 0 OR SellPrice = 0 THEN
UpperLevel = Highest[IntradayBarIndex - IndexStartDay +1] (High)
LowerLevel = Lowest [IntradayBarIndex - IndexStartDay +1] (Low)
endif
BuyPrice = UpperLevel + OrderDistance*PointSize
SellPrice = LowerLevel - OrderDistance*Pointsize
endif
//Long position
indicator3 = Average[100](close)
c3= (close > indicator3)
IF Time <= LastEntryTime AND c3 THEN
BUY PositionSize CONTRACTS AT BuyPrice STOP
ENDIF
// Conditions to enter short positions
indicator4 = Average[100](close)
c4 = (close < indicator4)
indicator7 = DClose(1)
indicator8 = SellPrice
c7 = (indicator7 < indicator8)
indicator6 = (high-low)
c6 = (indicator6 < 42)
IF Time <= LastEntryTime AND c6 AND c4 AND C7 THEN
SELLSHORT PositionSize CONTRACTS AT SellPrice STOP
ENDIF
//trailing stop
trailingstop = 45
//case SHORT order
trailshort = 40
if shortonmarket then
MINPRICE = MIN(MINPRICE,Low) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE> 0 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<= 0 then
priceexit = tradeprice(1)+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)>= 0 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)<= 0 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