Elsborgtrading

Heiken Ashi TMS/TDI strategy

Category: Strategies By: Elsborgtrading Created: August 6, 2016, 7:13 PM
August 6, 2016, 7:13 PM
Strategies
16 Comments
Heiken Ashi TMS/TDI strategy

Hi guys.

My first contribution to the strategy site. It’s based on several codes from the site, but mainly the TDI and TMS from both Nicolas and Reiner. I changed the strategy a bit so it fits the Oil- Brent Crude. It seems like that every strategy that I test need to be “adjusted” to the particular instrument. Does anyone do the same, or do you strictly keep the rule? Anyway the code has no zero bar profit nor does it have SL or TP coded, in fact it has only 15 trades over 3 month. It sure could be more “perfect” as there are some entries that could be more profitable. Unfortunately I can only backtest it 3 month. Apparently IG only hold 3 month of data for Crude Oil. It’s tested with a 3 point spread. Anyway here it is, please comment 🙂

Cheers

Kasper

//TDI OIL 2H elsborgtrading
// based on Trend Surfer DAX-Reiner/Nicolas-TMS
//http://www.prorealcode.com/prorealtime-trading-strategies/trend-surfer-dax/
//http://www.prorealcode.com/topic/trading-made-simple-tms-system/
//http://www.forexmt4.com/_MT4_Systems/Traders%20Dynamics/TDI_1.pdf

// code-Parameter
DEFPARAM CumulateOrders = true

//DEFPARAM FlatAfter = 230000
//DEFPARAM Flatbefore = 030000

//MONEY MGT//

Equity = (Strategyprofit+20000)
Risk = round(Equity/100000)
Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0
streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0
if losses then
 PositionSize  = max(abs(round(max(3+risk-2,risk-2))),2)
elsif not losses then
 PositionSize  = max(abs(round(max(3+risk,risk))),2)
endif
if streak then
 PositionSize  = max(abs(round(max(5+risk,risk))),2)
endif

//TDI indicator
//parameters :
lengthrsi=13
lengthrsipl=2
lengthtradesl=7

//overbought and oversold values of the TDI indicator
upperzone = 68
lowerzone = 32

//heiken ashi
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
 xOpen = (xOpen[1] + xClose[1])/2
 xHigh = Max(xOpen, xClose)
 xLow = Min(xOpen, xClose)
endif

//indicators
r = rsi[lengthrsi](close)
mab = average[lengthrsipl](r)
mbb = average[lengthtradesl](r)
yellowMA = average[5](TypicalPrice)
yellowMAshifted = yellowMA[2]

//trade conditions
longCondition = mab crosses over mbb AND mab<50 AND xHigh>yellowMAshifted
shortCondition = mab crosses under  mbb AND mab>50 AND xLow<yellowMAshifted
Longsell=mab crosses under mbb AND mab<upperzone and mab>50 AND xlow>yellowMAshifted
Shortexit= mab crosses over mbb AND mab>lowerzone and mab<50 AND xhigh>yellowMAshifted

//***************************

// open position
// long
IF Not LONGONMARKET AND longcondition THEN
 BUY PositionSize CONTRACT AT MARKET
ENDIF

// short
IF Not SHORTONMARKET AND shortCondition THEN
 SELLSHORT PositionSize CONTRACT AT MARKET
ENDIF

// close position
//Longsell
IF LONGONMARKET and Longsell  THEN
 SELL AT MARKET
ENDIF

//Shortexit
IF SHORTONMARKET and Shortexit THEN
 EXITSHORT  AT MARKET
ENDIF

 

Download
Filename: TDI-OIL-2H-ElsborgTradingV3.itf
Downloads: 299
Download
Filename: Screenshot_202.png
Downloads: 89
Download
Filename: Screenshot_203.png
Downloads: 247
Download
Filename: Screenshot_200.png
Downloads: 90
Download
Filename: Screenshot_201.png
Downloads: 76
Download
Filename: Heiken-Ashi-TMS-TDI-strategy.itf
Downloads: 614
Download
Filename: Screenshot_148.png
Downloads: 146
Download
Filename: Screenshot_147.png
Downloads: 368
Download
Filename: Screenshot_149.png
Downloads: 109
Elsborgtrading
Elsborgtrading Veteran
Developer by day, aspiring writer by night. Still compiling my bio... Error 404: presentation not found.
Author’s Profile

Comments

DerPat
10 years ago
#

I am also interested in your forward testing, as backtesting results are useless.

Elsborgtrading
10 years ago
#

I agree, but since we don't have any SL or TP at all, or any Profit on zero candle, I think it safe to say that this backtest is more useful. However 3 month is somewhat not enough.

grizzly
10 years ago
#

Can i suggest, that this piece of code:

Risk = round(Equity/100000)
be changed to

MaxPositionA = 50
Risk = min(round(Ratio*Equity/100000)*1,MaxPositionA)
Otherwise, risk -> infinity haha

Elsborgtrading
10 years ago
#

Grizzly, what should Ratio be?

Elsborgtrading
10 years ago
#

Very nice Grizzly. I properly would have done some beginners programming like this, but yours has more "pronage" :-) My code is only running on Live demo for at least 3 month before considering investing real money in it. Mainly due to the small backtesting range- but if It would make it to real investment, I thing I also would start with only 1 contract

If PositionSize>=50 then
PositionSize=50
endif


to begin with

miguel33
10 years ago
#

Ho notato che sembra dia buoni risultati su GBP/USD  (la prima versione del codice) 

Chi può postare un backtest più lungo ?

Grazie.

Miguel 

Elsborgtrading
10 years ago
#

Hello guys. Using the optimization technique I was able to produce a more profitable code. still without the huge drawback. also it eliminated the one loss I had. I also added an extra streak to the Money Management code. 4 in a row- since we were doing so well.  I'd still like if someone could be kind and test it back further as I still only have data since may 2016

//-------------------------------------------------------------------------
//TDI OIL Brent Crude (1£ Contracts) 2H ElsborgTrading V3
//
// based on Trend Surfer DAX-Reiner/Nicholas-TMS
//http://www.prorealcode.com/prorealtime-trading-strategies/trend-surfer-dax/
//http://www.prorealcode.com/topic/trading-made-simple-tms-system/
//http://www.forexmt4.com/_MT4_Systems/Traders%20Dynamics/TDI_1.pdf
//-------------------------------------------------------------------------

// code-Parameter
DEFPARAM CumulateOrders = true

//DEFPARAM FlatAfter = 230000
//DEFPARAM Flatbefore = 030000

//MONEY MGT//

Equity = (Strategyprofit+20000)
Risk = round(Equity/100000)
Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0
streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0
Streak2= positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0 and positionperf(4)>0
if losses then
PositionSize  = max(abs(round(max(3+risk-2,risk-2))),2)
elsif not losses then
PositionSize  = max(abs(round(max(3+risk,risk))),2)
endif
if streak then
PositionSize  = max(abs(round(max(5+risk,risk))),2)
endif
if streak2 then
PositionSize  = max(abs(round(max(7+risk,risk))),2)
endif


//TDI indicator
//parameters :
lengthrsi=13
lengthrsipl=2
lengthtradesl=7

//overbought and oversold values of the TDI indicator
upperzone = 65
lowerzone = 7
//upperzone = upz
//lowerzone = loz

//heiken ashi
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
xOpen = (xOpen[1] + xClose[1])/2
xHigh = Max(xOpen, xClose)
xLow = Min(xOpen, xClose)
endif

//indicators
r = rsi[lengthrsi](close)
mab = average[lengthrsipl](r)
mbb = average[lengthtradesl](r)
yellowMA = average[5](TypicalPrice)
yellowMAshifted = yellowMA[2]

//trade conditions
longCondition = mab crosses over mbb AND mab<50 AND xHigh>yellowMAshifted
shortCondition = mab crosses under  mbb AND mab>51 AND xLow<yellowMAshifted

//Longsell=mab crosses under mbb AND mab<upperzone and mab>56 AND xlow>yellowMAshifted
//Shortexit= mab crosses over mbb AND mab>lowerzone and mab<56 AND xhigh>yellowMAshifted
Longsell=mab crosses under mbb AND mab<upperzone and mab>55 AND xlow>yellowMAshifted
Shortexit= mab crosses over mbb AND mab>lowerzone and mab<58 AND xhigh>yellowMAshifted
//Longsell2=mab crosses under lowerzone
//Shortexit2=mab crosses over upperzone
//***************************

// open position
// long
IF Not LONGONMARKET AND longcondition THEN
BUY PositionSize CONTRACT AT MARKET
ENDIF

// short
IF Not SHORTONMARKET AND shortCondition THEN
SELLSHORT PositionSize CONTRACT AT MARKET
ENDIF

// close position

IF LONGONMARKET and Longsell then//or longsell2 THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET and Shortexit then//or shortexit2 THEN
EXITSHORT  AT MARKET
ENDIF


// stop and profit
//SET STOP pLOSS sl
//SET TARGET pPROFIT tp

 

Elsborgtrading
10 years ago
#

The reason i added those limmit is to catch the false breakout of a trade. It will save many orders that othervise would have a huge drawback

Dymjohn
10 years ago
#

Hi Casper,

I see you've been busy. Wondering if it would be better  to remove on "shortexit" mab<50 and on "Longsell" mab>50. On recent history this reduces profits but only  minimally but avoids seeing large erosion on the latest trade.

John

Elsborgtrading
10 years ago
#

hi john. Yes quite busy. Regards the  numbers I just found a way to optimise the them. I did not had the time yet

grizzly
10 years ago
#

Great work. I see you've used some of my code too :)

Elsborgtrading
10 years ago
#

Yes Grizzly. That part is awesome :-D

mr.brymas
10 years ago
#

Hi! Thanks for sharing. I´m able to backtest the code a year. Here´s the result:

http://picgur.org/images/2016/08/07/Skarmavbild2016-08-07kl.17.37.03.png

ALEALE
10 years ago
#

Dear Mr. Brymas ,
could you test the optimazed strategy of Elsbortrading below for 1 year ?
Thanks All

 

Elsborgtrading
10 years ago
#

thanks for the test. Still not bad, but room for improvement :)

Nicolas
10 years ago
#

Thank you Kasper for your contribution to the Library. I know this kind of strategy code can help a lot of people around here. You have put together a lot of other people pieces of work in one strategy to make yours and that's fine. I can say that the objective of the website has been completed :) Sharing our coding knowledge to help each other to better and quickly achieve the hard learning curves to build effective codes, even if they are not perfect. I can see code from Grizzly too and from Adolfo.

About the strategy, I tested it on PRT-CFD history (which is longer than the IG one), and I find it good too since mid-2015 (no history before that). Understand that the profit curve is not straight, but not deal with massive drawdown at all. Hope to see more from you soon :) 

ProRealCode ProRealCode
Loading...