DI TEMA Trendfollowing strategy on DAX 5 min

Category: Strategies By: Jan Created: May 10, 2019, 8:02 AM
May 10, 2019, 8:02 AM
Strategies
9 Comments

Please find below a simple strategy based on a combination of the DI and TEMA indicators.

It performs quite well on the DAX 5 minutes (7:00-22:00 trading), for 100.000 bars, spread 5 pips.

Conditions to OPEN positions (see settings in the code)

1 TEMA trend turn into positive (for long) or turns into negative (for short)

2 the DI increases, but starts from below zero (Long) or decreases, but starts from above zero (short)

The only CLOSE conditions are  a Trailing stop loss, whereby the Trailing stop is reduced after 12 trading bars.

I tried it on several indices in different timeframes, I only got good results for the DAX, 5 minutes bar.

Disadvantage of this strategy is the long TTM, Time in the Market, of at least 65 %, obviously also overnight.

As a spread I have taken into account 5 pips, which should include 3 pips for interest to be paid (estimation 4% x exposure 12.000 Euro for 1 contract x 65% in the market / 120 trades per year)

This strategy requires a bit different settings for 2019 alone (for better results) compared to the settings set in the code for the whole period of 100.000 bars. I am (obviously!) looking for automated setting adjustments during different structures of market movements, any suggestions are more then welcome.

Any suggestions for improvement welcome !

DEFPARAM CumulateOrders = false // Cumulating positions deactivated
//VARIABLES
once SLperc = 105 // Stoploss percentage 105/10000 * Close
once TrailSLPerc = 85  // Trailng Stoploss percentage 85/10000 * Close
once Tema2 =  30 // Tema setting for opening long/short positions
once DI2 = 7 //DI setting for opening long/short positions
once Duration = 12  // number of bars in trade before reducing the trailing stop
once Factor = 7/10//factor to reduce trailing stoploss after some time in the trade

once StartE = 74500  //start time for opening positions
once StartL = 103000  //ending time for opening positions (only trading in the  morning)
once N = 1  // initieel aantal contracten
OTD = Barindex - TradeIndex(1) > IntradayBarIndex  // limits the (opening) trades till  1 per day

//Setting Stop loss and trailing stop loss  //Dynamic for indices
once SL = round(close * SLPerc/10000)
once trailingstop = round(close * (TrailSLPerc)/10000)

// Conditions to OPEN positions
//1/TEMA trend turn into positive(long) or turns into negative (short)
//2/ DI increases, but starts negative (Long) or decreases, but starts with positive value (short)

// Conditions to CLOSE positions
//1/Trailing stop loss hit
//2 Trailing stop is reduced after 12 trading bars

iTema = TEMA[Tema2](close)  //default TEMA 20
iDI = TEMA[3](DI[DI2](close)) //default TEMA 14

if time >= StartE And time <= StartL and OTD and not onmarket  then
 IF  iTema > iTema[1] and iTema[1] < iTema[2] and iDI > iDI[1] and iDI < 0   then
  BUY N shares AT MARKET
  SET STOP ploss SL
 // long sell conditie (bovengeschikt aan short sell  and dligneJ < Avd
 else
  IF  iTema < iTema[1] and  iTema[1] > iTema[2] and iDI < iDI[1] and iDI > 0    THEN
   SELLSHORT N shares AT MARKET  //short sell conditie
   SET STOP pLOSS SL
  endif
 endif
endif // einde aankoop

//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 barindex - tradeindex(1) > Duration then //normal trailing stop adjusted for factor, which decreases trailing stip
  if tradeprice(1)-MINPRICE >= Factor * trailingstop*pointsize then //if the MFE is higher than the trailingstop then
   priceexit = MINPRICE + Factor * trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
  endif
 else //normal trailing stop
  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
endif
//case LONG order
if longonmarket then
 MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
 if barindex - tradeindex(1) > 12 then //normal trailing stop adjusted for factor, which decreases trailing stip
  if MAXPRICE-tradeprice(1)>= Factor * trailingstop*pointsize then //if the MFE is higher than the trailingstop then
   priceexit = MAXPRICE- Factor * trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
  endif
 else //normal trailing stop
  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
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
 EXITSHORT AT priceexit STOP
 SELL AT priceexit STOP
endif

Download
Filename: 190506-TEMA-DI-SL.itf
Downloads: 836
Download
Filename: Backtest-results-DAX-5-min-sep17-mei19.png
Downloads: 422
Jan Veteran
This author is like an anonymous function, present but not directly identifiable. More details on this code architect as soon as they exit 'incognito' mode.
Author’s Profile

Comments

Logo Logo
Loading...