Grid Trading – Back Testing

It is essential to back test the Grid Trading system before considering putting it into action. If at all. I suspect few do so.

According to Investopedia :

Grid trading is when orders are placed above and below a set price, creating a grid of orders at incrementally increasing and decreasing prices. Grid trading is most commonly associated with the foreign exchange market. Overall the technique seeks to capitalize on normal price volatility in an asset by placing buy and sell orders at certain regular intervals above and below a predefined base price.

Grid trading is common in the forex and currency world and takes a number of formats. I set out to test the idea as faithfully as I could, after coming across the scheme here. I had been taking an interest in trading bots, and since I code in Python I decided to put the Dexbot Staggered Orders strategy to the test. I believe the developers and backers of the project are trading the strategy without back testing, such is their confidence in it. And good for them.

I tend to take a rather less sanguine approach. It is always amusing, for any given trading strategy, to look at what is being presented to retail punters.

Here is a sample for the Grid Trading Strategy:

Forex Grid trading is a clear winning technique. See the LIVE client trading results & how it works.

The Grid trading is a type of trading strategy that profits from the sideways as well as trending market conditions.

It works well in volatile, ranging markets, where there isn’t a clear trend.

Grid trading very viable method of automated trading .

I have spent far too many decades in financial markets to have much that much confidence in anything, Perhaps I have been lucky enough to avoid some of the worst pitfalls. Perhaps I have learnt to tailor my risks to my aptitude to bear them. Whatever.

These days my interest centers around the novel. Or at least something that is new to me. To that extent, Dexbot fitted the bill. It trades crypto currencies on decentralized exchanges on the Bitshares block-chain. And it is a bot – automated trading software

There are none of the fancy orders you find in well established financial markets – no stop loss orders, no fill or kill….none of the sophistication you find elsewhere. You simply make or take bids and offers.

I chose to ignore leverage in my back testing. The crypto markets are volatile enough without adding rocket fuel. More like trading futures or the Vix.

There are probably dozens of different approaches and ways to construct and back test a “grid”. Happily, if you have a little coding experience you can try them all.

I took a few currency pairs USDCHF, USDJPY, EURUSD, GBPUSD and downloaded daily data free from AlphaVantage. It gives me daily bars in OHLC format. If markets are fractal, then that should suffice for my purposes. If not – well get some minute or tick data.

I created a whole list of user adaptable parameters. Note in particular the 4 different “modes” I chose to test. Doubtless there are countless other “modes” I haven’t thought of but these should be easily enough programmable given a little effort.

Bet Size. “bet_size” – represents the trade size in terms of a percentage of the amount of total equity held at the time of the relevant trade.

Quote / Base. “quote” and “base” represent the amounts of quote and base currency held at the start of the test.

Profit Target. “profit_target” is used to construct the list of sell orders from the list of buy orders (the buy orders are created first). Each buy order will be matched by a sell order placed at buy order + the profit percentage.

Number of Trades – The Grid. “num_trades” – the number of buy and sell orders created. If this number is set to 100, 100 buy orders and 100 corresponding sell orders will be created.

Start and End.” buy_start” – “buy_end”. This represents the range of order prices created. If “num_trades” is set by way of example to 100, 100 buy orders will be created logarithmically spaced between “buy_start” and “buy_end”. In other words this setting creates your “range” or “grid”. Sell orders are then based on buy orders + “profit target”.

Modes. Mode 1 is plain vanilla. Each order is executed as, when or if it comes into range. Mode 2 uses a “set_point”:- it is customary when creating a “Grid” to decide whether you think the price is going to trend or mean revert. If your belief is that the instrument mean reverts around a set_pont, then try mode 2. Buys of the base currency will only be executed when the price is below the “set_point, sells of the base currency will only be executed when the price is above the set_point. Mode 3 explores trend following: user defined short and long moving averages define the trend. The base currency will only be sold if the trend is down and bought if the trend is up. Mode 4 encompasses mean reversion and only takes trades which are against the near term trend.

I find it helpfull to view my results in three different ways. I have to be able to see the results as CSV files, which I can analyse further with Excel to show my my mistakes or misunderstanding. Or indeed to enhance my understanding of the way a given system works. Then I like to produce numerous trading statistics showing CAGR, Drawdown and all the usual culprits. Lastly I have to see copious charts.

And have I come to any firm conclusions on the Grid Trading Strategy? These days I am none too keen on venturing opinions. In life as in markets its every man for himself. Each trader needs to spend many, many hours researching his strategy and providing his own answers. Back test for yourself – don’t take anybody else’s word for it when it is your money at stake.

  • Charts


  1. thank you for your posts on this subject. I have an idea that in manual back testing seems to work and I now believe it to be a grid system based on what you outlined above. As with my other ideas my concern is the costs associated with many open orders. Do you know of a way to mitigate the spread, commission and swap – whilst also grid trading?


  2. Hello Neville. I think one has to decide first the number of trades and the size of the grid. If you are going to have only a few trades (10 perhaps?) and a wide profit margin (say 10%) then I guess open orders are not too much of a worry and you can manage them manually, although they would need to be watched closely. I think one would have to adjust the size from time to time in accordance with the then existing account size. Even if you want to trade a larger grid there is no reason why you should not continue to trade manually but just put on a smallish group of orders close – ish to the current price. But of course the danger is sudden large shocks which take the price way beyond the grid. Automated software (such as Dexbot for instance) obviously handles and sizes all orders for you and can keep putting them on and taking them off as the price moves up and down. You still face the same risk if you only put on a small number of orders related to your total grid size. As regards spreads, commissions and so forth I imagine these are hard to keep in hand as a retail trader? You have only to look at some of the absurd spreads charged by retail forex brokers and the likes of IG Index. Perhaps anyway it is worth looking at an open source software effort like Dexbot so that you can see how orders are handled. Also of course you can always build in an exposure limit. In my back testing software, because I wanted to avoid margin, I provided that zero exposure was the limit either side of the trade – in other words no more quote could be bought if the base was at zero and no more base could be bought if the quote was at zero. This figure could easily be adjusted in back testing and in an automated bot. You might want for instance for your account never to go below a 25% exposure to the base and above a 75% exposure to the quote. The trouble is, as you know, once you start adding rules it is difficult to stop. Hope these thoughts may be of some help.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s