Therefore, such approach as above can only be used in situations where we run the exploration applied e. If you want to display the value for other bars than last bar of selected range, you need an extra column, like this:. There is an alternative method to display values that change on bar by bar basis as letters though.
Instead of displaying full string we can display single characters in a column using formatChar parameter, as shown in the code below:. Note: If you are using version older than 5. For the purpose of calculating the correlation between two data-arrays, there is a Correlation function in AFL which can be used.
We can also use Exploration feature to display a correlation matrix e. The below example shows the process for Watchlist 0 members. Be careful and try not to put items in the watch list because it would need to create a table with 10K columns. Windows has some limits on pixel width of the list view and it would truncate display when the display width scrollable area inside list exceeds pixels.
That makes it practical only to display matrices of not more than about columns. In order to add analysis results to a selected watchlist manually, we can use context menu from the results list:. There is, however, a way to automate this process and add the symbols to a watchlist directly from the code.
To do so, we need to: — check if our Filter variable was true at least once in the tested Analysis range — based on the above condition, use CategoryAddSymbol function to add tickers to a watchlist. Additionally, we can erase the watchlist at the beginning of the test if we want to store just the new results. One of the most powerful features of AmiBroker is the ability of screening even hundreds of symbols in real-time and monitor the occurrence of trading signals, chart patterns and other market conditions we are looking for.
This can be done in Analysis module with Scan or Exploration features. Both these features allow for continuous screening of the database in real-time conditions. The following procedure shows how to configure basic scan formula and generate alerts when conditions coded in the formula are met. Then in the Analysis window select Apply To: All Symbols, Range: 1 Recent bar , this defines which symbols are included in the screening and what time-range will be shown in the results list.
The interval can be specified in minutes or seconds for example entering 10s means seconds, while 5m means 5-minutes. The below example uses second repeat interval:. The results window will show the hits and generated alerts will also be logged in Alert Output window and the scan will be automatically repeated every 15 seconds in search for new signals.
Repeat the process for other symbols remember to draw the trendlines in the same chart pane. December 23, Using multiple watchlists as a filter in the Analysis The Filter window in the Analysis screen allows us to define a filter for symbols according to category assignments, for example watchlist members or a result of mutliple criteria search. Click on List 1 , then in the bottom part of the Symbols window mark all tickers. The My new understanding of volume and volume has stopped.
Balance of Power BOP is an oscillator that measures the strength of buying and selling pressure. The volatility ratio is a technical measure used to identify price patterns and breakouts. This works as a scanner to find candles that formed as bearish flips.
Also can plot arrow to show which candle has formed bearish flip on the price chart. Pivot Fibo indicator is used as an improvement of classic Price Pivot Point indicator. The problems with classic pivot point are as follows: The formula is based on daily candles, hence making Some code issues have been corrected in this version. In addiiton the following features have been added - Facility to plot candle sticks - Various Bar colouring option - Unique strength B This indicator is used as a buy and sell area on a stock.
If the price crosses the pink layer, you can take a buy position. If you touch the teal layer, you can sell it first. Please use wise Green arrow indicates long, Red arrow indicates short. Green arrow indicates long Red arrow indicates short.
Please check before any use. Thanks to someone who wrote this afl code. Currently, I have changed the code by adding a scanner to look for some stocks with closing price conditions above the midline. Please use wisely as ne This scanner for you if want to search stocks when 3 bars after MA 5 cross MA Filter by Volume more than 1. Beta is a measure of the volatility of a stock compared with an index or average. If the bars are below red volatility band std deviation of 1, This indicator is used simply to see price movements or smart money movements to follow them.
This indicator uses volume up or down, price up or down and volume to buy or sell price. This indicat Moving average between open and close provides better signals during trending market. The below script generates buy green arrow , exit buy blue arrow , sell red arrow , exit sell yellow sig Searched for an AFL but what I found was a pinescript code.
So, Converted the pinescript code to AFL. This is my interpre You can use this "switch code" to trigger a trade that will execute only once a month.
This is where you build the database of stocks that you want to do your analysis and backtesting on. Once you create a new database, you have the option of pulling data straight in from a third party plugin.
My stock data provider is Norgate which works seemlessly with Amibroker. We will look at this more closely later. You can import different time frames, not just daily prices. You can go all the way down to 1-min and tick data if you want. The shorter the timeframe the bigger your database is going to get. So if you want 5 years worth of 1-minute data, you will need to set the number of bars to roughly , If you have 20 years of EOD data you will need to set the number of bars to roughly You can use the wizard to import stock data, sentiment data, fundamental data etc.
This means you can import your data without the need of a third-party plugin. Then you open up Amiquote and Amiquote is going to download data from one of the available sources and import that data straight into your Amibroker database. Here is a screen grab showing the Amiquote interface:. They come in the. Here is a list of Nasdaq tickers already created:. Once you have your list of symbols, set a date range and pick a data source such as Yahoo!
Next, click the green arrow to start the download. That will automatically populate your Amibroker database with the data for all of those ticker symbols. Next time you go into Amibroker, each ticker can be loaded up by clicking in the symbol box at the top.
You can also access the tickers via the Symbols window. Before we move on, I should point out that free data is really good for getting started. But there are also problems with free data which you should be aware of. It can contain holes and is not always adjusted for corporate actions like stock splits.
As I mentioned before there are many data providers available. I can also recommend data from Sharadar for fundamentals and eSignal for intraday data. Learning how to use Amibroker would not be complete without looking at charting. Amibroker provides lots of technical analysis tools and indicators that we can look at. Once you select a stock symbol, the data will populate in the main chart window. Hover your cursor over any price bar and a small window will pop up with some useful information like the date, the open, high, low and the close price.
For example, you can drag a moving average from the left and drop it on to the chart. That will bring up some adjustable parameters. You can set the moving average to use the close price or something else. And you can set the periods, the colour and the style. Click OK and the moving average overlays on to your price chart. You can also create your own indicators using Amibroker formula language. If you want to zoom in, use the green plus arrow on the right hand side.
Just below that you can also switch timeframes between daily d , weekly w and monthly m. The price chart in the centre is called a window pane. In the graphic below there are three panes. A price chart takes up the top pane. Volume is in the middle pane and MACD indicator moving average convergence divergence is in the bottom pane.
For example, right click on the price chart and you can adjust any of your parameters such as your moving averages. You can also Edit the formula or delete any of the indicators. You can also move the panes around, maximise their size or remove them completely. If you close a pane by mistake and end up without a price chart go back to the chart window on the left and hit the basic charts dropdown. Double click any of these items to bring up a brand new pane. Price all in one brings up the price chart for the selected ticker complete with Bollinger Bands, volume and moving averages.
Whereas double click just Price and the default price chart will return to your main chart window. For example, you can plot Apple in the top pane and then Microsoft in the bottom pane using the foreign chart. This process works for anything in the charts window.
Whether its price, volume or an indicator, everything will get its own new pane if you double click it. As well as using chart panes, there are also sheets. You can have different charts and different indicators on the various sheets. There are 8 sheets available and you can rename each one.
Another thing you can do is open up more chart windows. You can set the symbol to something else and then flick between the two charts to compare diffrences. When you have multiple chart windows open you can click into the Window Menu and cascade them. You can arrange the windows vertically or horizontally. You can also make the windows floating and spread them over to another monitor. A useful feature with the chart windows is to use the padlock to lock a chart. You can also link charts together.
So if you set the symbol link to blue, every other chart with a blue symbol link is going to revert back to the same symbol. The Charts window lets you set up the different price charts. The Symbols window lets you search through different markets and watchlists to find the symbols you want. Layouts is where you can save the current workspace. Amibroker also comes with a selection of drawing tools. Trend lines, horizontal lines, channels, pitchfork, circles.
If you want to delete them just right click and delete all studies. There are also indicator drawing tools such as Fibonacci extension, Fibonacci arc, Gann square and Gann arc etc. As mentioned already in this Amibroker tutorial, you can also create your own indicators by going into the formula editor. After writing the code for your formula you can clik Apply Indicator or Insert Indicator and that will plot it onto the chart or into its own pane.
You can also place indicators on top of other indicators. For example, the following graphic shows a period moving average overlaid on top of a 2-period RSI:. In the View Menu on the toolbar, you can turn the cross hair on or off, change the style of the chart and the scale.
You can also do that using right click. Insert is another way to insert drawings like trend lines, and zig zags and indicator lines which we talked about earlier. Format works with the drawings that you put on the chart.
Symbols is where you can manage the different tickers in your database. You can create new symbols, delete symbols and create watchlists. You can also go into the quote editor to see the actual quotes for each symbol. This lets you fix any errors that you have found in the quotes. Analysis is where you can open up the formula editor or new analysis window. As always, the best way to learn Amibroker is to get stuck in and start experimenting. The Tools Menu is where you can purify your database, maintain indicators and set up third party plugins.
You also use this menu to access Preferences to customise your setup. You can change the color of your charts and candlesticks and set up your time intervals. One thing you might want to look into is the decimal settings and the base currency. When you start Amibroker, you create a a database and import your historical data for all your stocks.
Obviously, a good idea is to organise your stocks into smaller groups so that you can easily do your analysis on them. In Amibroker you can create new watchlists and put whatever symbols you like into them. A simple way to do that is to right click on the symbol in the symbols window, and then add the selected symbol to the watchlist you created. If you select more than one symbol amibroker will let you add those symbols all at once.
You can also type in the symbols separated by a comma. The main advantage of using watchlists is that you can sort your stocks into smaller groups and that will let you do your analysis more efficiently and quickly. It allows you to organise your stocks to create more logical backtests.
If you have Norgate Data, you will notice that there is a sophisticated hierarchy of watchlists already set up:. When it comes to backtesting or scanning, you open a new Analysis tab. Then click the small green funnel icon and select the watchlist that you want to scan or backtest on. A scan is a quick way to search through a watchlist for any symbols that meet any of your buy and sell rules.
These are the rules that you have written into the formula editor. A scan works well when you already have a strategy you trust. You simply need a way to find new trading signals so you use the scan function to return those on a bar-by-bar basis.
Scans are quick and easy whereas explorations provide more control and customisation. To get to the Amibroker Formula Editor you have to click into the small hammer icon. This is the starting point for writing any Amibroker AFL whether it is a scan, backtest, custom indicator or exploration. An exploration is similar to a scan but you can customise the output. So with an exploration you can produce a much more detailed report. To run an exploration, open up the formula editor.
Filter tells Amibroker which stocks to include in the analysis. Once you have the explotation filter set up you insert the AddColumn code in order to arrange the results of the exploration into neat columns. There are text columns and number columns you can use which can be set to different decimal places.
Basically, it lets you create your own customised screens and reports. For more info see How to screen for stocks with Norgate. Another useful thing you can do is to run an exploration on the data and then export that out into excel. For example, if you run an exploration code like below you can produce a report that contains all of your OHLC and volume quotes.
After running the exploration across all bars Amibroker will provide you with the quotes for those stocks. This will let you save the quotes as a CSV file. You can then load it up in Excel. In other words, you can successfully export data from Amibroker into CSV format for analysis elsewhere.
Hopefully you can see how powerful explorations can be. I use exploration regularly to run detailed stock screens and it can be customised with different colors. This screen encompasses technical and fundamental metrics:. The way it works is you write your code in the Formula Editor. You set your symbols in Apply to Watchlist. You set the date range and then you check your Backtester Settings by clicking the spanner icon.
Then you just click Backtest and Amibroker runs through the data, bar by bar, processing your rules. It then reports the results in a couple of different formats. One thing you should do is put as much of your trading rules into the AFL code as possible. If you look at the backtester settings more closely, almost everything in there here can be written directly into your code, mostly with the SetOption functions.
This is shown in the example below:. Once you have taken care of the intitial backtester settings you can move on to your backtest rules. These are your rules which tells Amibroker when to buy and sell. For example, the following code tells Amibroker to enter a buy order when the day moving average crosses over the day moving average. It enters a sell order when the MA crosses back under. The number 2 signifies that the trade exit will be placed on the next bar. If we were to use 1, then the trade exit would occur at the trade price intraday.
There are different ways to set up the ApplyStop settings as shown in this article. When using end-of-day data you generally want to specify either the open price or the close price. If trading intraday then you can set up a limit price of your choice:. When you write your entry rules in Amibroker you may end up with more than one candidate and so you need a way to choose between them. For this, Amibroker includes a variable PositionScore which allows you to rank all the stocks that meet your rules.
PositionScore tells Amibroker to choose the highest scoring symbols first. It will then choose the higest scoring candidates. Alternatively, you can ask Amibroker to choose the lowest scores first by substracting from or inverting the formula. For example, the following formula will now pick the lowest RSI 14 scores first:. Putting all the above code together gives us a very simple Amibroker trading system. Now the formula has been loaded into the Analysis Window you can set the dates you want to test and the symbols by clicking on the green funnel icon.
Then hit Backtest and the backtest will run. A useful feature of Amibroker is being able to clearly see every trade taken by the backtester in the Result List. This tab is found at the bottom of the screen while in the Analysis Tab. This is the first thing you should look at to make sure that the backtest is actually doing what you expect it to do.
Once you are in the Result List tab you can right click on any trade and click show current trade arrows. That action will place trade arrows into the price chart window. You can then go back to the chart and see if the trades are taking place at the right times. Once you are satisfied that the system is doing as you expect it you can move on to the detailed backtest report. This report shows you numerous statistics as well as equity curves, drawdown charts, profit tables and monte carlo runs:.
An optimization lets you backtest many different settings at once. For example, instead of running one backtest using a day moving average, you could run 10 backtests at once analysing every moving average length from days to days. By testing a broad range of variables you will typically find a sweet spot where your system works best.
You can then drill further down into this sweet spot to find the best performing parameters. Robust parameters are those that are based on a large sample of trades and which are surrounded by similar strong performing parameters. For example, the following graphic shows a basic optimization report for a moving average crossover test.
The graphic shows that there are many different combinations of moving average that produce resonable results. However, there is a definite sweet spot of performance which I have circled in white. Values in this range are more likely to be robust since the performance is more consistent within this range of values.
To run an optimization in Amibroker we can create a new identifier in our AFL code and then instruct Amibroker to optimize the parameters. Using the formula below as an example, the optimization starts at a day moving average, it then tests every moving average length up to in steps of The figure is the default moving average that will be applied if an optimization is not run.
For example, if you run a backtest and no optimization:. In other words, this code enables us to test every moving average length from 50 to in steps of The more variables and steps involved in the optimization, the longer the optimization will take. The code below optimizes three different variables, fast moving average, slow moving average and stop loss. Amibroker will test every combination of the three settings above.
The speed of the optimization will depend on the power of your computer and the number of stocks being tested on. These techniques speed up the optimization procedure by focussing on the steps of the optimization that are most likely to be useful. For example, once the algorithm finds a setting that is optimal it may skip all nearby steps greatly speeding up the process. Optimization is a fast and powerful tool.
As mentioned, its important not to over-optimize but to use optimization to find robust patterns and market truths. Walk forward analysis is another powerful feature for trading system developers. Other platforms seem to find this technique difficult but in Amibroker it is a breeze. The idea of a walk forward optimisation is to optimise your system on some in-sample data, then test it on out-of-sample data, using the best parameters that were found in-sample.
You then move forward and do it again, until you have reached the end of the data. Next, you concatenate stitch together all of the out-of-sample segments to get a performance summary that consists only of the out-of-sample parts. This is a great way to produce less biased backtest results since you are building a system based only on the out-of-sample results. Using a walk forward method is similar to how you might approach real trading.
You have an idea of what works and then you go and trade it in the live market. Using a walk forward analysis you can get an idea of what would happen if you did that. First by optimizing the search and then by validating it repeatedly on different segments of out-of-sample data. To run a walk forward analysis you first set up an optimization, just like we did earlier. You then need to adjust some items in the backtest settings on the Walk Forward tab. You will need to set your in-sample and out-of-sample dates and select the optimization target.
The optimization target tells Amibroker which metric to benchmark performance by. For example, do you want to select the strategy that makes the most profit or the smallest drawdown? For a walk-forward analysis to be effective you need to use enough data in the in-sample period to give you a large enough sample of trades.
You can then use an out of sample that is maybe a third the size of the in sample. For example, I might use an in-sample period that lasts five years and generates 1, trades then use a walk-forward sample of two years. Essentially you are optimising the system over 5 years of data, then you take the best variation of the system and backtest it on the next two years of unseen data.
Professional Real-Time and Analytical platform with advanced backtesting and optimization. Up to 32 simultaneous threads per Analysis window. Includes both bit and bit versions. Everything that AmiBroker Professional Edition has plus two very useful programs: AmiQuote - quote downloader from multiple on-lines sources featuring free EOD and intraday data and free fundamental data.
Invaluable learning tool for novices. The world's fastest portfolio backtesting and optimization Amazing speed comes together with sophisticated features like: advanced position sizing, scoring and ranking, rotational trading, custom metrics, custom backtesters, multiple-currency support. Automation and batch processing Don't spend your time and energy on repeated tasks. Charts and drawing tools AmiBroker features all standard chart styles and drawing tools.
They all can be customized, combined and overlaid anyway you want. A water level can be adjusted to precisely determine peak and valleys above and under certain level. Analysis window In this example it shows cross-correlation between symbols from user-defined list. This is just one of many things that you can do using Exploration. The Analysis window is home to backtesting, optimization, walk-forward testing and Monte Carlo simulation.
Symbols window AmiBroker allows you to categorize symbols into different markets, groups, sectors, industries, watch lists. Ultra-quick full-text search makes finding symbols a breeze. Interpretation window The interpretation is automatically generated market commentary based on user-definable formulas. You can use pre-written interpretations or create your own.
Gradient chart and market profile Any chart, not only price, can be displayed as gradient chart for attractive look. On the left side you can see volume-at-price chart orange which allows to quickly recognize price levels with highest traded volume. Fundamental data can also be used in your formulas. Flexible user interface can be arranged and customized in any way you like. Multiple monitor setups are fully supported. Windows can be docked or floated.
Find optimum parameter values Tell AmiBroker to try thousands of different parameter combinations to find best-performing ones. Walk-forward testing Don't fall into over-fitting trap. Monte Carlo Simulation Prepare yourself for difficult market conditions.
Concise language means less work Your trading systems and indicators written in AFL will take less typing and less space than in other languages because many typical tasks in AFL are just single-liners. Built-in debugger The debugger allows you to single-step thru your code and watch the variables in run-time to better understand what your formula is doing State-of-the-art code editor Enjoy advanced editor with syntax highlighting, auto-complete, parameter call tips, code folding, auto-indenting and in-line error reporting.
Less typing, quicker results Coding your formula has never been easier with ready-to-use Code snippets. All our licenses are perpetual which means you can buy once and use the version that you purchased forever.