This is my first robot strategy, but I thought I’d share it to see anyone can improve it even further. It has been tested and configured to make a consistent profit gain going back to mid 2016.
This robot strategy is a momentum strategy to be run on the EUR/USD 15 Minute time frame only between 05:00 and 21:00 UK time.
It consists if 4 indicators: 16EMA, Stochastic, MACD and RSI.
This strategy is using the revised trailing stop code by Nicolas, which has improved the average loss of losing trades. I have had to program the exiting of trades on indicators to simulate a reversal price action once entered a trade, but as prorealtime code still does not support multiple time frames, I cannot see away around this. For example it would be beneficial to be able to exit a short trade after two consecutive 5 minute green candles, instead of having to wait for the full 15 minute candle to complete and the stop to kick in.
Overall the percentage of winning trades is lower, prior to mid 2016. Following some research, my findings were attributed to more whipsaws prior to 2016. Increasing the stop to 10 will improve this strategy prior to mid 2016.
To improve the % of winning trades, I would not run this strategy during quiet periods on holidays (Christmas etc) or during a major economic announcements where you may see a large Doji candle.
Defparam PreloadBars=5000
DEFPARAM CumulateOrders = false // Cumulating positions deactivated
// The system will cancel all pending orders and close all positions at 21:00. No new ones will be allowed until after the "FLATBEFORE" time.
DEFPARAM FLATBEFORE = 050000
// Cancel all pending orders and close all positions at the "FLATAFTER" time
DEFPARAM FLATAFTER = 210000
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Conditions to enter long positions
indicator1 = ExponentialAverage[16](close)
c1 = (close > indicator1)
/// Only trade when Stoch is upwards
indicator2 = Stochastic[5,3](close)
c2 = (indicator2 > indicator2[1])
// stochastic 2 periods ago has to be lower to go long
indicator3 = Stochastic[5,3](close)
c3 = (indicator3[2] < indicator3)
indicator5 = Stochastic[5,3](close)
c5 = (indicator5[1] < 70)
indicator6 = MACDline[5,35,5](close)
c6 = (indicator6 > -0.0001)
indicator7 = ExponentialAverage[5](MACDline[5,35,5](close))
c7 = (indicator7 > -0.00016)
indicator8 = RSI[14]
c8 = (indicator8 >=50)
// close to a higher open
higheropen = open > (close[1] -3)
// dont open if a doji
Nodoji1 = abs(open-close) > 0
// dont open if a loose doji
Doji7 = abs(open - close)
loosedoji1 = Doji7 > .00027
Doji6 = abs(open[1] - close[1])
loosedoji2 = Doji6 >= .00010
// dont open on a red candle
// redcandle = (Close < Open)
// dont open if long candle body
candlebody = abs(open - close) < 0.00086
// if candle is red, don't go long
noredcandle = (close - open) > 0
// if 2 red candles in a row
// noredcandles = (close - open > 0 AND close[1] - open[1] > 0)
// close price is close to upper boll, don't enter trade
// indicator99 = BollingerUp[20](close)
// c99 = ABS(close-indicator99 > 12)
IF ( c1 AND c2 AND c3 AND c5 AND c6 AND c7 AND c8 AND Nodoji1 AND higheropen AND loosedoji1 AND loosedoji2 AND candlebody AND noredcandle) AND not daysForbiddenEntry AND not LONGONMARKET THEN
BUY 5 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
// close when you get a strict Doji
Doji1 = (Open = Close)
c8 = Doji1
// close when you get a small bodied red candle
Doji2 = ABS(Open - Close) < .00014
c10 = Doji2
IF LONGONMARKET AND (c8 OR c10) THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator18 = ExponentialAverage[16](close)
c18 = (close < indicator18)
/// Only trade when Stoch is downwards
indicator21 = Stochastic[5,3](close)
c21 = (indicator21 < indicator21[1])
indicator13 = Stochastic[5,3](close)
c13 = (indicator13[1] > 30)
// MACD minus Signal
indicator14 = MACDline[5,35,5](close)
c14 = (indicator14 < 0.0001)
// MACD Signal
indicator16 = ExponentialAverage[5](MACDline[5,35,5](close))
c16 = (indicator16 <= 0)
indicator17 = RSI[14]
c17 = (indicator17 <=50)
// stochastic 3 periods ago has to be higher to go short
indicator18 = Stochastic[5,3](close)
c18 = (indicator18[3] > indicator18)
// dont open if a doji
Nodoji2 = abs(open-close) > 0
// must be a close to a lower open
// nearloweropen = open <= (close[1] + 2)
// must be a strict lower open
loweropen = open < (close[1])
// if candle is green, don't go short
nogreencandle = (close - open) < 0
IF (c21 AND c13 AND c14 AND c18 AND c16 AND c17 AND loweropen AND Nodoji2 AND loosedoji1 AND loosedoji2 AND candlebody AND nogreencandle ) AND not daysForbiddenEntry AND not SHORTONMARKET THEN
SELLSHORT 5 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
// close when you get a strict Doji
Doji1b = (Open = Close)
c20 = Doji1b
// close when you get a long green candle
longgreencandle = (close - open) > .00050
// close trade when stochastic has crossed
// indicator25 = Stochastic[5,3](close)
// indicator26 = Average[3](indicator25)
// revdirection = (indicator25 CROSSES OVER indicator26)
// close when you get a loose Doji
// Doji3 = Range > ABS(Open - Close) * 1.2
// c10 = Doji3
IF SHORTONMARKET AND (c20 OR longgreencandle) THEN
BUY AT MARKET
ENDIF
//************************************************************************
//trailing stop function
trailingstart = 10 //trailing will start @trailinstart points profit
trailingstep = 10 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
// Stops and targets
SET STOP pLOSS 7
SET TARGET pPROFIT 40