Australian (ASX) Stock Market Forum

Amibroker FAQ

Hi everyone,

I'm trying to write a code that uses less equity to trade when in drawdown...
so if I'm 10% down the system will only use 80% of the equity (from the previous peak).

Is drawdown a built-in function? I haven't been able to find it...

any suggestions?
 
hi, im new to AB and im having some real trouble trying to code for the following.

I want to identify / be able to scan for when a stock gaps down (or up), on open and close back into the previous days range?

as per the following chart

can anyone at least point me in the right direction?

any help would be awesome
The Downside Tasuki Gap seems to be what you were chasing. A fairly rare event on the day from what I have found. Code and example ....

Code:
//Downside Tasuki Gap

MS = Ref(Close,-2)<Ref(Open,-2) AND Ref(Open,-1) < Ref(Close,-2) AND Ref(C,-1) < Ref(O,-1)
     AND Open > Ref(C,-1) AND Open < Ref(O,-1) AND Close > O AND C > Ref(O,-1) AND C < Ref(C,-2);

Filter = MS>0.5;
AddColumn(MS, "Downside Tasuki Gap");
AddColumn(C, "close");
AddColumn(V, "Volume");
 

Attachments

  • untitled.jpg
    untitled.jpg
    57.1 KB · Views: 5
Hi,

This is driving me mad :banghead:, can someone please explain why this isn't working!?
To explain I have a very simple system:
MAs = MA(C,20);
MAl = MA(C,50);
Buy = Cross(MAs,MAl);
Sell = Cross(MAl,MAs);

What I want to do is to stop issuing buy signals based on something else, ie, another filter, maybe when the market is a bear market.

So, my system would now look like this:

flagval = 0;

MAs = MA(C,20);
MAl = MA(C,50);

Buy = Cross(MAs,MAl) AND flagval = 1;
Sell = Cross(MAl,MAs);

Where the first variable 'flagval' changes from 0 to 1.
However, if I run the above code I still get the same number of buy signals.
Surely the above code should not give me any buy signals as flagval is always zero and my buy criteria is looking for flagval = 1.

What am I missing here?

Thanks

The problem here is the operator that is being used. The equals sign alone "=" means that you are assigning a value of "1" to the variable "flagval" when you are buying, so you aren't filtering. You want to use "==" which checks if flagval does equal 1 instead of assigning a value of 1.
 
hi, im new to AB and im having some real trouble trying to code for the following.

I want to identify / be able to scan for when a stock gaps down (or up), on open and close back into the previous days range?

as per the following chart

can anyone at least point me in the right direction?

any help would be awesome

Code:
//This code will search for bars which gap and then close inside the previous 
//bar. No copyright blah blah. Created by saiter, 2010.

_SECTION_BEGIN("Gaps");
//Switches
sUp = ParamToggle("Show Gap ups?", "NO|YES", 1);
sDown = ParamToggle("Show Gap downs?", "NO|YES", 1);
f0 = ParamList("Search for:", "Gap down|Gap up", 0);

//Create the arrays
gd=Null;
gu=Null;

//Search for the bars

for(i=1;i<BarCount;i++)
{
	if(O[i]<L[i-1] AND C[i]>L[i-1] AND C[i]<H[i-1])
		gd[i]=1;
	else gd[i]=0;
	if(O[i]>H[i-1] AND C[i]<H[i-1] AND C[i]>L[i-1])
		gu[i]=1;
	else gu[i]=0;
}

//Plot stuff
Plot(C,"Close", colorBlack, styleBar);
if(sDown)
	PlotShapes(IIf(gd, shapeSmallCircle, shapeNone), colorRed, 0, L, -15);
if(sUp)
	PlotShapes(IIf(gu, shapeSmallCircle, shapeNone), colorGreen, 0, H, 15);

//Filters
NumColumns=1;
if(f0=="Gap down")
	Filter=gd;
if(f0=="Gap up")
	Filter=gu;
_SECTION_END();

This will do what you want. You should be testing this to see if this is what you want. Amibroker will look for anything that "gaps" whilst you might want it to gap by 50% etc. Obviously, this code needs to be further refined to do what you want it to do. Examples below:

example1.png

example2.png
 

Attachments

  • example1.png
    example1.png
    16.6 KB · Views: 0
  • example2.png
    example2.png
    17 KB · Views: 0
I'm trying to create a number of separate buy conditions, each with their own buyprice. Example:

buy=(close>X AND buyprice=X)
OR (close>Y AND buyprice=Y)
OR (close>Z AND buyprice=Z);

How do I do this? Basic stuff I'm sure, but a seach hasn't found anything yet. The idea is that the buyprice forces the backtesting to fire at a specific price, rather than ohlc. It works fine when I use one instance of buyprice, but not when using multiple instances.

I'd be using loops and if statements for this:

Code:
for(i=0;i<BarCount;i++)				//Loop through all the bars
{
	if(Condition1)					//1st buy condition
	{
		Buy[i] = 1;					//Trigger a buy signal at THAT bar
		BuyPrice[i] = C[i];			//The buyprice
	}
	if(Condition2)					//Same as above, different conditions
	{
		Buy[i] = 1;
		BuyPrice[i] = O[i];
	}
}

Note that Condition1 and Condition2 are NOT variables, rather, they are statements e.g. C>C[i-1]
 
Hi everyone,

I'm trying to write a code that uses less equity to trade when in drawdown...
so if I'm 10% down the system will only use 80% of the equity (from the previous peak).

Is drawdown a built-in function? I haven't been able to find it...

any suggestions?

ummm - help anyone? :)
 
Hi everyone,

I'm trying to write a code that uses less equity to trade when in drawdown...
so if I'm 10% down the system will only use 80% of the equity (from the previous peak).

Is drawdown a built-in function? I haven't been able to find it...

any suggestions?

You would be able to do this using the Custom Backtest mode, there's an example of adjusting position size relative to equity in the document posted by Great Pig in the thread below.

https://www.aussiestockforums.com/forums/showthread.php?t=7260
 
Hi all

just thought i'd drop and ask something a little off the most recent topic

If I wanted to have the opportunity to trade say any one of the stocks that make up the SP1500, (so not only sp500, but also SP600 and SP400), are there any online brokers that can handle this?

I am with CMC Market Maker, and they only handle the basket of stocks that make up sp500.

Any help greatly appreciated
ST
 
Amibroker & Northgate/Premium ASX data

Hi,

Currently a subscriber and was wondering can Amibroker Standard Edition handle the intraday snap shops offered by Premium.

Would like to be able to see a little more detail of market action that occurred during the day other than EOD OHLC.

Cheers
 
Amibroker & Northgate/Premium ASX data
Currently a subscriber and was wondering can Amibroker Standard Edition handle the intraday snap shops offered by Premium.

Would like to be able to see a little more detail of market action that occurred during the day other than EOD OHLC.

Yes it handles it fine.

AmiBroker Standard Edition is limited to daily data. Our intraday snapshots are still daily data - that is, a snapshot of the daily OHLCV up to a particular point in the day.

For example, today BHP had the following OHLCV snapshots:

11:00 snapshot (available at 11:20):
42.95,43.04,42.65,42.74,5133514

12:00 snapshot (available at 12:20):
42.95,43.04,42.65,42.84,6601441

13:00 snapshot (available at 13:20):
42.95,43.06,42.65,43.06,7779578

14:00 snapshot (available at 14:20):
42.95,43.07,42.65,42.76,9009708

15:00 snapshot (available at 15:20):
42.95,43.07,42.65,42.78,10162213

Interim close snapshot (available at 16:30):
42.95,43.07,42.65,42.67,14347171

Final close snapshot (available at around 19:20):
42.95,43.07,42.65,42.67,14798484

When you click the Update button, you get the latest snapshot.

If you would like a trial of the intraday snaphots please email us and we'll enable it for you.

Note: Many users utilise the intraday snapshots, especially the 1500 snapshot, in order to make an entry on or near the closing price auction rather than waiting for the next day.
 
Thanks for the reply Richard much appreciated.

Just in the process of renewing subscription with Premium Data, have been more than happy with the data and service.

Do the snap shots show up as individual bars in the Amibroker charts as I only see options for periods of day, week and month.

Would you be able to show a small section of any chart as an example with time line.

Cheers
 
The snapshots are just daily data. Overwritten each time there is a new snapshot. There is no way to retrieve a prior snapshot after you have updated.

So the data looks the same as you have it now, just that you are able to click the update button several times a day.
 
The snapshots are just daily data. Overwritten each time there is a new snapshot. There is no way to retrieve a prior snapshot after you have updated.

So the data looks the same as you have it now, just that you are able to click the update button several times a day.

Here's what BHP looked like at the 13:00 today snapshot today:
bhp-20100122-1300.png

And here's what it looks like at the 19:00 final snapshot today:
bhp-20100122-1900.png
 

Attachments

  • bhp-20100122-1300.png
    bhp-20100122-1300.png
    29.1 KB · Views: 0
  • bhp-20100122-1900.png
    bhp-20100122-1900.png
    29.4 KB · Views: 0
Monte Carlo Analysis

Hi all

Does anyone know how to use the monte carlo analysis in AB?

Ie. when i "backtest" a system on all of the trades that would have occurred in all / any of the stocks that make up the say russell 3000 over the past 10 years, does that backtest result only give ONE course of action, or is it giving me the results of say 10,000 courses of action (or histories, or whatever the correct term is)?

I am assuming it is only the ONE as I am not seeing any standard deviations or confidence levels in the results summary.

1. please advise on whether this function exists
2. where such a fucntion can be located on the program

Cheers
ST
 
Re: Monte Carlo Analysis

Hi all

Does anyone know how to use the monte carlo analysis in AB?

Ie. when i "backtest" a system on all of the trades that would have occurred in all / any of the stocks that make up the say russell 3000 over the past 10 years, does that backtest result only give ONE course of action, or is it giving me the results of say 10,000 courses of action (or histories, or whatever the correct term is)?

I am assuming it is only the ONE as I am not seeing any standard deviations or confidence levels in the results summary.

1. please advise on whether this function exists
2. where such a fucntion can be located on the program

Cheers
ST

Hi ST --

There are many uses of Monte Carlo in the fields of econometrics and financial analysis and modeling. But the three described below are the most applicable to trading systems development. Some are easy to implement in AmiBroker, others are more difficult. Some are useful, others are not useful or poor practice.

1. Use Monte Carlo techniques to study the robustness of a trading system to small changes in the data. Small, random amounts of noise can be added to the open, high, low, close, and volume to see if the trading system is sensitive to noise in the data. This is easily done and useful. There is a more detailed explanation, including code, in my book, Quantitative Trading Systems.

2. Use Monte Carlo techniques to study the robustness of a trading system to small changes in values of parameters. When an optimization is performed, the value of an objective function is calculated for every set of parameter values tested. The best set of parameters is the set that give the highest value of the objective function. If we consider a two dimensional optimization, say the lengths of two moving averages, then we can imagine and visualize the objective function as a surface above (or below) the plane defined by the two variables. If the highest value of the objective function is an isolated peak, then the system is sensitive to changes in the relationship between the model and the data being modeled, and even small changes in the characteristics of the data will cause a shift in the position of the optimal solution. That is, the system is not robust relative to changes in the values of the parameters. If, on the other hand, the highest value of the objective function is a broad plateau, then the system is relatively insensitive to changes in the relationship between the model and the data and small changes in the characteristics of the data will not result in significant changes in the profitability of the system. That is, the system is robust relative to changes in the values of the parameters.

Monte Carlo techniques can be used to study the sensitivity of the system by adding random noise to the values of the parameters, testing solutions near the optimal solution. There are many subtle issues that arise when performing this type of study, making general solutions very difficult. Specific solutions are easy to code by running a second set of optimizations that look at the solution space near the previously selected optimum. Additionally, some of the optimization methods included with current releases of AmiBroker (such as the non-exhaustive method known as cmae -- Covariance Matrix Adaptation Evolutionary Strategy) have a robustness component that is used with no need for additional coding by the trading system developer.

3. Monte Carlo techniques can be used to study the risk profile of a sequence of trades.

Your question prompts me to ask how the tests you are running are defined. If the universe of stocks being tested is comprised of the 3000 stocks that are the current members of the Russell 3000 index, and the test period is the past ten years, then there is a considerable survivorship bias in the test runs. That is, the 3000 companies that are in the index now have survived the past ten years, but those companies that disappeared during that period are not included in the tests. That bias strongly affects the test results. In some of my research, I have compared two studies:
1. Use the list of stocks currently in an index.
2. Use the lists of stocks that were in an index at the start of each year and run tests one year at a time, with lists reconstructed at the beginning of each year.
The results of the first study are always significantly better than the results of the second study. Ignoring the survivorship bias will cause the trading system developer to significantly over-estimate the likelihood that the system will be profitable in the future.

Norgate Premium Data (http://www.premiumdata.net/) is an excellent source of end-of-day data for the US and Australian markets, including data for issues that have been delisted. They are in the process of developing historical lists of components of major indexes which will be very valuable for study of the effects of survivorship. Richard Dale of Norgate is a regular poster to ASF and might comment of their plans.

Your question also raises a related issue about how trades are selected. Some developers run a general test using a large universe of possible issues to trade, which results in a number of potential positions to enter that is greater than the funds available to take those positions. They then consider using Monte Carlo techniques to analyze what might happen if different combinations of issues are purchased. This is an inappropriate use of Monte Carlo analysis and is poor trading system development practice. I do not know of a single trader or trading company who runs a test or report, generates a list of signals, sees that it has more signals than he or she has money, and rolls dice to determine which of the signals to actually take. The trader will always have a secondary set of conditions that are used to rank-order the list of signals so that the best candidates can be purchased. If the secondary set of conditions comes from non technical analysis data, rankings from Investor's Business Daily for example, then it will be difficult to incorporate the ranking in any trading system development platform, including AmiBroker. If, however, the secondary set of conditions comes from technical analysis, recent relative strength of price for example, then it is easy to calculate a ranking score and use it so that the signals generated do not exceed the funds available and there is no need for application of a Monte Carlo technique. In AmiBroker, this secondary set of conditions is stored in the reserved variable PositionScore. It is, in effect, a tie-breaking component of the objective function.

Returning to the question of reordering trades to study the risk associated with the trading system. Use of Monte Carlo analysis in this area is very valuable. It is best done using a program that accepts a list of closed trades and performs the risk analysis. Equity Monaco, available free (http://www.tickquest.com/product/equitymonaco.html), is a good one to start with. And Market Systems Analyzer (http://adaptrade.com/) has more capability and a trial version.

I hope this has been helpful.

Thanks for listening,
Howard
 
Re: Amibroker

I am new here, but I see all the recommendations for AMIBROKER, and I am considering getting a copy to help incease my trading abilities.
What is the best (free if possible ) way of downloading data for the Australian market. I am already with Commsec but what about yahoo finance. Any suggestions.
 
Hi,

If your serous about your trading, then you will need to be serous about your data regardless of the charting package. As it is the data that allows you to make informed decisions. If the data is incorrect or incomplete then your decision making process will be effected.

I can recommend Premium Data. Link is in Howards post above.

Cheers
 
Re: Amibroker

I am new here, but I see all the recommendations for AMIBROKER, and I am considering getting a copy to help incease my trading abilities.
What is the best (free if possible ) way of downloading data for the Australian market. I am already with Commsec but what about yahoo finance. Any suggestions.
A free trial is available and I suggest you try that first to see if the software meets your needs. As noted many times before, correctly adjusted historical data is best to use but I get by using Yahoo with the knowledge that the data is not entirely accurate. Within the software is a configurable auto-downloader.

I use the Amibroker software to backtest formula for possible real life profitability.

p.s. buying the book and joining the forum will help with understanding AFL code.
 
Top