Heiken Ashi TMS/TDI strategy

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 🙂




Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

New! PRC is also now on YouTube, subscribe to our channel for exclusive content and tutorials

  1. Nicolas • 08/06/2016 #

    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 🙂 

  2. mr.brymas • 08/06/2016 #

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

    • Elsborgtrading • 08/06/2016 #

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

    • ALEALE • 08/06/2016 #

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

  3. grizzly • 08/06/2016 #

    Great work. I see you’ve used some of my code too 🙂

  4. Dymjohn • 08/06/2016 #

    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.

    • Elsborgtrading • 08/06/2016 #

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

  5. Elsborgtrading • 08/06/2016 #

    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

  6. Elsborgtrading • 08/06/2016 #

    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

    // 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)
    if streak then
    PositionSize = max(abs(round(max(5+risk,risk))),2)
    if streak2 then
    PositionSize = max(abs(round(max(7+risk,risk))),2)

    //TDI indicator
    //parameters :

    //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)

    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

    // short
    IF Not SHORTONMARKET AND shortCondition THEN

    // close position

    IF LONGONMARKET and Longsell then//or longsell2 THEN
    IF SHORTONMARKET and Shortexit then//or shortexit2 THEN

    // stop and profit
    //SET STOP pLOSS sl


  7. miguel33 • 08/06/2016 #

    Ho notato che sembra dia buoni risultati su GBP/USD  (la prima versione del codice) 
    Chi può postare un backtest più lungo ?

  8. grizzly • 08/06/2016 #

    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 • 08/06/2016 #

      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
      to begin with

    • Elsborgtrading • 08/06/2016 #

      Grizzly, what should Ratio be?

  9. DerPat • 08/06/2016 #

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

    • Elsborgtrading • 08/06/2016 #

      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.

Register or


avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
rafadonl2 Here it is the screener. (sorry I don't speak german). //Reglas en Heikin-Ashi: //1- Sec...
finplus Muchas gracias. Have a good day.
rafadonl2 I have modified some lines and it seems this version will work better. Even so, I recommend...
jwebster2 Hi Nicholas.. please ignore previous comment .. as I have located it... !
ALAM Merci Nicolas, j'ai bien trouvé la version corrigée de l'indicateur. Un grand merci pour ton...
Yvan63 Bonsoir, Je ne comprends pas comment la variable HaOpen prend sa première valeur vu que Ext...
Nicolas Set the vertical axis to use the price only (in price settings).
lagjan Thanks Nicolas it helps,,,but what are the settings of variable? After upload the code and u...
rafadonl2 Nicolas is right. You have to set up thevertical axis. When you install and run the indicato...
Nicolas haga su pregunta en el foro, ¡obtendrá más ayuda!
Scalp Buenos días Nicolás, aquí la pregunta: Yo uso el cierre del Heikin Ashi por encima de una me...
rafadonl2 Hola. Yo sólo la uso en cierre diario. lamento no poder ayudarte en la parte de envío de órd...
Nicolaconte Many many thanks for that Nicolas. What if i would like to screen a weekly time frame? It se...
Nicolas Choose weekly timeframe in the dropdown menu in ProScreener.
Nicolas On peut augmenter le nombre d'unités en utilisant (x) unités pour backtester très loin dans ...
Doctrading Chez IG markets, on est effectivement plus limité.C'est pourquoi j'utilise ProRealTime CFD. ...
pascal3431 il semble que cette stratégie ne fonctionne pas avec des stop loss : y a t'il un moyen de li...
skydive Now I did lose even more candle on the chart Sorry I did not have permission to upload och...
tahar Bonjour, je travaille sur un ecran noir et les bougies sont extremement palotes, on distingu...
Alai-n Voir Echantillons de Couleurs RVB : https://www.prorealcode.com/documentation/category/instr...
3 years ago
Francesco78  What is the timefram you suggest for this kind of indicator? Only in the 15 minutes? Thank...
Nicolas Any timeframe possible, this indicator is only an RSI with bands made of standard deviation.
bobtrader Hi Nicolas, would it be possible to modify this code so that I could try it in ProBackTest? ...
Nicolas Hello Bob, of course it is possible. I'll post your request on the English ProOrder Forum ASAP.
Nicolas @bobtrader, you'll find your strategy request coded here in the forum : http://www.prorealco...
3 years ago
gclark25 Hi Nicolas.Is there an updated code for this - I copy and pasted your code exactly how it is...
Nicolas I think it might be something to deal with the parameters which are commented between line 1...
gclark25 Nicolas - you sir, are an absolute gentleman. Thank you for getting back to me so quick.I se...