Index/bond strategy based on slow accumulation of contrarian orders (BUY) and MoneyManagement “antimartingala” style

Index/bond strategy based on slow accumulation of contrarian orders (BUY) and MoneyManagement &# ...


I reviewed the last strategy using contrarian orders and I added more filters in order not to accumulate too much contracts.

The base logic is “buy”.

Furthermore the system try to follow automatically the uptrend when it appears.

Inside the code I trid to explain the main parameters to use.

Actually such code is the automatisation of a my old “manual” strategy that I use since 2010 (using a simply Excel that give me the operating signals) using ETF instruments (It seems to me that even on IG it is possible to use ETF – isn’t it?).

The strategy that I am posting today works on long periods of time, so the broker (i.e. IG) withdraw an amount of cash every night (CFD cash) .

For what I know this is a blocking problem because overnight interest destroy any good strategy.

If I am wrong on what I’m saying please let me know if you can help me to resolve this problem (that’s why I sopke about ETF instrument which are not hit by this issue).

Moreover using CFD future with own expiry date I suppose that the issue on overnight interest doesn’t exist.  Isn’t it?

But this way, how can I think to use an automatic strategy if I have to rollover every expiry date ?

What do you think on this ? keep in mind that I’m not an expert on future …. 🙂

Anyway I would be happy if you can “play” with the parameters of my strategy in order to know your opinion (let’s try on the main index or monetary market).

Thx a lot.



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. vitatrader35 • 03/23/2017 #

    Hello, Deio
    Thanks for sharing the strategy, it’s very interesting.
    As long as I can see you don’t set any type of stoploss. I guess you control the max risk with portfolio management?
    Regarding to the problem with CFD’s, have you tried the same concept with stocks?

  2. DEIO • 03/23/2017 #

    hi vitatrader35,
    regarding stop loss actually there’s not a typical stop loss, but a sort of stop loss you can apply modifying the parameter “tp” setting it to a percentage below zero.
    Now tp = +0.25  but you can try with -0.25  or  -0.5 and check results.
    I’ve never tested on stocks this strategy because in my mind indexes are less risky…. but yes…it is possible.
    For example news on a single stock can be devastaing compared to an index which collect a group of stocks, especailly 
    applying a strategy which accumulate, but on an index I can suppose that even after a huge bear market the price will rise.
    Anyway overnight it’s a problem… but using instruments without this issue this kind of strategy works…. but it is necessary to be patient
    and the number of trade are quite few, and I think that such aspect excludes 90% of traders.
    Thx for your post

  3. vitatrader35 • 03/23/2017 #

    Thank you for sharing and  for explanations too!
    I’ll try to use both (tp and ‘sl’) in a backtesting with stocks and I’ll let you know if I found something interesting…

  4. DEIO • 03/23/2017 #

    have you the possibility to test the strategy on 200.000 bars  (12 H)  ?
    In case let’s try on index:  US Tech 100 (Nasdaq).
    Thanks in advance.

  5. reb • 03/23/2017 #

    I tested on DAX with 200k bars
    Very good results but Big DD  so you need a great amount of capital
    and sometimes  the strat takes 50 contracts
    We need to be very confident on the strat

  6. reb • 03/23/2017 #

    sorry I can t paste an attachement, I don’t know why

  7. DEIO • 03/23/2017 #

    Hi Reb,
    this is due to a size calculation on a % of capital, so the number of contracts is high (as the performance) , but if you change
    the variable (in the two occorrence in the code – substituting sizebuy = 1 ) you should see a reasonable number of contracts (mini).
    thx for your post.

  8. reb • 03/23/2017 #

    Hi DEIO
    I have just opened a topic in the forum with the screenshot of my backtest on dax (section proorder in english)
    It will be easier to discuss about your strat

  9. Bard • 03/23/2017 #

    Hi DEIO,I haven’t had time to run this system. Is this a variation of a volatility break out, no? If so I’m wondering which part deals with the trend direction as surely trading a lower close today than compared to yesterdays isn’t going to guarantee following the trends direction?As far as the cost of overnight funding on an IG synthetic Futures contract the spread of eg 110 tics is the cost of the overnight funding charges. For an EFT / DFB which are based on IG’s fee + LIBOR the calculation is this, (below is an amended version of IG Index email response to my inquiry on cost of funding) :“If you were to hold the DFB contract in ETFs, then the overnight funding cost would be calculated in the following way:The interest adjustment on a DFB is derived from the current one-month interbank offered rate of the currency of the share in which you are dealing, adjusted for IG Index funding.As you are able to trade ETFs in £, the interest adjustment is calculated by adding the latest one month London Interbank Offered Rate (LIBOR) to IG Index’s funding adjustment, usually 2.5% per annum. So, LIBOR is currently 0.26%, and so the total daily interest adjustment to a long position would be roughly 0.008% (0.26% + 2.5% ÷ 365).So to calculate your daily overnight funding for holding an ETF long overnight, take the total value of your position ( £ per point x official closing price of ETF) x 0.008%If holding short positions in these ETFs overnight, you would currently pay a slightly smaller rate of 0.006% x the total value of your position, per night as LIBOR is subtracted not added in this case.Note: LIBOR changes daily and so daily funding, for both long and short positions, will vary from day to day.Forward contracts ( such as the September contract of these ETFs) will not incur any overnight funding charge.”
    Even if the EFT is quoted in $’s (iShare 1-3 yr and 20yr+ Treasury Bond) the overnight funding cost will be in £ if this is the base currency you’re trading in. 
    My email response:Just to confirm a long position on an ishare 20+yr treasury bond held overnight would cost:at £1/tic (100 iShares) = $1.25/tic (to convert to $’s) and it buys 125 iShares, so: £1/tic x current DFB/EFT 20+ yr Treasury price = 120.62 x 0.008% = £0.96/night.IG Index confirmed this.
    I emailed IG Index again to ask how these funding charges could be applied in the money management section of the PRT backtest Strategy creation window:(“If you instead decided to trade these ETFs in $ per point, then the overnight funding rate would be based on the $ interest rate (approximately 0.98% at the moment))As the overnight funding fee will change on a daily basis you could either make an approximation of what the average fee would be ( maybe order fee of 0.01% of transaction ?) and then add spread. Alternatively, you could make 2 backtests; 1 for a DFB contract ( order fee and spread cost specified) and 1 for a forward contract (only spread cost specified).”As a suggestion with regard to money management. I would never try and limit a systems ability to make money. Your largest drawdown hasn’t happened yet but it will increase with the capital growth, so the best course of action would be to use Ralph Vince’s Optimal F strategy to only reinvest the square root of the capital growth, i.e. your capital goes from 10k to 20k but you don’t double the size of your trades (position size), i.e. you only trade the sq root of the increase in capital growth and attribute that ratio to position sizing: The sq root of 2(x) = 1.4. You will effectively be trading a £14,000 account. Therefore position size has not grown as fast as your capital and this will avoid large future drawdowns that will always typically be 50% more than you backtest results ever hinted out. I am not sure how effective Monte Carlo testing is, as this assumes that trades are independent but the Random Walk hypothesis of markets is incorrect and strong price trends exist based on market psychology (fear and greed).This needs to be coded for PRT as I have looked for it here but it’s not in the library:This is a good Optimal F position size overview:’d add the link but this site jumps to the bottom of the page when I try to, and I almost lost this whole post above by not being able to re-access the portion of my post here on this section of the page).Thanks for posting, and I hope the above helps and that someone can add an Optimal F code to PRT?

    • Nicolas • 03/23/2017 #

      Links creation is automatic in comments.
      About the Optimal F position size, you can add a query in forum for sure, seems very interesting!

    • DEIO • 03/23/2017 #

      Hi Bard,
      first of all thanks for the long explanation regarding the issues posted.
      The criteria of volatility break out is nothing new but this is a my simply idea trying to buy nearthe lowest price of the period, avoiding to accumulate to much contracts.
      Currently I use this volatility rule trading ETF on my bank account and, till this the moment it works quite well.
      If we are talking about the same kind of instruments (ETF – exchange traded funds), I am surprised of the fact that on such instruments are charged any type of fee (but it could be that I don’t know something…).
      If I am not wrong they are not derivatives products… isn’t it ?For instance I have been using the Etf with Ticker: LVE (on prorealtime is almost impossible a backtest … too few data).
      Anyway in order to avoid any charges the solution are the forward contracts, but in automatic strategy how can Iaccumulate forward contrats which expiries during the time ?
      Anyway because I’m curious I’m trying to understand your explanation regarding account charging applied by IG andit seems to me that apparently the daily charge applied is not so high.
      I am going to make more some calculation on such issue.
      To be Honest I don’t know the difference between ETF DFB contracts and I’m trying to find something more on the net.
      Speaking about Money Management it’s clear your suggestion about Optimal F and I am going to implement it on my strategy,even though the backtest on only 100.000 bars doesn’t provide a clear evidence of the Money management applied..
      Regarding this argument it can be very usefull the reading of the book of Andrea Unger (maybe you have alreday read it..).
      For Montecarlo simulation for what I know, I think it’s not so easy to create a hystorical series of valid data and thanuse it for a backtest (but maybe it’s my limit…).
      I thank you again I hope to share other topic or to go deeper on the issue we spoke about.

  10. • 03/23/2017 #

     Hi, how do I if I want to end SL? Whats the code?

    • DEIO • 03/23/2017 #

      Hi Eva,
      If you mean the application of stop loss, the strategy doesn’t apply the classical SL, that’s why such strategies are considered risky.
      Anyway as I said in a previous reply, if you want to  see a sort of stop loss effect you can set the variable “tp” (now set on +0.25) on negative value (i.e. -0.5)  and check results which will be better or worse according to the setting of this variable.

  11. Alex975 • 03/23/2017 #

     Ciao Deio,
    interesting strategy.. thanks to show it

    • Bard • 03/23/2017 #

      No worries Deio, I hope the cost of funding calculations help. 
      Re: “trying to buy near the lowest price of the period” – what I meant is, where is the trend filter in the system? After all volatility can drop and you could enter long but still end up buying into a prolonged bear market? So I was just wondering how the system works in those cases, remember bond prices have hit a 300 year high. The only way prices have gone is up! What happens when the bubble bursts or China and Russia introduce a gold backed currency?IG Index have only synthetic Futures contracts, they’re not the eg actual Sept 2017 Futures Contracts although you can still roll them over like normal futures contracts that you’d get at a brokers. I am not sure how you would roll these in a backtest but I bet IG Index support could help? Perhaps if you find out you could update this thread?The IG Index EFT Daily Funded Bet contracts are another synthetic contract and derivative of the underlying bond contracts.I have added a new topic with no PRT code to get Ralph Vince’s Optimal F programmed in to PRT code here: for the  Andrea Unger tip, I am reading Kevin Davey’s Building Winning Algorithmic Trading Systems, he also won the World Cup Trading Championships, it’s a very good book.

  12. Bard • 03/23/2017 #

    I have opened a new thread on Optimal F position sizing (and a better modification that takes into account drawdowns) here: Nicolas, I accidentally used the links creation (insert/edit link) to post a link here in the comment and the “page jumping to the bottom” issue occurred again so I could not get back to my reply/comment to Deio I had just written but not posted  (because the page jumps to the bottom) and I refreshed the page and lost the whole comment… yet again!

    • DEIO • 03/23/2017 #

      Hi Bard,
      Thx for you replies.
      Rgarding the filters of my strategy as you can see on the code the only filter applied is a decrease of the standard deviation together an amount of decline of the instrument (these two conditions aren’t so frequent).
      Maybe it’s not enough  …. but I usually try not to use usual oscillators.
      Another filter that I applied on the strategy is to work only on Friday (if you try that you will see that the number of contracts will decrease and so the risk):
      IF DayOfWeek = 5 THEN
      I agree with you that with a long bear market this approach become too risky (with derivative instruments – less risky using instruments like ETF (no CFD) no margin – no overnight interest – but less gain too…..- I do this since 2010 (real) . But this is another story.
      While in case of trend the only condition is that if I’m not in the market, because I closed the previous position opened and today the price is lower than yesterday, I go in the market again).
      Obviously these criterias doesn’t always work,  the same way classic oscillator/indicator do.
      About Money management I’ll try to read Ralph Vinces ideas.
      In my opinion the real problem with any application of money management is the avaiability of a large amount of bars in the backtest, otherwise
      the backtest has not a real validity and all remain just theory.
      Anyway I hope to post different strategies I’m testing, where finally I can be more comfortable by use of CFD.
      Thx again for your cooperation.

  13. Bard • 03/23/2017 #

    Hi DeioThanks for the further clarifications. I was curious to see how the system worked on the overnight session and switched the official opening hours of 9am to 17.45pm times to:TIMEWORK = 174500TIMESTOP = 090000But it didn’t take any trades? What am I missing? Also what is the reasoning behind using 12 hour bars? There is marginally less drawdown using 4 hour bars (DD=52%.not 55% but still 230% gain – 5th Dec 2012 to 6th Ap 2017)Clearly although changing the IF CLOSE < CLOSE[1] to IF CLOSE < CLOSE[30] and changing tp to 0.50 and acc to 4, will bring Drawdown (DD) down to a more “reasonable” 35% (although it changes the % profit to 164% (from 230%)). You can guarantee the DD will be 50% more than the backtest result during real live trading, right? (Richard Dennis has been known to let DD’s hit +70% but that = not sleeping at night and getting an ulcer…)I will look at this code again, I have an idea for a trend oscillator filter that can be up to 90% accurate. If it improves the system I will update the results here.I also ran the backtest with the same code on an identical chart (that had far less indicators to speed the backtests up) and got two totally different results: pls see screenshot. Any ideas @Nicolas ?CheersBard

  14. Bard • 03/23/2017 #

     p.s. I just tried the above changes on the 1 hour Dax it results in a far more healthy DD of 26% and gain of 121%. Ave trade gain may be a bit low though. (I’ve beeb using the Dow Jones widest spread of 3.8 tics)Maybe also perhaps it would benefit the strategy if it had a rule that made sure it didn’t accumulate more positions after the market has a sharp very large wide ranging bar to the downside (short bar) as this typically signifies further downside movement? 

    • DEIO • 03/23/2017 #

      Hi Bard,
      The use of standard deviation should just avoid To buy during wide bars of bear market.
      Anyway i’ll check Again.

  15. Bard • 03/23/2017 #

     Hi Deio, that’s what I thought, yet I tried it with your parameters (4 hr Nikkei’s) and with the 5 day and 30 day look back for the Close. but the 18th Dec wide bar occurs and the system still accumulates long positions into a steep market breakdown. I really like what you have created. I’m sure with a few more modifications (trend filter) it can attain a far better DD. Let me look at it some more.

    • DEIO • 03/23/2017 #

      Hi Bard,
      please attach the entire code you used which gave you such results on Nikkei, because I can’t find Buy ad 18 dec  (year??).
      I have been working in otrer to find another filter that can help us…on DD
      I also tried the strategy on tiny timeframe, but I think it’s very very much risky.
      Anyway I am waiting for the code.
      thx for you cooperation.

  16. Oskar Bergvall • 03/23/2017 #

    This looks very intresting. I’m trying to add some sort of stop but doesnt seem to work well with it. Sometimes it buys and doesn’t sell…ever 🙂

  17. Oskar Bergvall • 03/23/2017 #

    Maybe it’s possible to add so it can only buy when EM50 is positiv and sell if it goes negative as a “stop” if the market changes?

    • DEIO • 03/23/2017 #

      Hi Oskar,
      it’s possible to add any filter you want, even thoug such good results  strongly depends on the performance index which rose a lot in the last years.
      So pay attention weather index markets should fall down because this strategy could not be so brilliant in the sense that you should accumulate many contracts….
      Adding a stop loss is always a good idea ….. i tried to make a version of the strategy which closes under a certain level and obviously results are not so good…but we are more safe…
      here to code (it’s just an axample):
      //———————————————————————————————–//TF a 6 h//dax min 1 Eur.
      DEFPARAM cumulateorders = trueIF DayOfWeek = 5 THENTIMEWORK = 070000TIMESTOP = 210000acc = 0.5
      period=10stdev=STD[period](close)//LOOK FOR A LOCAL VOLATILITY DECREASE//I WANT TO BUY AGAIN ONLY WHEN BEAR MARKET SHOWS A LOCAL PAUSEif (stdev[0]+stdev[1]+stdev[2]+stdev[3]+stdev[4]) < (stdev[1]+stdev[2]+stdev[3]+stdev[4]+stdev[5]) thenSWBUY=1elseSWBUY=0ENDIF
      IF TIME > TIMEWORK AND TIME < TIMESTOP THENif not onmarket thensizebuy = 1tp = 1IF CLOSE < CLOSE[1] AND SWBUY=1 THENBUY sizebuy SHARES AT MARKETendifendif

    • Oskar Bergvall • 03/23/2017 #

      Thanks for the answer!
      I tried this but it seems to work alot worse for some indexes/bonds. I had one idea that could work: If it ONLY acts when for example MA200 is very positive. The few times your original code works bad is on downtrend and MA200 is mostly down then. I suck at programming but going to see if I can get it in and test.

    • Oskar Bergvall • 03/23/2017 #

      I tried adding MACD. So if will only buy if the minussignal crosses over to positive. I tried on a bond in Sweden called “fingerprint” which went down 37% some time ago. With the original code backtesting I lost all my capital. With the MACD it didn’t buy at all since the signal was negative. Requires more testing, and of course it could still go bad, but abit safer 🙂
      DEFPARAM cumulateorders = true
      indicator1 = MACD[12,26,9](close)c1 = (indicator1 > 0)
      IF c1 THENTIMEWORK = 070000TIMESTOP = 210000acc = 5
      if justone = 0 thencapital = 10000 * pointvaluejustone = 1endif
      perccap = 0.5margin = 0.5 * close * pointvalue / 100period=5stdev=STD[period](close)//LOOK FOR A LOCAL VOLATILITY DECREASE//I WANT TO BUY AGAIN ONLY WHEN BEAR MARKET SHOWS A LOCAL PAUSEif (stdev[0]+stdev[1]+stdev[2]+stdev[3]+stdev[4]) < (stdev[1]+stdev[2]+stdev[3]+stdev[4]+stdev[5]) thenSWBUY=1elseSWBUY=0ENDIF
      IF TIME > TIMEWORK AND TIME < TIMESTOP THENif not onmarket thensizebuy = ROUND((capital *perccap /100)/ margin)tp = 0.1IF CLOSE < CLOSE[1] THENBUY sizebuy SHARES AT MARKETendifendif

  18. Oskar Bergvall • 03/23/2017 #

    With tp= -0,1 and with the MACD I’d say it’s very safe in 4 hour I cannot find a single fail.

    • DEIO • 03/23/2017 #

      Hi all,
      I posted a new version on the related topic.

  19. rpcasanas30779 • 03/23/2017 #

    Hi, Tried test this strategy on USTech 100 ( Nasdaq) and looks excellent return ( 90+% Accuray) 2kbars in 1H TF. By the way this is in wlak forward method. My query is, how you will set contract when enabaled at ProOrder?

  20. hhintzen • 03/23/2017 #

    Hey Deio,
    Good strategy, but Why only long postitions??
    We are once again come in a baer market, what does your system do than? Is it possible to test a system in a baer market? oOly short positions ?Harry

    • DEIO • 03/23/2017 #

      hi Harry,
      surely it’s possible, I will try …. even if I think that the setting could be a little bit different (I suppose), keeping in mind that
      usually the bear market is faster (during the falling) than bull market (during the rising).

  21. hhintzen • 03/23/2017 #

    Di Deio,
    I know, i test your system. I will trey what it does in short market.
    Can you tell me how I can turn strategy from long to short ???

  22. Koenigsleon • 317 days ago #

    (2min/dax Basis, its for me better)

    DEFPARAM cumulateorders = true

    indicator1 = STE[10](close)
    c1 = (indicator1 < 1.7)

    TIMEWORK = 070000
    TIMESTOP = 210000
    acc = 5

    if justone = 0 then
    capital = 10000 * pointvalue
    justone = 1

    perccap = 0.5
    margin = 0.5 * close * pointvalue / 100
    if (stdev[0]+stdev[1]+stdev[2]+stdev[3]+stdev[4]) TIMEWORK AND TIME < TIMESTOP THEN
    if not onmarket then
    sizebuy = ROUND((capital *perccap /100)/ margin)
    tp = 0.25
    IF CLOSE tp then
    capital = capital + PERFC
    if (((CLOSE-TRADEPRICE)/TRADEPRICE)*100) < -acc AND SWBUY=1 then
    sizebuy = ROUND((capital *perccap /100)/ margin)

    SET STOP pLOSS 19.0

    • DEIO • 315 days ago #

      HI Koenigsleon ,

      Maybe there is some mistakes in the code you pasted above.
      I can’t use it because I get errors.
      Anyway pay attention to the backtest because on TF 2 min you can’t obtain a solid backtest .


  23. sublime06 • 154 days ago #

    bonjour Deio. la stratégie est vraiment exceptionnel. 😉 malheureusement je n’ai pas de connaissance en codage. pourrait tu expliqué la méthode du déclenchement de la position pour comprendre le fonctionnement ? je ne s’ai pas faire par programmation.. mais si je peu avoir la création simplifier, je pourrait essayer d’amélioré le système. j ai de très bon résulta en réel, ( 1 mois % gain 89%/ Ratio, 21,82 ) mais si je change les paramètres j ai beaucoup d’erreur de code et je ne peu les résoudre. Merci

  24. DEIO • 153 days ago #

    Hi sublime06,

    I tank you for the compliments, but first of all I STRONGLY want to warn you to use such
    strategy in real, because deep and long bear market seasons could last a long time during which
    the strategy would go on buying and I don’t know if it is what you want.

    Don’t forget that markets in general are rising for7/8 years, so it’s easy that strategy with a long goal
    are gaining money, so be aware of it.

    About the strategy I had tried to comment inside the code the logic code, but be patient but I can’t say more
    that that.

    Anyway the base concept is to buy only when the volatility of the market decrease due to the fact that when it’s increasing
    easily we are in a bear market that probably will go on, so I wait for a decrease of it and then BUY.

    I hope I am usefull for you and anyway go on try to code by using the manual or finding on the site the answers to the many issue opened which are a lot !

    thx again

Register or


avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar

+1 more likes

Related users ' posts
Onetime Bonjour je viens d'essayer votre indicateur sauf que moi j'ai pas les signaux ( les flèches ...
Onetime Pardon non enfait ils sont bien la merci
GianfrancoCeck Salve Nicolas. Ho provato ad inserire anche questo suo indicatore, ma sulla T3 ho sempre la...
danibo JR1976, thank you for your reply. Still I can't make the TS work with the US 550 because ...
JR1976 NOthing change ... tried with CFD US500 cash mini
EchnatonX Hallo Im Demomodus bei IG habe ich das Problem, dass oft keine Orders ausgeführt werden kön...
Nicolas Indeed, if you are not willing to loose, you will always win. Averaging down losers can carr...
David You're always safer going Long especially with averaging down on an index as the probability...
Oskar Bergvall  I noted Davids and Nicolas remarks. Could it be possible to make an indicator for contraria...
Julio Hi Doctrading, Is it possible to flip this to a "going bearish" by simply switching the cod...
Doctrading Hello, Yes, you can do it very simply...
Tarek Laaroussi Hi doctrading i am the one who sent you the email first thanks for the code . It really wo...
Fabio Anthony Terrenzio this strategy works only in a well defined trend
brosly Good afternoon I am trying to get the complete code of lex strategy made by adolfo since I s...
dreif123 hi Adolfo, is Alex Auto Trading Botindex working on DAX as well ? if so , can you post the...
Doctrading I forgot to write at the beginning :  a = 50 b = 50 These are intermediate levels Sorry
DerPat Thank you. This one could be an aid in my current research on stochastics.
Nicolas Ahah, I'm not the author of this one :) I know you are a great coder Wilko, why don't you p...
Wilko Thanks for the flattery! I will, I promise.  /F
Nicolas Still don't have seen anything from your own :) You promised me! Ahaha 
Adolfo Onrubia Hi, fisrtly thanks for your interest on it. :) Variable "c" is to set your initial capital ...
Adolfo Onrubia Ups! Sorry. Variable "S" is to set an specific Spread if needed. Could be "0", or the distan...
GraHal Hi Adolfo, big thank you for your code, but I am a bit confused. Spread is the difference b...