This strategy is designed to take advantage of new highs and new lows compared to the previous trading day.
Previous trading day on Monday is Friday and the code filters out any weekend data should it be present.
The stops are optimized for GBPUSD in the timeframe tested which was 100000 units between 23rd April and 16th September 2016.
In theory you should be able to adapt to other pairs, or anything, but works best where there is a trend or imbalance between currencies.
Currently the strategy is set up to trade from 001000. Note that I have proved that using 000000 will result in the code picking up the day before yesterday setting to 10 minutes past midnight (uk time) makes the code work as intended but will still be profitable if you use midnight.
The test used a spread of 1.5 points.
Hope this is of some use
// 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