Trading strategies for amibroker




Customer reviews
cokia
In my opinion you are mistaken. Suggest it to discuss.
Mashka-milashka
I think you are making a mistake. Write to me in PM, discuss.
Jula
I'm sorry I broke ... I know this situation. I invite to discussion.
mra4ek
Bomb watch all!
DrugOnFly
Author you 3 Trouble
Ra-ca-ca
Totally agree with you. This is something there, and I think it's a great idea.
kyenilmez
Just what you need to share it. Together we can come to a right answer.
Fr0s7
Sorry for that I interfere ... I here recently. But I am very close to this topic. Write to the PM.
Fairy-Julia
I know everything about world most popular medications for impotence treatment!

Trading strategies for amibrokerWriting AFL for Amibroker

Share this post:

2C208" /% The best resources for Amibroker AFL can be found via the Amibroker AFL library or one of the Amibroker yahoo forums. Here there are usually plenty of generous traders who are happy to share some of their code and give assistance if needed.

I also provide code for 20 trading systems written in AFL with every purchase of my book or course and will be posting plenty of free AFL code here in the future so make sure to come back regularly.

New to Amibroker?

Luckily writing AFL for Amibroker is fairly straightforward even for someone with no background in programming. If you are new to Amibroker I will recommend a piece of advice that I first received when on the Amibroker forum:

Start off with end of the day data for US stocks and look for simple, robust systems.

Everything you need from a good trading system can be found with EOD data and from here it should be possible to reach returns of 30% CAR a year with a little bit of work. From there you can start to work on even greater returns but remember higher returns will inherently mean higher risk.

By end of day data I mean data that shows the high, low, open, and close from the trading day. Its far better to concentrate on daily or weekly systems and ignore day trading if you are new to the markets.

And remember, no trading system can be created without good quality data. I recommend Norgate Premium Data and you can get a free trial of the service here .

Writing AFL for Amibroker

When you start writing Amibroker AFL its a good idea to begin with a kind of template that you can then use as the basis of several trading systems. I usually start off with something like this, (the set options can also be set in the Amibroker panel but its better to write them into the code):

SetOption( InitialEquity, 10000);

This one sets how much capital you have to trade e. g. $10,000

SetOption( UsePrevBarEquityForPosSizing, True );

Allows position size to be calculated using % of previous bars funds. Can be turned on or off

SetTradeDelays( 1, 1, 1, 1 );

Its usually not possible to trade on the exact moment that a signal occurs. So you can delay the buy, sell, short and cover entries by 1 (or more) bars.

SetOption( MaxOpenpositions, 10);

Sets the Maximum open positions you want at any one time. Ive set mine at 10 as I trade a portfolio of 10 stocks.

SetOption(SeparateLongShortRank, True );

Amibroker enters trades based on the signal rank also known as positionscore. If you hold short and long positions this variable allows them to be ranked separately so you dont end up favoring one direction over the other.

SetOption (Maxopenlong, MOL);

SetOption (Maxopenshort, MOS);

This code allows a maximum of 10 long positions and 5 short positions at any one time.

SetOption( AllowSameBarExit, True );

Allows trades to be closed on the same bar that the exit signal or stop signal occurs

Numberpositions = 10;

SetOption(Maxopenpositions, numberpositions);

SetPositionSize( 1, spsShares );

PositionSize= -20/10;

This is the segment of code I use to set my positionsize or risk. -20 / 10 means my position size per trade is 20% of my account divided by 10.

In other words, if I start with $10,000, my first trade will have a stock value of $200. To get the number of shares, you simply divide this number by the stock price. Eg, for a stock that is $12, I will buy 16 shares.

Ranking trades

Once thats in place its a good idea to define positionscore metrics and enter the formulas for any indicators you plan to use. Remember, positionscore determines the rank. If you have more than one trade signal, Amibroker will take the trade that is scored the highest. This is quite important, particularly if your system generates lots of signals on the same day/ bar. You can use any calculation you like. Here are some ideas:

PositionScore = RSI(14) 100; Prefers long positions with lower RSI values and short positions with high RSI

PositionScore = ATR(10) 100; Prefers long positions with smaller ATR (average true range) values

PositionScore = ROC(C,1) * -1; Prefers long positions with lower ROC (rate of change) values

Then you can enter your buy and sell conditions. When you write AFL for Amibroker its a good idea to keep everything organised so that you dont make any mistakes and you can easily understand it in the future. Heres a very simple moving average crossover example:

fastema = EMA(C,50);

slowema = MA(C,200);

Buy = Cross(fastEMA, slowEMA); Buys when the 50 period EMA crosses over the 200 period EMA.

Sell = Cross(slowEMA, fastEMA); Sells when the 200 period EMA crosses under the 50 period EMA.

Once you have tried this, you can set about optimising some of your parameters like below:

fastema = Optimise(fastEMA,50,25,200,25);

slowema = Optimise(slowEMA,200,180,300,20);

When run, the optimiser will cycle through these values and present them in a table showing which ones performed the best. The numbers in brackets stand for (default setting, first iteration, final iteration, step). In other words the optimizer will first test the fastema with using the 25 setting, it will then keep testing at intervals of 25 until it gets to 200 where it stops. If you run the backtest without the optimiser, Amibroker uses the default (50) setting.

After your buy and sell conditions you can enter code that plots your various indicators on the chart and any calculations that you may have with the equity curve.

Its also a good idea to check out the resources from Amibroker for back-testing and portfolio testing here.

Enjoy this post? You'll love my free eBook, system code, & free course. Just enter your email address below to download all. Unsubscribe at any time.

Backtesting Engine Definition

November 6th, 2008 by jackieannpatterson | 1 Comment | Filed in Glossary

TradeStation Backtesting Engine At Work

The Backtesting Engine is the core software doing the backtest.

The backtesting engine applies the trading strategies to the historical price data to get a series of hypothetical trades and records the results.

The outputs of the backtesting engine are typically performance statistics. I have added instrumentation to gather additional information about each trade for later analysis.

Many backtesting engines are available commerically. Well-known platforms include TradeStation. Worden Blocks BackScanner. WeathLab. Amibroker . Many brokers such as TD Ameritrade offer backtesting engines for their customers.

In spite of the wide availability of software, many traders dont backtest because of the huge amount of work it takes. Reading a Backtesting Report is much easier.

In order to describe a trading system with no ambiguity or bias, you need to code your rules into a language a computer can decipher.

The choice of which software to use for coding and backtesting has to be tackled early on in the process. A good choice will not only vastly increase your productivity, it will also allow you to backtest the broadest possible spectrum of strategies in the broadest asset classes.

QiT chose Amibroker for a number of reasons: ease of use, APIs with numerous data providers, and as Howard Bandy, author of Introduction to Amibroker, writes, Amibroker is a powerful, comprehensive trading system development platform with cutting edge charting and graphics. It has a fast, flexible and powerful portfolio-level backtesting, optimization, and automated walk forward validation. If that is all gobblegook to you, suffice to say it has everything a retail system developer – or quant trader – will need.

Amibroker’s main purpose is to help investors and traders identify profitable opportunities to buy and sell or short and cover. It includes an extensive library of technical indicators that can be plotted along with the price chart as well as tested for profitability in a trading system. It has all the tools needed to chart, test, and trade stocks, exchange traded funds, mutual funds, commodities, and Forex.

Amibroker’s two primary modes of operation are charting and formula evaluation. In its charting mode, historical price and volume data are displayed, along with technical indicators, just like all other charting programs. In its formula evaluation mode the trader can evaluate his/her own trading ideas using patterns, conditions, and rules. These rules are programmed into a computer language and the program analyzes the price and volume data and reports on the profitability of the rules. When profitable trading systems have been found, it scans the group of stocks that are of interest to the trader and lists the current buy and sell signals.