Australian (ASX) Stock Market Forum

Amibroker FAQ

Just want to know if I'm doing the following correctly:

(1) I want Cond1 to find a stock that has closed 10% above the lowest low in the past 20 days:

Code:
Cond1 = C > (LLV(Low,20)*1.1)

(2) I want Cond2 to find a stock where its 20 day MA is 10% above its 100 day MA:

Code:
MA1 = MA (C, 20)
MA2 = MA (C, 100)
Cond2 = MA1 > (MA2*1.1)

Also after a backtest, when I look at the Reports --> Trades section, the position sizes are fluctuating wildly. I am using the following for position size and max. open positions:

Code:
SetPositionSize( 5, spsPercentOfEquity );
SetOption( "MaxOpenPositions", 20 );
I understand that there should be some fluctuation as my open equity fluctuates, but the variations in trade size are far larger than they should be.
 
Just want to know if I'm doing the following correctly:

(1) I want Cond1 to find a stock that has closed 10% above the lowest low in the past 20 days:

Code:
Cond1 = C > (LLV(Low,20)*1.1)

(2) I want Cond2 to find a stock where its 20 day MA is 10% above its 100 day MA:

Code:
MA1 = MA (C, 20)
MA2 = MA (C, 100)
Cond2 = MA1 > (MA2*1.1)

Also after a backtest, when I look at the Reports --> Trades section, the position sizes are fluctuating wildly. I am using the following for position size and max. open positions:

Code:
SetPositionSize( 5, spsPercentOfEquity );
SetOption( "MaxOpenPositions", 20 );
I understand that there should be some fluctuation as my open equity fluctuates, but the variations in trade size are far larger than they should be.

1) try this instead: a = Ref(LLV(L,20),-1);
Cond1 = c>=(1.1*a);

3) check settings>portfolio>limit trade size...
A fixed position size will be more useful for most systems. Positionsize = 20,000;
 
I understand that there should be some fluctuation as my open equity fluctuates, but the variations in trade size are far larger than they should be.
Also in Backtester Settings the minimum position value can be set so there is no small position trades below the setting.
 

Attachments

  • untitled.jpg
    untitled.jpg
    52.2 KB · Views: 119
Just want to know if I'm doing the following correctly:

(1) I want Cond1 to find a stock that has closed 10% above the lowest low in the past 20 days:

Code:
Cond1 = C > (LLV(Low,20)*1.1)

Have you considered the Cross function to achieve this as well? It may reduce the number of signals you get - this may or may not be what you want to do
 
1) try this instead: a = Ref(LLV(L,20),-1);
Cond1 = c>=(1.1*a);

Thanks, I'll give it a go.

3) check settings>portfolio>limit trade size...
A fixed position size will be more useful for most systems. Positionsize = 20,000;

I tried this and it worked. However, if my account starts at $50K and each position size is $2500... I don't want my position size to still be $2500 if my equity grows to $100K. (think compounding)

I want the trade size to be a fixed % of open equity. If my equity increases, I want my position size to increase (and visa versa if it decreases).

Also in Backtester Settings the minimum position value can be set so there is no small position trades below the setting.

I did this and set it to the initial size I want each position to be (so that I don't have any tiny positions), but this doesn't eliminate the really oversized trades that are happening. Just a few trades in I get a position size that is almost half of my entire equity. ???

Have you considered the Cross function to achieve this as well? It may reduce the number of signals you get - this may or may not be what you want to do

Nope, I hadn't thought of that. I'll give it a go.

Thanks all :)
 
In the analysis window, I am doing an exploration but a couple of stocks with dates outside the parameters are coming up.

My dates are 24/10/2011 to 26/10/2011.
There are 45 results in total. 42 of them correct.
The other 3 have dates 9/8/2011, 11/8/2011 and 18/10/2011.

This has just started happening. Even when using older dates there is always 2 or 3 that don't fit the parameters. This only started happening yesterday. I don't understand it.
 
Hi

Im trying to write some buy and sell code for this formula. As it is at the moment it works but the buy or sell is based on the middle of the candle passing the respective trail. If I changed the formula to say

Buy = NW < Close;
Sell = NW > Close;

Then it buys and sells on either trail (NW is the same name)

Question: Is it possible to change this formula so that the bulltrail has one name and the beartrail has another so that I could have something like

Buy = Close> Beartrail;
Sell = Close< Bulltrail;

I just want it to buy when the close goes above the top trail and sell when it goes below the bottom trail. (The close not the middle of the candle)

Does that make sense?




_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );


SetChartBkGradientFill( ( ColorRGB(208,230,217)),( ColorRGB(240,225,173)));




_SECTION_END();

_SECTION_BEGIN("Trail long");
function trail_func(jj,trBull,trBear)
{
trailArray[ 0 ] = jj[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (jj[ i ] > prev AND jj[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,jj[ i ] - trBull[ i ]);
}
else if (jj[ i ] < prev AND jj[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,jj[ i ] + trBear[ i ]);
}
else if (jj[ i ] > prev)
{
trailArray[ i ] = jj[ i ] - trBull[ i ];
}
else
{
trailArray[ i ] = jj[ i ] + trBear[ i ];
}
}
return trailArray;
}

// code by E.M.Pottasch
// adjusted from M.Kartnik
// following: http://wisestocktrader.com/indicators/1710-nma-v-3-6-a-optimiser

k_bull = Param("mult bull",3.9,1,4,0.05);
k_bear = Param("mult bear",3.8,1,4,0.05);
k_bull = Optimize("mult bull",3.9,1,4,0.05);
k_bear = Optimize("mult bear",3.8,1,4,0.05);


Per= Param("period",10,5,50,1);

HaClose=(O+H+L+C)/4;
HaOpen = AMA(Ref(HaClose,-1),0.5);
HaHigh = Max(H,Max( HaClose,HaOpen));
HaLow = Min(L,Min(HaClose,HaOpen));

ms=ParamList("ST0P/REV",List="Reg|Smoothed",0);
if(ms=="Reg")
{
nm =(H-L);
j=(O+H+L+C)/4;
}
else
{
nm=(HaHigh-HaLow);
j=(HaOpen+HaHigh+HaLow+HaClose)/4;
}

rfsctor = WMA(nm,PER);
revers_bull=k_bull*rfsctor;
revers_bear=k_bear*rfsctor;

nw = trail_func(j,revers_bull,revers_bear);

GraphXSpace = 5;


Plot(IIf(NW > j,NW,Null),"\ntrailShort",ParamColor("ColorTrailShort",ColorRGB(255,0,0)),styleStaircase);
Plot(IIf(NW < j,NW,Null),"\ntrailLong",ParamColor("ColorTrailLong",ColorRGB(0,255,0)),styleStaircase);


Buy = NW < j;
Sell = NW > j;


Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);









PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);







_SECTION_END();
 
How/where do you get data for these applications ? How often/how do you get the updates ect.. ?

Just looking for something to get me started to monitor stocks..
 
How/where do you get data for these applications ? How often/how do you get the updates ect.. ?

Just looking for something to get me started to monitor stocks..

What do you mean by "applications"? Do you mean Amibroker?
Well you won't get intra-day data for free (easily) so you would need to choose a paid service of data vendors like esignal or iqfeed or ... . Or you can get data from Interactive Brokers (all mentioned ones are supported by Amibroker). IB data feed is for free if you generate $30 in trading commissions each month else it's $10/month.

If you want EOD (end of day) data only then you can choose yahoo or google or msn service. All three are supported by Amibroker as well.
 
Well you won't get intra-day data for free (easily) so you would need to choose a paid service of data vendors like esignal or iqfeed or ... .
I think IQFeed only has SFE data and not ASX data for Aussie players.
 
What do you mean by "applications"? Do you mean Amibroker?
Well you won't get intra-day data for free (easily) so you would need to choose a paid service of data vendors like esignal or iqfeed or ... . Or you can get data from Interactive Brokers (all mentioned ones are supported by Amibroker). IB data feed is for free if you generate $30 in trading commissions each month else it's $10/month.

If you want EOD (end of day) data only then you can choose yahoo or google or msn service. All three are supported by Amibroker as well.

Greetings --

Do not rely on intra-day data provided by a brokerage platform to build a database that will be used for testing. Brokers send as much data as the capabilities of the computers and data transmission facilities allow. In periods of heavy activity, quotes will be intentionally omitted. Brokerages seldom (never?) correct bad ticks. They provide data as a side activity to their brokerage business.

Instead, get the intra-day from a data vendor -- their business is supplying high quality data.

Thanks,
Howard
 
Greetings --

Do not rely on intra-day data provided by a brokerage platform to build a database that will be used for testing. Brokers send as much data as the capabilities of the computers and data transmission facilities allow. In periods of heavy activity, quotes will be intentionally omitted. Brokerages seldom (never?) correct bad ticks. They provide data as a side activity to their brokerage business.

Instead, get the intra-day from a data vendor -- their business is supplying high quality data.

Thanks,
Howard

Hello Howard, yes I know that IAB data feed isn't the best, for example.
 
New question:

If I use positionsize = -5;

and have a very large starting equity, say 10 million, presumably a backtest will pick up all signals so I can get a good idea of overall performance when no trades are left out.

But then I add Positionscore = random(); and the whole thing goes very weird. Repeat backtests yield very different equity curves.

Any ideas what's going on? I've never really understood how AB chooses which stocks to trade. The description in the manual is very hard to follow.

Does positionscore = random() override any/all entry criteria?
 
Hi all,
I'm trying to test an index function using an EMA cross as a trigger but it doesnt appear to be plotting correctly.
if you look at the below, you can see that the black line is the on/off trigger, but it's almost random as to when it triggers.
It's very simple, the afl is below but it just doesnt work.
I tried it with another stock and it triggers exactly right, just not with XAO/^AORD.
Capture.JPG


Any ideas appreciated.

aIndex = foreign("^AORD", "C");
Plot(aIndex, "XAO", colorBlue, styleLine | styleOwnScale);

aIndexEmaLong = EMA(aIndex, 21);
aIndexEmaShort = EMA(aIndex, 9);

Plot(aIndexEmaLong, "XAO EMA 21", colorRed, styleLine | styleOwnScale);
Plot(aIndexEmaShort, "XAO EMA 9", colorGreen, styleLine | styleOwnScale);
aIndexDown = aIndexEmaLong >= aIndexEmaShort;
Plot(aIndexDown, "Index down", colorBlack, styleLine | styleOwnScale);
 
New question:

If I use positionsize = -5;

and have a very large starting equity, say 10 million, presumably a backtest will pick up all signals so I can get a good idea of overall performance when no trades are left out.

But then I add Positionscore = random(); and the whole thing goes very weird. Repeat backtests yield very different equity curves.

Any ideas what's going on? I've never really understood how AB chooses which stocks to trade. The description in the manual is very hard to follow.

Does positionscore = random() override any/all entry criteria?

When you have multiple buy signals, but not enough cash, amibroker has to make a choice as to which ticker to buy. By default it will go by alphabetical order (giving "A" preference").

Positionscore Random randomises it so it becomes more realistic. If your equity cruve varies too much when you randomise the trades, then your system probably isn't robust enough.
 
What do you mean by "applications"? Do you mean Amibroker?
Well you won't get intra-day data for free (easily) so you would need to choose a paid service of data vendors like esignal or iqfeed or ... . Or you can get data from Interactive Brokers (all mentioned ones are supported by Amibroker). IB data feed is for free if you generate $30 in trading commissions each month else it's $10/month.

If you want EOD (end of day) data only then you can choose yahoo or google or msn service. All three are supported by Amibroker as well.

Whatever really. Just want to start familiarising myself with these kinds of products without spending a small fortune. Gotta start somwhere.

Also I have some programming experience. Thanks I'll try out of some of those sources you metioned.
 
Right click on chart, click on Parameters, click on EMA Price Field and then click on ^AORD.

Hi Wysiwig,
Thanks for the reply, I cannot do that as it's not the primary stock, just an overlay, hence has to be (from my understanding) referenced using the Foreign function.
When I do right click, the options are O/H/L/C/Average/Volume/OpenInt, no option to select ^AORD.

Cheers,
JB
 
Top