Averaging down techniques in automated trading

Without martingale or averaging down, automated trading wouldn’t have been so popular over the internet in the last years. Promised of eternal money returns without any cons is of course not real. However,  learn to code “grid” orders is educational and that’s the purpose of this article.

It surprised me that no one has ever shared any averaging down (also called grid) trading strategy on the website so far. Since this is something very interesting in terms of coding techniques, I decided to write this blog article to share simple codes and thoughts about this so popular way of trading around the internet.

I have seen so much trading strategies dealing with averaging down / grid other the last years, and of course coded myself a lot of them in many different ways that you can call me a “guru” 🙂 In fact, grid strategies are popular and interesting in a way that any loosing or not so good strategy can be turned into a money machine.. Almost like martingale position sizing, averaging down never offer to loose a trade (in its pure and simple version) and that is the main reason you are always a winner while trading it.

Have you ever seen this kind of equity curve on the internet? Charming isn’t it?

grid-trading-backtest-strategy

What is averaging down trading? Why is it called “grid”?

Recover loosing position(s) not closed is the main purpose of averaging down.

Let’s take an example of a simple moving average crossover trading strategy:

In this picture, we are trading 3 EMA vs 10 EMA, we took a short trade on the first bearish crossover that occurred at 9:00AM..

averaging-down-first-entryWe don’t have any stoploss on this trade and it is not going in the good direction. Since we are convinced here that the trend is bearish and many other traders are thinking the same as us, we decide to add another sell order the first time we’ll see another red Heikin Ashi candlestick.. let’s do it!

adding-orders-gridSecond order is added .. What we expect now is the price to retrace at least, to the average price of open position:

_ first position opened @ 10440

_ second order opened @ 10460

if the price go down to at least to (10440+10460)/2 = 10450 points, we are safe.. The first order loose 10 points, while the second one gain 10 points.

.. but in our example the price didn’t go down and so we add another order @10463:

third-order-averaging-down-techniquesNow the average price is : (10440+10460+10463)/3 = 10454.3

We are building a grid of sell orders, to trap the price where we want it to, at our orders’ average open price.

Price didn’t go south in our example, a fourth trade opened @ 10470 with a new average open price of the whole orders basket @ 10468.25. Finally after some hesitation, price drop down to the average price and all orders could have been exited for a compound little profit or breakeven.

complete-grid-orders-example

We have successfully managed the 1st loosing trade .. while added 2 other loosing ones in the same row we have also dig into our money balance with a large drawdown .. but hey! we survived! 🙂

When to average down the trades?

As you have probably now understand, this orders management technique can be added to any strategy with also any way of order re-enter you can imagine : fixed points step, dynamic one, new signals, support/resistance etc.

There is no pre-defined rules of adding orders, that’s up to your trading style and your ability to spot good re-entry point when price will tend to reverse. But something I learned so far, it is that the more orders in the grid, the easier to return to the average price of the orders’ basket.

Grid / averaging down codes for prorealtime

You’ll find below the code of the simple example strategy I explained in the article. This is a simple “framework” you can extend in many ways in your own strategy. So feel free to explore, discuss and share what you found in the forums or/in the automated trading codes library of the website.

To build the code, we only need to know if we are or not already on market with shortonmarket, if we are above the last trade entry with tradeprice, and monitor the average open price with positionprice.

grid-orders-with-prorealtime-codes

 

Like always, you can download the code in the attached file at the end of the blog post.

Never loose again, great! Where is the limit of averaging down?

This is dangerous, like any other martingale system, with averaging down, you are trying to beat the market and that’s not possible at all. If time were infinite and if you could have infinite money on your trading account, that could be possible .. but stop dreaming life is not a scifi movie! 🙂

The only con of grid orders is that you have to face up with large equity drawdown with many lines of loosing orders in your trading console. Whatever the strategy you applied to enter at first signal and average down, if you don’t offer to loose, you’ll met this con.

Through my trading programming services company, I came across many customers that asked this kind of trades management in their strategies. I even know some people that make a living with grid strategies, so I believe (and I’m sure it is the case for any automated trading system), that you need to rely on your strategy if you decide to let a code script deciding for you when and how to enter the market. So it’s up to everyone and I’m not here to give you secret weapons to be rich.. because there are no secret weapons!

Share this

  1. Philippo • 11/08/2016 #

    Thanks Nicolas, at the moment I am favouring a system which gets out as soon as it’s wrong so grid trading is not my cuppa right now. But I am interested in this area for another reason: my system is very enthusiastic, if it’s right, more position, right again? again more positions! which sees some tremendous accelerations! But I see that the tremendous gains are easy to lose, so was thinking about ways to step out of large positions into medium and small positions.  I look at PositionPerf quite closely, but on a purely price action basis am interested in seeing when is time to accelerate the position and when is time to decelerate the position. I will post but any ideas are welcome.  Thanks again. 

  2. verdi55 • 11/08/2016 #

    From my experience, averaging down – as well as building pyramides – has no advantage when your strategy is basically good. In most cases, this will only decrease the maximum result per contract, and it is better to run a strategy first to the maximum number of contracts possible (without much slippage), before you start to average down or to build pyramides. Besides that averaging down can be highly dangerous and lead to enormous drawdowns, it is mostly a sign that your basic strategy is not good, when you need to do it.

    • Nicolas • 11/08/2016 #

      I agree with you. Averaging down is used to avoid closing bad trades and then often lead to accumulate losing orders… A bad idea in most cases. The purpose of this article is to teach people different manner of dealing with orders with the code and because this way of trading is largely developed in the automated strategies community.

  3. verdi55 • 11/08/2016 #

    Just by the way  –  Bernie Maddoff showed a similar equity curve to his clients as a performance proof of his funds. Now he is in jail – and his clients poorer by some 50 billion dollars…  🙂

    • Nicolas • 11/08/2016 #

      I also came accross many hedge funds and others dream seller with this kind of equity curves in their commercial documentations 😉

  4. Alessio • 11/08/2016 #

    Sto tentando di fare la versione long, ma ho dei problemi a scrivere il programma, successivamente vorrei fare una versione per l’intraday.
    Gentilmente mi date una mano Grazie
     
     

  5. leombg • 11/08/2016 #

    Mainly didactic curiosity: to the described strategy there is a way to add a command to put a limit on the drawdown, for example when the accumulation of orders makes me lose 300 dollars close the positions (exitshort) and then start again with the strategy. Thanks!

    • Nicolas • 11/08/2016 #

      Yes, we could do that with a limitation on a negative floating profit condition. try with:
      // test the current floating profit and close orders if needed
      floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
      if floatingprofit>=300 then
      SELL AT MARKET
      EXITSHORT AT MARKET
      endif

    • leombg • 11/08/2016 #

      Thanks for the idea! I tried to insert the proposed code at the end of the my program but it doesn’t work. It returns no errors but the drawdown is over $ 300.

    • Nicolas • 11/08/2016 #

      Sorry it should be negative:
      if floatingprofit<=-300 then
      SELL AT MARKET
      EXITSHORT AT MARKET
      endif

    • leombg • 11/08/2016 #

      Now it works correctly !! Many thanks, it is a good starting point for study ..

avatar
Register or

Top