Australian (ASX) Stock Market Forum

Amibroker FAQ

The solution I came up with is as follows:

Code:
_SECTION_BEGIN( "ArrayHL" );
function ArrayHL( Periods )
{
    customArray = 0;

    j = BarCount - 1;

    for ( i = BarCount - 1; i >= 0; i-- )
    {
        if ( j < 2 * Periods )
            break;

        for ( count = 0; count <= Periods; count++ )
        {

            customArray[ j ] = H[ i - count ];
            j--;
            customArray[ j ] = L[ i - count ];
            j--;
        }
    }

    return CustomArray;
}
_SECTION_END();


_SECTION_BEGIN( "PercentileHL" );
Periods = Param( "Periods", 3, 1, 20, 1 );
Percent = Param( "Percentile (%)", 50, 0, 100, 5 );

Array = ArrayHL( Periods );

PA = Percentile( Array, 2 * Periods, Percent );
Plot( PA, "PercentileHL", colorRed, styleLine );
_SECTION_END();


It only gives the right answer at the right-most bar. Is there a way to stop the plot from 'jumping' around? I would like to overlay the plot on a price chart.
 
Since you wanna have the median of two arrays H and L then you can not have one after another since you can not exceed ticker's barcount. So I would sort one array descending and the other one ascending and then you take the two values after the cross of the two sorted arrays and (H[x]+L[x]) / 2 is the median of both arrays where x is bar after cross.

The barcount of both combined arrays is always even since 2 * x = y then y is always even no matter if x is even or uneven.


image.png
 
Thanks trash - not quite what I was looking for.

In the end I had to create 2 composite arrays (combination of H & L therefore twice as long as Barcount) to fit inside Barcount. So the arrays were H L H L H L H L H L etc. I then took the Percentile of the two arrays allowing for the 'gap' due to the lag in periods for the Percentile function. Then I had to scale the Percentiles of each array back by a half (deleting every second data point in the arrays). I then concatenated them to completely cover all data. It end up being over 100 lines of code with a bunch of simple loops but it checks off perfectly against an excel spreadsheet including allowance for the periodicy lag at the 'join' in the middle.

Thanks again for the help guys.
 
Hi everybody,
Just a quick newbie question here : When I click on the show arrows for actual trades option in the analysis window after a backtest, I notice that the arrows disappear after approximately 70 seconds if I don't move the chart. This is annoying as I then have to go back to the analysis window and select the arrows option again. Is there a way to keep the arrows there other than moving the chart before the 70 seconds are up?
 
Hi everybody,
Just a quick newbie question here : When I click on the show arrows for actual trades option in the analysis window after a backtest, I notice that the arrows disappear after approximately 70 seconds if I don't move the chart. This is annoying as I then have to go back to the analysis window and select the arrows option again. Is there a way to keep the arrows there other than moving the chart before the 70 seconds are up?

Arrows don't disappear until you click "Refresh all". You probably have a background process running that executes some OLE script refreshing the UI in interval mode. Check all your chart code(s) if there is some Shellexecute or OLE code executing. A.lso check task manager if there is some wscript.exe showing up in intervals.
 
Dear All,

I am new in here and learning to use Amibroker, I have a question which I actually don't know how to solve it.

I have a breakout strategy with the trailing stop. However, I discovered that the logic is unrealistic as I set the stop when H < UpperBand and L < trailing stop. The problem is that L could come first which hit my stop first in real time trading. If L hit my stop point first and H hit the upperband later, then the position will be cleared first and entered again. But I will still hold the position in backtest if H also hit the upperband at the same bar but no exit generated at this bar. It will create an unreasonable profit.

I would like to correct my strategy now. So, I would like to ask is there any method to prohibt my entry signal for the bar where exit is generated. I know there is an option for same bar entry/exit. However, i would like to write it in my AFL which can be used in live trading.

Thank you very much!!
 
Dear All,

I am new in here and learning to use Amibroker, I have a question which I actually don't know how to solve it.

I have a breakout strategy with the trailing stop. However, I discovered that the logic is unrealistic as I set the stop when H < UpperBand and L < trailing stop. The problem is that L could come first which hit my stop first in real time trading. If L hit my stop point first and H hit the upperband later, then the position will be cleared first and entered again. But I will still hold the position in backtest if H also hit the upperband at the same bar but no exit generated at this bar. It will create an unreasonable profit.

I would like to correct my strategy now. So, I would like to ask is there any method to prohibt my entry signal for the bar where exit is generated. I know there is an option for same bar entry/exit. However, i would like to write it in my AFL which can be used in live trading.

Thank you very much!!


Try this one

Code:
// sample system start
period = 20; // number of averaging periods 
m = MA( Close, period ); // simple moving average
Buycond = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sellcond = Cross( m, Close ); // sell when closes crosses BELOW moving average
// sample system end

SellCounter = Cum( Sellcond );
SellSinceBuy = SellCounter - ValueWhen( Buycond, SellCounter );
Sellcond2 = SellSinceBuy == 1; // 1st sell signal since buy

Buy = Buycond AND BarsSince( Sellcond2 ) >= 1;
Sell = Sellcond;
 
Try this one

Code:
// sample system start
period = 20; // number of averaging periods 
m = MA( Close, period ); // simple moving average
Buycond = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sellcond = Cross( m, Close ); // sell when closes crosses BELOW moving average
// sample system end

SellCounter = Cum( Sellcond );
SellSinceBuy = SellCounter - ValueWhen( Buycond, SellCounter );
Sellcond2 = SellSinceBuy == 1; // 1st sell signal since buy

Buy = Buycond AND BarsSince( Sellcond2 ) >= 1;
Sell = Sellcond;

Thank you for your help. I will try it first.
 
Try this one

Code:
// sample system start
period = 20; // number of averaging periods 
m = MA( Close, period ); // simple moving average
Buycond = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sellcond = Cross( m, Close ); // sell when closes crosses BELOW moving average
// sample system end

SellCounter = Cum( Sellcond );
SellSinceBuy = SellCounter - ValueWhen( Buycond, SellCounter );
Sellcond2 = SellSinceBuy == 1; // 1st sell signal since buy

Buy = Buycond AND BarsSince( Sellcond2 ) >= 1;
Sell = Sellcond;

Hello,

May I ask one more question how to plot the actual trades as what backtester show?
Currently i am using the following code for plotting but it will plot every signal in my strategy. As I remvoed some signal generated at the same bar, some long/short signals actually were not the actual one.

PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
PlotShapes(Short*shapeDownarrow,colorblue,0,High);
PlotShapes(Cover*shapeUparrow,colorbrown,0,Low);

Thank you for your help.
 
Hello,

May I ask one more question how to plot the actual trades as what backtester show?
Currently i am using the following code for plotting but it will plot every signal in my strategy. As I remvoed some signal generated at the same bar, some long/short signals actually were not the actual one.

PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
PlotShapes(Short*shapeDownarrow,colorblue,0,High);
PlotShapes(Cover*shapeUparrow,colorbrown,0,Low);

Thank you for your help.

To remove excessive signals in chart use ExRem for example.
I don't understand your last sentence. Anyway I'm not a magician or psychic that can read your brain. Either offer more info, code or picture or otherwise you're on your own. It's no fun playing wheel of fortune.
 
To remove excessive signals in chart use ExRem for example.
I don't understand your last sentence. Anyway I'm not a magician or psychic that can read your brain. Either offer more info, code or picture or otherwise you're on your own. It's no fun playing wheel of fortune.

Sorry. i think i know what is the problem in my code after thinking for night. Thank you for your help.
 
Sorry. i think i know what is the problem in my code after thinking for night. Thank you for your help.

And what is/was the problem? Perhaps others face or will face same/similar problem. So why not posting what you have found out so that others may refer to it?
 
And what is/was the problem? Perhaps others face or will face same/similar problem. So why not posting what you have found out so that others may refer to it?

I want to plot the actual signals instead of all raw signals. So, I need to modify the code, so they would not be generated on the same bar.

Currently I use the following loop for trailing stop:

stopLevelB = LLV(Ref(C, -1), 3);
trailstopB = 0;

for( i = 0; i < BarCount; i++ )
{

// ------------------------------------------ buy exit-----------------------------------------------------

if( trailstopB [ i ] > 0 )
{
trailstopB = (Max( stoplevelB[ i ] , trailstopB[ i ] );
trailARRAYB[ i ] = trailstopB ;
}

if( trailstopB [ i ] > 0 AND L < trailstopB)
{
Sell[ i ] = 1 ;
SellPrice[ i ] = Min (Open , trailstopB);
trailstopB = 0;
}

if( trailstopB [ i ] == 0 AND Buy[ i ] )
{
trailstopB = stopLevelB[ i ];

}
else Buy[ i ] = 0;

}

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

The above code only can prevent the sell at the first bar when long is generated. However, it cannot prevent the same bar entry/exit after the first bar entry. So, I put one more code Buy = 0 after Sell = 1 to remove the same bar signal. I am checking whether it works or not.
 
Hi Guys, Can I get some help with volume-at-price please?

I'm interested in looking at making the highest volume price from the previous period (say a month) the trigger price.

_SECTION_BEGIN("VAP");
segments = IIf( Interval() < inDaily, Day(), Month() );
segments = segments != Ref( segments , -1 );
I notice you haven't posted for awhile but did you find a way to manipulate VAP? I have tried price and volume to manipulate bar colour to reflect bullish or bearish but these values are wrong arguments. Something like this doesn't work.

PlotVAPOverlay(Param("VAP Lines",300,10,1000,1), Param("VAP Width",10,1,99,1), IIf(C > Ref(C,-1), colorGreen, colorRed), Param("VAP Style",0,0,7,1)); # 3 argument wrong :1zhelp:
 
I've been using Amibroker for a couple of weeks now and am reading all I can about trading systems.

I'd like to trade the Australian market and the S&P500. I'm a while off making any 'real' trades and am testing out different systems and ideas at the moment.

I initially set up Amibroker with a downloaded list of ASX stock tickers, but have quickly realised that this list hasn't been updated for a while so there are stocks missing, others that have ceased trading etc. Obviously this affects the accuracy of my back-testing.

What data sources do you use to set up the initial database - I'm assuming I'd need historical data that's adjusted for splits etc. I'm happy to pay for this data.

On an ongoing basis, what are the data providers that people use. If I download the EOD data from Yahoo I'm assuming that'll work for a while, but I'd need to manually update splits etc. An alternative is to subscribe to EOD data that has all the updates as part of the package.

I'm looking for value for money when it comes to this data. What do you all recommend?
 
Hi

I want to optimize three parameters as follows

N = Optimize( "N", 3, 1, 7, 1 );
HoldDays = Optimize( "HoldDays", 7, 1, 7, 1 );
ProfitTarget = Optimize( "ProfitTarget", 0.4, 0.2, 4, 0.2 );

Even my dodgy maths confirms Howard Bandys statement that this amounts to 980 combinations, but Ami tells me that it requires 931 steps, and that is the number of results it produces. I haven't used SetOptimizeEngine to use any other method and can't see any place to set 'Exhaustive' which I presume is the default? Any ideas please?
 
Hi Frank --

If there is no statement "OptimizerSetEngine", then the search is exhaustive.

The difference in run count may be due to rounding error in adding floating point values.

Best regards,
Howard
 
Howard is correct. It is a result of floating point arithmetic as documented by AmiBroker here http://www.amibroker.com/kb/2010/07/20/about-floating-point-arithmetic/

Rather use

Code:
N = Optimize( "N", 3, 1, 7, 1 );
HoldDays = Optimize( "HoldDays", 7, 1, 7, 1 );
ProfitTarget = Optimize( "ProfitTarget", 4, 2, 40, 2 ) / 10;

or as seen in the link

Code:
N = Optimize( "N", 3, 1, 7, 1 );
HoldDays = Optimize( "HoldDays", 7, 1, 7, 1 );
step = 0.2;
ProfitTarget = Optimize( "ProfitTarget", 0.4, 0.2, 4 + step/2, step );
 
I've been using Amibroker for a couple of weeks now and am reading all I can about trading systems.

I'd like to trade the Australian market and the S&P500. I'm a while off making any 'real' trades and am testing out different systems and ideas at the moment.

I initially set up Amibroker with a downloaded list of ASX stock tickers, but have quickly realised that this list hasn't been updated for a while so there are stocks missing, others that have ceased trading etc. Obviously this affects the accuracy of my back-testing.

What data sources do you use to set up the initial database - I'm assuming I'd need historical data that's adjusted for splits etc. I'm happy to pay for this data.

On an ongoing basis, what are the data providers that people use. If I download the EOD data from Yahoo I'm assuming that'll work for a while, but I'd need to manually update splits etc. An alternative is to subscribe to EOD data that has all the updates as part of the package.

I'm looking for value for money when it comes to this data. What do you all recommend?

Here are some links:

http://www.australianstockmarket.com.au/data.htm
 
I've been using Amibroker for a couple of weeks now and am reading all I can about trading systems.

What data sources do you use to set up the initial database - I'm assuming I'd need historical data that's adjusted for splits etc. I'm happy to pay for this data.

On an ongoing basis, what are the data providers that people use. If I download the EOD data from Yahoo I'm assuming that'll work for a while, but I'd need to manually update splits etc. An alternative is to subscribe to EOD data that has all the updates as part of the package.

I'm looking for value for money when it comes to this data. What do you all recommend?

Hi Allan --

To my thinking, Norgate Premium Data is the gold standard.

If you have not already read it, my "Introduction to AmiBroker" describes in detail how to set up both free and subscription data services for AmiBroker, including Premium Data. You can download a free copy of the book from the book's website. Start here:
http://www.introductiontoamibroker.com/

Best regards,
Howard
 
Top