Australian (ASX) Stock Market Forum

AmiBroker Tips and Tricks

Thanks I'll suggest that he look for outliers that might skew the results. Back test across 5 years ( Jan-16 - Dec-20).

One observation I can share with you concerns the number of positions (open trades) in the portfolio. The testing started with 20 equal positions. Results ordinary, so I suggested back testing with 40 positions. The profit was larger and the DD significantly reduced. I'm unaware what number of positions was tested in the latest set of results. More evidence to me that 40 positions is better than 20 when trading small/micro cap stocks that can double and triple in price. Having just a few in the portfolio can significantly improve overall results.
 
Backtesting is made simpler & chart swapping is even easier
@Trav. may elect to do a post - how to code using the (switch) feature - as the possibilities with Amibroker is limitless.
@Skate mentioned that some might find this feature easier to use in their codes, so I have a simplified version as an introduction to what can be done.

In the following code I have made a simple price chart that has multiple moving averages shown, the chart can get a bit overloaded with information and you might want to be able to switch off 1 or more moving averages or all indicators (these could be buy / sell arrows or your secret sauce etc).

So in the following parameter select window you can turn off each Moving Average individually or all at once

1608210074974.png

Also in this example I have added some charts that can be used and are contained in the same AFL file (image blacked out to simplify drop down view)

1608210144723.png

to insert these just create a new blank pane and follow the instructions

1608210350361.png

1608210518905.png


So in the above example you can have a chart looking like this

1608210619109.png

you can use this logic to switch codes as suggested by @Skate or you might have an alternate way to use the ParamList function, feel free to add your thoughts as we are all here to learn.



1608210976436.png


Code:
ChartType = ParamList( "Chart Type", "Price Chart|ADX & STOCH|ADX & MACD" ); // Enables the user to select which type of chart is displayed.

Show_MA10 = ParamToggle( "Show MA10", "Off|On", 1 ); // Turn on/off moving average plot
Show_MA20 = ParamToggle( "Show MA20", "Off|On", 1 );
Show_MA50 = ParamToggle( "Show MA50", "Off|On", 1 );
Show_MA100 = ParamToggle( "Show MA100", "Off|On", 1 );
Show_MA200 = ParamToggle( "Show MA200", "Off|On", 1 );


AllOff = ParamToggle( "Turn Off All Inidcators", "Off|On", 1 ); // Turns all moving averages off in Price chart


///////////////////////////////////////////
//              CHARTING                 //
///////////////////////////////////////////


SetChartBkColor(colorBlack);
SetChartBkGradientFill( colorBlack, colorBlack);

if( ChartType == "Price Chart" )
{
Plot( C, "Price", colorDefault, styleCandle );

if( Show_MA10 AND AllOff )
{
     Plot( EMA( C, 10), "EMA 10 ", colorGold, styleLine, 0, 0, 0, 0, 1 );
}

if( Show_MA20 AND AllOff )
{
     Plot( EMA( C, 20), "EMA 20 ", colorGreen, styleLine, 0, 0, 0, 0, 1 );
}

if( Show_MA50 AND AllOff )
{
     Plot( EMA( C, 50), "EMA 50 ", colorAqua, styleLine, 0, 0, 0, 0, 1 );
}

if( Show_MA100 AND AllOff )
{
     Plot( EMA( C, 100), "EMA 100 ", colorBlue, styleLine, 0, 0, 0, 0, 1 );
}

if( Show_MA200 AND AllOff )
{
     Plot( EMA( C, 200), "EMA 200 ", colorBrown, styleLine, 0, 0, 0, 0, 1 );
}

}

if( ChartType == "ADX & STOCH" )
{
_SECTION_BEGIN("Stochastic %D");
periods = Param( "Periods", 12, 1, 200, 1 );
Ksmooth = Param( "%K avg", 1, 1, 200, 1 );
Dsmooth = Param( "%D avg", 1, 1, 200, 1 );
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

SetChartBkColor( colorBlack );
r4 = Param("Periods", 12, 2, 200, 1 );
ADXColor = IIf( ADX(r4) > 30, colorBrightGreen, colorDarkGreen);
Plot( ADX(12), StrFormat("ADX"+"(%g)", r4), ADXColor, ParamStyle("ADX style", styleThick | styleOwnScale ) );

_SECTION_END();
}

if( ChartType == "ADX & MACD" )
{
_SECTION_BEGIN("ADX & MACD");
SetChartBkColor( colorBlack );
ADXColor = IIf( ADX(14) > 30, colorBrightGreen, colorDarkGreen);
Plot( ADX(14), StrFormat("ADX"+"(%g)", 14), ADXColor, ParamStyle("ADX style", styleThick | styleOwnScale ) );

FastMACD = 12;
SlowtMACD = 26;
SignaMACD = 9;
Plot( ml = MACD(FastMACD, SlowtMACD), StrFormat("MACD"+"(%g,%g)", FastMACD, SlowtMACD), ParamColor("MACD color", colorRed ), ParamStyle("MACD style", styleLine | styleOwnScale) );
Plot( sl = Signal(FastMACD,SlowtMACD,SignaMACD), StrFormat("Signal" + "(%g,%g,%g)", FastMACD, SlowtMACD, SignaMACD), ParamColor("Signal color", colorLightBlue ), ParamStyle("Signal style", styleLine | styleOwnScale) );
Plot( ml-sl, "MACD Histogram", ParamColor("Histogram color", colorDefault ), styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleNoLabel | styleOwnScale, maskHistogram ) );
_SECTION_END();
_SECTION_END();
}
 
and another twist to the above.....food for thought anyway

3 x simple systems that can be displayed on the one chart.

1608294974868.png

Parameters for each can be adjusted here in the properties for each system

1608295039406.png


1608295230009.png

Code:
SystemSelect = ParamList( "System Select", "Channel Break Up|EMA Crossover|MA Crossover" ); // Enables the user to select which type of system is traded.

ShowArrows = ParamToggle( "Show Buy/Sell Arrows", "Off|On", 1 );

AllOff = ParamToggle( "Turn Off All Inidcators", "Off|On", 1 ); // Turns all moving averages off in Price chart

ChannelBreakUpPeriod = Param("Channel Break Up Period", 10, 5, 100, 1); // 10 bars
StopLevel = 1 - Param("Channel Break Up TS %", 20, 5, 30, 1)/100;
EMAperiod = Param("EMA Crossover", 20, 5, 100, 1); // number of averaging periods
MAperiod = Param("MA Crossover", 20, 5, 100, 1); // number of averaging periods

SetTradeDelays(1, 1, 1, 1);

///////////////////////////////////////////
//              CHARTING                 //
///////////////////////////////////////////

// Title
_N(Title = StrFormat("{{NAME}}" + " - {{FULLNAME}} " + " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol " +
WriteVal(V, 1.0), O, H, L, C, (ROC(C, 1))));

SetChartBkColor(colorBlack);
SetChartBkGradientFill( colorBlack, colorBlack);
SetChartOptions(1, chartShowDates, chartGridMiddle, 0, 0, 0);
Plot( Close,"Price",colorBlack,styleBar);

if( SystemSelect == "Channel Break Up" )
{

ChannelBreakUp = Close > Ref( HHV( High, ChannelBreakUpPeriod ), -1 );
Buy = ChannelBreakUp;
Sell = 0;

trailARRAY = Null;
trailstop = 0;

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

   if( trailstop == 0 AND Buy[ i ] )
    {
       trailstop = High[ i ] * stoplevel;
    }
    else Buy[ i ] = 0; // remove excess buy signals

   if( trailstop > 0 AND Low[ i ] < trailstop )
    {
       Sell[ i ] = 1;
       SellPrice[ i ] = trailstop;
       trailstop = 0;
    }

   if( trailstop > 0 )
    {   
       trailstop = Max( High[ i ] * stoplevel, trailstop );
       trailARRAY[ i ] = trailstop;
    }

}

Plot( trailARRAY,"trailing stop level", colorRed );

if( showArrows AND AllOff )
{
/* Plot Buy and Sell Signal Arrows */

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeupArrow, shapeNone),colorWhite, 0,L, Offset=-45);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, L, Offset=-60);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,L, Offset=-70);
PlotShapes(IIf(Sell, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-65);
}
}

if( SystemSelect == "EMA Crossover" )
{
emaCross = EMA( Close, EMAperiod ); // exponential moving average

Buy = Cross( Close, emaCross ); // buy when close crosses ABOVE moving average
Sell = Cross( emaCross, Close ); // sell when closes crosses BELOW moving average

if( AllOff )
{
Plot( emaCross, "EMA ", colorGreen, styleLine, 0, 0, 0, 0, 1 );
}

if( showArrows AND AllOff )
{
/* Plot Buy and Sell Signal Arrows */

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeupArrow, shapeNone),colorWhite, 0,L, Offset=-45);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, L, Offset=-60);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,L, Offset=-70);
PlotShapes(IIf(Sell, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-65);
}
}

if( SystemSelect == "MA Crossover" )
{
maCross = MA( Close, MAperiod ); // simple moving average

Buy = Cross( Close, maCross ); // buy when close crosses ABOVE moving average
Sell = Cross( maCross, Close ); // sell when closes crosses BELOW moving average

if( AllOff )
{
Plot( maCross, "MA ", colorYellow, styleLine, 0, 0, 0, 0, 1 );
}

if( showArrows AND AllOff )
{
/* Plot Buy and Sell Signal Arrows */

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeupArrow, shapeNone),colorWhite, 0,L, Offset=-45);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, L, Offset=-60);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,L, Offset=-70);
PlotShapes(IIf(Sell, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-65);
}
}

Have Fun :cool:
 
I was adding some new watchlists today and it took me a minute to remember how to organise them, so I thought that I would share this really simple but important tip

From the toolbar select Symbol / Categories.

1608454346207.png

Select the Watch list tab, and then move up / down your watchlists into the order that you would like.

1608454382282.png

Simple as that, but a handy reminder.
 
Hi there, how can i set up Amibroker for multiple time frame analysis?

I want to have 4 chart windows open, each timeframe taking up a quarter of the screen space. weeky, daily, 4hr and 5min.

Thanks in advance!
 
*** I had this post lined up and forgot to post for some reason ****

Once you get that working you will want to save the layout for future use as you not want to do the arranging every time....

So in your Layout section right click and select Save As...Rename ( eg 4 chart layout )

1609566809542.png

Once saved you can also set this new layout as Default Layout
 
Now, quick question: is there a way to sync the cursor so that when it's pointing at one price on one timeframe, it'll highlight the same price on all other timeframes?
Not that I am aware of mate, but others might have seen this elsewhere.

If you do some reading on TimeFrameSet you then can have multiple time frames in the one chart, which may be a work around.

1609572055646.png
 
Now, quick question: is there a way to sync the cursor so that when it's pointing at one price on one timeframe, it'll highlight the same price on all other timeframes?

It's certainly possible, I use it for discretionary trading with multiple time frame charts in Amibroker. The thread below on the AB forum might give you some helpful pointers.


Great username btw @greasy_pancakes :)
Pancakes smothered in home-made butter is my favourite way to kick off the day :)
 
Thanks for dropping by @captain black and that worked well.

Thanks @Trav. Great thread btw. I rarely drop in here nowadays but I'm in the office over xmas-New Year looking after our auto systems etc. while the other guys have a break so thought I'd see what's been happening on here :)

Now I know nearly 5% of the capabilities of AmiBroker. :xyxthumbs

Yeah, it's amazing software, capable of anything. I've been using it for 20 years now and still come across new ways of doing things.
 
I was adding some new watchlists today and it took me a minute to remember how to organise them, so I thought that I would share this really simple but important tip

From the toolbar select Symbol / Categories.

View attachment 116803

Select the Watch list tab, and then move up / down your watchlists into the order that you would like.

View attachment 116804

Simple as that, but a handy reminder.

Another good way to add/subtract/edit your Watchlists is to find the "index" file in C:\Program Files\AmiBroker\Data\WatchLists. Exit AmiBroker and edit it with Notepad and save. Delete all the other Watchlists in that Folder. It will update to new one next time you start AmiBroker.

Probably a good idea to make sure you've got a backup in case you mess up.

Whenever I run a Filter that I only want to save the result temporarily, I made a Watchlist called "0 Watch" or just "0". It appears at the top of the list so it's easy to access, and when finished, I overwrite it with the next Filter. HIghlight, then right click and "replace watch list list with selected results". This way you can scroll up and down without clicking.
 
Another good way to add/subtract/edit your Watchlists is to find the "index" file in C:\Program Files\AmiBroker\Data\WatchLists. Exit AmiBroker and edit it with Notepad and save. Delete all the other Watchlists in that Folder. It will update to new one next time you start AmiBroker.

Probably a good idea to make sure you've got a backup in case you mess up.

Whenever I run a Filter that I only want to save the result temporarily, I made a Watchlist called "0 Watch" or just "0". It appears at the top of the list so it's easy to access, and when finished, I overwrite it with the next Filter. HIghlight, then right click and "replace watch list list with selected results". This way you can scroll up and down without clicking.

Oops, done this from memory. Thought I'd better recheck process. Do not delete other Watchlists in that folder !! The index calls up those required *.txt files in that folder - the others can remain but are not used.
 
I was adding some new watchlists today and it took me a minute to remember how to organise them, so I thought that I would share this really simple but important tip
As I am in a sharing mood this morning I thought that I would put up some watchlist that are good starting point for you to run your scans against a particular sector.

You could do this by selecting a sector as per below but you have 780 stocks currently in the Basic Materials Sector

1612569334342.png

Now if you wanted to focus on some Lithium stocks then I would select my watchlist as per below which has 19 stocks and therefore narrowed down your search a lot.

1612569413110.png

I have attached some watchlist that I created in the zip file and you can add / remove stocks in each section

1612569639852.png

Just extract to your watchlist folder and my path is below but you will find yours will have the standard Norgate watchlists already there

1612569693982.png

If the newly imported watchlists don't show immediately then restart AmiBroker and they should show up in the Watch Lists folder. Then you can reorganize as detailed in my previous post.

Now back to creating that Cobalt watchlist.

Goodluck !!!
 

Attachments

  • Watchlists.zip
    1.7 KB · Views: 17
Just knocked up a quick Cobalt list of stocks as well

 

Attachments

  • Cobalt.zip
    211 bytes · Views: 6
As I am in a sharing mood this morning I thought that I would put up some watchlist that are good starting point for you to run your scans against a particular sector.

You could do this by selecting a sector as per below but you have 780 stocks currently in the Basic Materials Sector

View attachment 119632

Now if you wanted to focus on some Lithium stocks then I would select my watchlist as per below which has 19 stocks and therefore narrowed down your search a lot.

View attachment 119633

I have attached some watchlist that I created in the zip file and you can add / remove stocks in each section

View attachment 119637

Just extract to your watchlist folder and my path is below but you will find yours will have the standard Norgate watchlists already there

View attachment 119638

If the newly imported watchlists don't show immediately then restart AmiBroker and they should show up in the Watch Lists folder. Then you can reorganize as detailed in my previous post.

Now back to creating that Cobalt watchlist.

Goodluck !!!

Awesome, thanks Trav!
 
I've been adding this code to my AFL:

Near the top of the file:

Code:
// System name for the chart watermark
SystemName                = StrExtract(StrExtract(GetFormulaPath(), -1, '\\'), -2, '.' );  // uses filename as SystemName
Ver                       = "1.01";  // This needs to be incremented for every committed change
SystemNameVer             = SystemName + "_" + Ver;

Then at the top of the charting section:

Code:
// Add watermark so we know we have the correct chart with the correct analysis
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", 24, weight=300, italic=true, underline=false, orientation=0);
GfxSetTextAlign(6);     // 6 = center, 0 = left, 2 = right
GfxSetTextColor(colorGrey40);
GfxSetBkMode(1);        // transparent
GfxTextOut(SystemNameVer, Status("pxwidth")/2.2, Status("pxheight")/2.5);

This adds a watermark to my chart so I know it's in sync with my AFL.

Before this, I often was looking at a chart that didn't match my AFL, wondering why my buy and sell arrows were off!

1618231168873.png
 
I've been adding this code to my AFL:

Near the top of the file:

Code:
// System name for the chart watermark
SystemName                = StrExtract(StrExtract(GetFormulaPath(), -1, '\\'), -2, '.' );  // uses filename as SystemName
Ver                       = "1.01";  // This needs to be incremented for every committed change
SystemNameVer             = SystemName + "_" + Ver;

Then at the top of the charting section:

Code:
// Add watermark so we know we have the correct chart with the correct analysis
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", 24, weight=300, italic=true, underline=false, orientation=0);
GfxSetTextAlign(6);     // 6 = center, 0 = left, 2 = right
GfxSetTextColor(colorGrey40);
GfxSetBkMode(1);        // transparent
GfxTextOut(SystemNameVer, Status("pxwidth")/2.2, Status("pxheight")/2.5);

This adds a watermark to my chart so I know it's in sync with my AFL.

Before this, I often was looking at a chart that didn't match my AFL, wondering why my buy and sell arrows were off!

View attachment 122732
Was doing something similar but more manual: thanks for the code,will adopt .
 
Top