We are glad to announce that new Dev 2 build of an upcoming 136 version of StrategyQuant X was just published. You can download it from our Download page under …
Range bar strategies step-by-step
In this article I’ll explain the step-by-step process of building a strategy for range or renko charts on MetaTrader4. The example below will use range bars, but the same process can be applied also to renko charts.
What are Range or Renko charts?
They are alternative charts that don’t display data in blocks grouped by time (5 minutes, 15 minutes, 1 hour) but by other criterion.
For Range bar, one candle on the chart represents given range, for example 10 pips. So every time market moves by another 10 pips a new candle is drawn.
NinjaTrader platform has build-in support for these chart types, so the only thing you need to do to use these charts in SQ is to export the chart data as same as for any other chart type.
MetaTrader4 platform doesn’t natively support Range or Renko charts, in order to display and use them you need third-party plugin. Very affordable provider of Range/Renko plugins for MT4 that we tested and can recommend is AZ-INVEST.EU
What you’ll need
- MetaTrader with an online broker connection
- Tick Data Downloader or similar program to download tick data
- AZ-INVEST Range bars plugin for MetaTrader (Pro version with special CSV2FXT scripts)
- StrategyQuant version 3.6+
- Birt’s Tick Data Suite if you want to test your EA on range bars in MT4 (not necessary for trading them)
- Obtaining the data
- Installing and using the AZ-INVEST Range bars plugin
- Generating Range chart data using CSV2FXT script
- Importing the data file to StrategyQuant
- Strategy building process
- Testing your new strategy in MetaTrader
- Trading your new strategy in MetaTrader
Obtaining the data
You should use high quality (preferably tick) data to compute accurate range or renko charts. You can use our Tick Data Downloader to download high quality tick data for free.
Just download the data for your selected symbol and export it as tick data to CSV file. In this example I’ll use GBPUSD data.
Installing and using the AZ-INVEST Range bars plugin
MetaTrader4 doesn’t natively support Range / Renko bars, you need to use external plugin that will enable this functionality. Purchasing and installing this plugin is beyond the scope of this article, it is a simple process.
AZ-INVEST plugins do have their own documentation and standard installer that will lead you through the setup.
Generating Range chart data using CSV2FXT script
With the Pro version of the Range bars plugin you’ll get a set of special CSV2FXT scripts that should be used to generate data files that will be needed for backtest.
If you properly installed the Range bars plugin you should see these scripts in your MetaTrader.
- Start your MetaTrader terminal.
If you have Tick Data Suite installed DON’T start TDS at this point, as the script will not run properly under TDS.
- Open your MT4 Data folder. To find out what is your data folder, open MT4, head to File -> Open Data Folder, which will open an explorer window with your MT4 data folder (typically looks likeC:Users[username]AppDataRoamingMetaQuotesTerminal[32_character_hex_string]).
- Copy the CSV file exported from Tick Data Downloader to folder MQL/Files in your MT4 data folder.
- Open the chart for GBPUSD, 1 Minute. You should always use 1 Minute the chart of the symbol you want to work with. Then go to Scripts and start CSV2FXT_rangebars_mod script.There are 3 important parameters:
- barSize – for Range bars we have to choose the size of bars in chart
- StrategyQuantExport=true – this will ensure that the conversion script will generate also data file for StrategyQuant
- Spread – it is best to use fixed spread, as StrategyQuant cannot use variable spread on Range / Renko charts
Then click on OK. This script will generate .HST and .FXT files necessary for testing in MetaTrader as well as data file for StrategyQuant.
This data conversion will take some time and you’ll see its progress on the chart.
When it is finished it will show dialog asking you if it can copy the new HST and FXT files to the appropriate folders. You can clickYes
Importing the data file to StrategyQuant
The next step is importing the generated range data file to StrategyQuant so it can be used to backtest strategies. If you used StrategyQuantExport=true the script generated new data file containing range chart data in your MQL4/Files folder.
We’ll import this file to StrategyQuant.
Open StrategyQuant, go to Data Manager and create a new symbol GBPUSD_range10:
Now select the new symbol and import the file GBPUSD_10pip_rangebars.csv generated in previous step.
You will see the new data with Timeframe type Intraday.
That’s virtually all! Now you can work with the new symbol in StrategyQuant as same as with any other data and generate new strategies for it.
Strategy Building Process
Building strategies for Range or Renko data is as sam eas building them for any other standard timeframe. You can of course use In-Sample and Out-of-Sample periods, robustness tests, optimizations, etc.
For more information on complete strategy building process please refer to this article.
Testing your new strategy in MetaTrader
Let’s say we generated some nice strategy in StrategyQuant and we want to test it in MetaTrader. In this example we’ll use Strategy 0.2232 below.
To test your range strategy EA in MetaTrader you need Tick Data Suite. Start your MT4 using TDS. Then go to Tools -> MetaQuotes Language Editor and create New Expert Advisor with name Strategy 0.2232.
Copy & paste the strategy EA from StrategyQuant to MetaQuotes Editor and compile the strategy.
Then open Strategy Tester in MT4 and choose GBPUSD symbol on 1 Minute timeframe. If you didn’t do any change, you still have the .FXT and .HST files generated by CSV2FXT scripts in their place and they will be used in backtest.
Select your strategy and click on Start to start the backtest.
When the test is finished you can check the chart, you’ll see that the results are as same as in StrategyQuant.
Trading your new strategy in MetaTrader
Trading the strategy in MT4 requires opening a range chart. Go to the GBPUSD, M1 chart and then find RangeBarChart indicator in Navigator -> Custom Indicators. Apply this indicator to the chart with the correct setting – in our case we used pip Range = 10 before.
Once you’ll do this you’ll see the following comment below your chart:
Now you need to open the generated offline chart – GBPUSD,M2 (as presented in the displayed comment) to access the LIVE RangeBars chart:
Open GBPUSD, M2 offline chart for 10.0 pip RangeBars.
To do this go to the File menu in your MT4 terminal and click on the Open Offline menu item:
The “offline” chart will start “ticking” when new quotes are received by MT4 and new bars will be created as they are formed.
Please note that every time the plug-in is attached (or MT4 terminal is restarted) it will recalculate all historical data so keep this in mind when you set the “RenderUsing1MhistoryBars” to 0 (all ofhistory).
Despite its name this is live range chart and you can normally add EA to it:
This EA will then normally trade on this range chart on demo or real account.