Australian (ASX) Stock Market Forum

Amibroker FAQ

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.

Greetings --

BillyB is correct in his explanation of the way AmiBroker determines which trades to take and how it uses PositionScore.

But I recommend thinking through the implications of using a random positionscore. Imagine that you have signals to buy 20 different issues at tomorrow's opening price, but only enough cash to buy 10 of them. Would you feel confident rolling the 20-sided dice to pick which ones to take with real money? If yes, then use random. If no, then decide what criteria you would use to rank order the twenty and code that into positionscore.

Thanks,
Howard
 
I'm trying to work out why the ATR line (the pinky/teal) one is set at those colours and how to change it. I can't find anything in the code. Is anyone able to help?

ATR trend.png

This is the code

_SECTION_BEGIN("Super Trend ");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();

period = Param("Period", 13, 1, 240, 1);
mult = Param("Multiplier", 1.7, 1, 240, 0.1);

f=ATR(period);

VS[0] = Close[0];
trend[0] = 0;
HighC[0]=0;
Lowc[0]=0;

for( i = period+1; i < BarCount; i++ )
{

vs = vs[i-1];
trend = trend[i-1];
highC = HighC[i-1];
lowc = lowc[i-1];

if ((trend>=0) && ( C <VS ))
{
trend =-1;
HighC = C;
lowc = C;
}

if ((trend<=0) && (C >VS))
{
trend=1;
HighC = C;
lowc = C;
}

if (trend==-1)
{
if (C<lowc) lowc = C;
VS= lowc+ (mult*f);
}


if (trend==1)
{
if (C>HighC) HighC = C;
VS= HighC-(mult*f);
}

}


Buy=Cross(Trend,0);
Sell=Cross(0,Trend);

Plot(Close,"Close",colorBlack,styleCandle);
A1 = ParamToggle("Trend Line", "Off|On", 1);
if(A1)
Plot(VS, "Vol Stop",IIf(trend==1, 10, 11),styleThick);

mkol = IIf( Trend==1, 43, 24);
B1 = ParamToggle("Trading Ribbon", "Off|On", 1);
if(B1)
Plot(5, "Ribbon", mkol, styleOwnScale|styleHistogram|styleNoLabel, 0, -5); // Weekly trend

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
C1 = ParamToggle("Trading Arrows", "Off|On", 1);
if(C1)
PlotShapes( shape, IIf( Buy, colorWhite, colorRed ), 0,IIf( Buy, Low-f*1.5, High+f*1.5)) ;
_SECTION_END();

SetChartBkColor(ParamColor("Outer panel color ",ColorRGB(144,144,144))); // color of outer border
SetChartBkGradientFill( ParamColor("Inner upper half",ColorRGB(121,121,121)),
ParamColor("Innerlower half",ColorRGB(163,163,163))); // color of inner panel
_SECTION_END();
 
I also want to know:

Is it possible to open up a new sheet and then have 2 windows and have:

1. one with a stock's daily chart and one with the same stock's weekly chart? (in the same sheet)
2. One with a stock's daily chart and one with another stock's daily chart? (in the same sheet)
 
I'm trying to work out why the ATR line (the pinky/teal) one is set at those colours and how to change it. I can't find anything in the code. Is anyone able to help?

In the line below, the numbers 10 and 11 represent colors. Change them to whatever colours you prefer (eg. ColorRed , ColorBlue) or if you prefer you can remove the IIf(trend==1) statement and have a single colour.

Code:
Plot(VS, "Vol Stop",IIf(trend==1, 10, 11),styleThick);
 
I also want to know:

Is it possible to open up a new sheet and then have 2 windows and have:

1. one with a stock's daily chart and one with the same stock's weekly chart? (in the same sheet)
2. One with a stock's daily chart and one with another stock's daily chart? (in the same sheet)

1.Check the section in the Amibroker tutorial/guide on working with chart layouts and displaying charts in different intervals.

2. Are you looking to display the 2 tickers on the same chart? If so, then you can use the "Price (Foreign)" chart listed under "Basic Charts" in your formula folder. There's also relative performance charts if you're looking to compare the relative performance of 2 tickers.
 
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.

Yeh but as I said, I had positionsize = -5, and a huge initial equity, which should mean that each and every trigger is bought, so Random() shouldn't make a difference.

Even if I add SetBacktestMode( backtestRegularRaw ), Random() still makes a difference to the curve on each run.

No idea how this happens.
 
Yeh but as I said, I had positionsize = -5, and a huge initial equity, which should mean that each and every trigger is bought, so Random() shouldn't make a difference.

Even if I add SetBacktestMode( backtestRegularRaw ), Random() still makes a difference to the curve on each run.

No idea how this happens.

positionsize = -5 means each position will have 5% of equity meaning only 20 trades will be open at any one time.
 
ok but if I remove Positionsize altogether and have:

PositionScore = Random();
SetBacktestMode( backtestRegularRaw );

I still get AB making different decisions on each run. 'Raw' should mean it takes every trade.
 
ok but if I remove Positionsize altogether and have:

PositionScore = Random();
SetBacktestMode( backtestRegularRaw );

I still get AB making different decisions on each run. 'Raw' should mean it takes every trade.

If you remove positionsize from the code check your AA settings window portfolio tab for Max. open positions setting. If you want every position to be taken it may be better to use a smaller positionsize setting such as 0.1% of equity or whatever is required to take every trigger.
 
Cap I have AA>max positions taken at 1000 already!

Very odd. Are you suggesting positionsize = -.0001 or something similar? I'm feeling like I'm missing something. Raw mode isn't doing what it says it should.
 
Cap I have AA>max positions taken at 1000 already!

Very odd. Are you suggesting positionsize = -.0001 or something similar? I'm feeling like I'm missing something. Raw mode isn't doing what it says it should.

It's probably best to email support to get a proper breakdown of what the backtest modes are designed to achieve.

It would be worth trying setting positionsize to a very small percentage and check the results.
 
...test an index function using an EMA cross as a trigger but it doesnt appear to be plotting correctly...
To answer my own question, use styleLeftAxisScale since styleOwnScale scales each EMA independently of the other, therefore the cross bears no relation to when they actually crossed.
Thanks to AmiBroker support.

JB
 
No probs GB. Post the reply from support here as this thread often shows up in google searches for Amibroker related questions and is a useful resource.

Just to re-cap for anyone following, I was playing with a system that went a bit crazy with the introduction of PositionScore = Random(). I don't have a monte carlo simulator, so I use 100 random runs to get a rough equivalent. Normally I like to see fairly similar equity curves each run, but this wasn't happening.

This fix is sort of 90% satisfying. I didn't find a complete answer, but this is good enough.

initial equity = 1000000000000// ie. large!
positionsize = 1000 // ie. small

PositionScore = Random()
SetBacktestMode( backtestRegularRaw )
Max open positions = 1000 // maximum allowable
Min shares = 1
Min Pos value = 0

Doing this should mean that each and every trade is taken. Then I used (AA –> Settings –> Report: Detailed log) to analyse more deeply.

Later, I use:

PS = Optimize("PS",1,1,100,1);
PositionScore=Random()*PS;
....for my layman's Monte Carlo analysis.
 
Then I used (AA –> Settings –> Report: Detailed log) to analyse more deeply.

Later, I use:

PS = Optimize("PS",1,1,100,1);
PositionScore=Random()*PS;
....for my layman's Monte Carlo analysis.

Hi GB --

I work with Monte Carlo simulation regularly, and my most recent book (Modeling Trading System Performance) is devoted to it. There is a Monte Carlo simulation module written as an Excel add-in on that book's website that you are welcome to download (at no cost) and use.

What I do and what you do may be quite different.

But I do not understand --
How do you use the results of the simulation runs?
What hypothesis are you testing?
What statistical manipulations or tests do you use?
How does what you find aid the development of a trading system?

Thanks,
Howard
 
Hi GB --

I work with Monte Carlo simulation regularly, and my most recent book (Modeling Trading System Performance) is devoted to it. There is a Monte Carlo simulation module written as an Excel add-in on that book's website that you are welcome to download (at no cost) and use.

What I do and what you do may be quite different.

But I do not understand --
How do you use the results of the simulation runs?
What hypothesis are you testing?
What statistical manipulations or tests do you use?
How does what you find aid the development of a trading system?

Thanks,
Howard

Hi Howard,

By using the following, I'm attempting to get close to what a monte carlo test might do. A poor man's substitute!

PS = Optimize("PS",1,1,100,1);
PositionScore=Random()*PS;

It gives me 100 results, when optimize is run. Then I look at the range of %profit reports and if they're all positive that's a good start. If they're all tightly packed together, even better. I look at the highest and lowest profit result, and assume that on average i might fall somewhere in between in live trading. If I run it 1000 times, it should be even more telling, but I find 100 adequate.

If on the other hand the system only picks out trades rarely, then there's no need for all this bother! I had a system that was buying a lot of different stocks every day, and I wanted to see what randomising would do.

I like to look at Sharpe ratio and %return. They're about the only two stats I need.
 
Ive never really understood about how to apply a stop loss to a system and hopefully plot it on the chart.

I want to set up a sell condition that would say something like

condition2= If price falls by 2% below entry price - Sell.

or

Condition2=If pricebreaks the low of the entry bar - Sell


I tried this but it doesnt plot. It just plots a line at the bottom of the chart.

ApplyStop(stopTypeLoss,
stopModePercent,
Param( "max. loss stop level", 2, 2, 30, 1 ),
True );
Plot(Sell==4,"ApplyStop Sell",colorRed,1|styleOwnScale);


Is anyone able to help please?
 
Ive never really understood about how to apply a stop loss to a system and hopefully plot it on the chart.

I want to set up a sell condition that would say something like

condition2= If price falls by 2% below entry price - Sell.

or

Condition2=If pricebreaks the low of the entry bar - Sell


I tried this but it doesnt plot. It just plots a line at the bottom of the chart.

ApplyStop(stopTypeLoss,
stopModePercent,
Param( "max. loss stop level", 2, 2, 30, 1 ),
True );
Plot(Sell==4,"ApplyStop Sell",colorRed,1|styleOwnScale);


Is anyone able to help please?

You need to use loops There is a good explanation here

http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/
 
Top