June 21, 2015 17:13
THIS IS A BETA VERSION OF THE SOFTWARE. EXPECT BUGS !!!
Backup your data files and entire AmiBroker folder first!
INSTALLATION INSTRUCTIONS
Just run the installer and follow the instructions.
Then run AmiBroker. You should see "AmiBroker 6.00.0 BETA" written in the About box.
See CHANGE LOG below for detailed list of changes. Note that only changes
that affect end-user directly are listed here. Internal code changes/refactoring
is usually not mentioned.
CHANGE LOG
CHANGES FOR VERSION 6.00.0 (as compared to 5.99.0)
MxGetSize( matrix, 0 ) - gives number of rows
MxGetSize( matrix, 1 ) - gives number of columns
CHANGES FOR VERSION 5.99.0 (as compared to 5.98.0)
To create a matrix use
my_var_name = Matrix( rows, cols, initvalue)
To access matrix elements, use:
my_var_name[ row ][ col ]
where
row is a row index (0... number of rows-1)
and
col is a column index (0... number of columns-1)
Matrices and their elements support all scalar (element-wise) arithmetic and logical operations
So you can for example add, subtract, multiply, divide two matrices if they have same dimensions with one call.
x = Matrix( 5, 6, 9 ); // matrix 5 rows 6 columns, initial value 9
y = Matrix( 5, 6, 10 ); // matrix 5 rows 6 columns, initial value 10
z = y - z; // will give you matrix 5 rows and 6 columns filled with elements holding value 1 (difference between 10 and 9).
All those operations are performed ELEMENT-WISE.
You can also apply any arithmetic and logical operation on matrix AND
scalar value. This would perform element-wise
operation on each element of source matrix and given scalar value.
m = Matrix( 10, 10, 0 ); // m will be 10x10 matrix filled with zeros
z = m; // z is now also a matrix
for( i = 0; i < 10; i++ )
{
z[ i ][ 4 ] = i; // fill z with some other values, note that m will remain
unaffected.
}
for( i = 0; i < 10; i++ )
_TRACEF( "%g = %g, %g, %g\n", i, m[i][1], m[ i][4], z[ i][4]);
// scalar addition (element wise)
z += 3;
m += 5;
for( i = 0; i < 10; i++ )
_TRACEF( "%g = %g, %g, %g\n", i, m[i][1], m[ i][4], z[ i][4]);
Additionally there is a new operator @ that handles matrix product (matrix
multiplication in the sense used in linear algebra). This operator requies
that number of columns in first array is the same as number of rows in
second array.
A = Matrix( 1, 3 );
B = Matrix( 3, 2 );
// matrix A = [ 1, 4, 6 ]
// matrix B = [ 2, 3 ]
// [ 5, 8 ]
// [ 7, 9 ]
A[ 0 ][ 0 ] = 1; A[ 0 ][ 1 ] = 4; A[ 0 ][ 2 ] = 6;
B[ 0 ][ 0 ] = 2; B[ 0 ][ 1 ] = 3;
B[ 1 ][ 0 ] = 5; B[ 1 ][ 1 ] = 8;
B[ 2 ][ 0 ] = 7; B[ 2 ][ 1 ] = 9;
X = A @ B;
_TRACEF("%g %g", X[ 0 ][ 0 ], X[ 0 ][ 1 ] );
CHANGES FOR VERSION 5.98.0 (as compared to 5.97.0)
CHANGES FOR VERSION 5.97.0 (as compared to 5.96.0)
CHANGES FOR VERSION 5.96.0 (as compared to 5.95.0)
ValidFrom - defines first bar since entry when stop can generate an exit.
0 means from the very beginning
ValidTo - defines last bar since entry when stop can generate an exit. -1
means "infinite".
By default stops are valid all the time (0/-1).
So now you can create stops that get actived/deactivated in different times.
This setting is independent for each stop type. It also works in conjunction
with SetOption("HoldMinBars", x ).
HoldMinBars affects BOTH regular exits and stops, preventing ALL kind of
exits during defined period.
ValidFrom/ValidTo works on each stop separately and does not affect regular exits.
For example always have a stopTypeLoss always in affect and only allow a trailing stop to become active after so many bars:
ApplyStop(stopTypeLoss, stopModePercent, 10, 1);
ApplyStop(stopTypeNBar, stopModeBars, 40, 1);
ApplyStop(stopTypeTrailing, stopModeRisk, 7, True, True, 0, 4 /* valid from
4th bar after entry */ );
This feature is extended implementation of FC item #514
IMPORTANT:
Precedence parameter introduced in 5.95 has been REMOVED.
That functionality has been replaced by new SetStopPrecedence function.
the old option:
SetOption("MCEnable", 1 ); // value == 1 enables MC only in portfolio
backtests (default)
Note that enabling MC in optimization is highly discouraged unless you actually
use MC metrics as optimization target via custom backtester
or otherwise use MC distributions in the optimization process.
Monte Carlo process is computationally costly and while few hundred milliseconds
added to one backtest don't matter much,
in case of optimizations when these are multipled by number of steps you
can easily increase optimization time by orders of magnitude.
So unless you REALLY need MC distribution as custom metric and optimization
target, do NOT enable MC in optimization.
and disables those preset controls from accidential change.
Using presets prevents beginners from using wrong settings.
It is still possible to override any setting from the formula level (so be careful what you write in your formula).
A default "CUSTOM" scenario works as in old versions -i.e. all
fields are enabled for change but it is user responsibility
to set those fields properly. Flexibility comes at a cost - some combinations
of settings that are not covered by preset scenarios
may make no sense and sometimes lead to wrong results. The user should consult
the manual and/or ask support when in doubt.
CHANGES FOR VERSION 5.95.0 (as compared to 5.94.0)
Keep in mind that if you are changing ApplyStop order/precedence you
1. MUST DEFINE ALL APPLYSTOP even if you don't use all stop types. It you
don't use given stop type use stopModeDisable in mode parameter
2. There must be NO DUPLICATE in precedence numbers. Otherwise unpredictable
behavior may occur.
3. The order of events inside bar is unknown so specifying given order of
execution of stops
is based on assumptions that may or may not be correct for given trading scenario.
It is advised to keep max. loss stop as first one.
Whenever N-bar stop is executed first or not depends on your trading setup.
If you trade on open, then Nbar stop may be executed first (even before max
loss).
Trailing stop can be excuted before or after profit target depending on your
setup. Contrary to "gut feeling" executing trailing stop before profit
target is not necesarily more pessimistic, because
in several cases leads to increasing CAR instead of decreasing it. Now you
can test both. Choose whatever fits your trading style. Choo
Example:
// Applystops will be excuted in the following order: loss, trailing, profit,
n-bar:
ApplyStop( stopTypeLoss, stopModePercent, 5, True, False, 0, 0 /*precedence*/
);
ApplyStop( stopTypeTrailing, stopModePercent, 5, True, False, 0, 1 /*precedence*/
);
ApplyStop( stopTypeProfit, stopModePercent, 5, True, False, 0, 2 /*precedence*/
);
ApplyStop( stopTypeNBar, stopModeBars, 40, False, False, 0, 3 /*precedence*/
);
Note:
for backward compatibility:
With stopTypeNBar, when Precedence parameter is provided then ExitAtStop
setting is ignored.
When Precedence parameter is not provided for stopTypeNBar
there are two possible sequences applied by default
if NBarHasPriority setting is true or you call ApplyStop with ExitAtStop
set to true then sequence is N-bar, loss, profit, trailing
otherwise default sequence is loss, profit, trailing, N-bar
These defaults will be re-applied whenever you call ApplyStop( stopTypeNBar
... ) without providing precedence parameter.
Note 2:
Fixed ruin stop (99.6% loss) is always executed as last one.
per = Optimize( "period", 20, 2, 100, 1 );
Buy = Cross( C, MA( C, per ) );
Sell = Cross( MA( C, per ) , C );
SetOption("MCEnable", True );
SetOption("MCRuns", 1000 );
SetPositionSize( 1, spsShares );
SetCustomBacktestProc("");
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(); // run default backtest procedure
// get access to Monte Carlo results
// note 1: it may be NULL if MC is NOT enabled
// note 2: MC results are available after Backtest() or PostProcess as MC simulation
is done in final phase of post processing
mc = bo.GetMonteCarloSim();
if( mc )
{
// get 25-th percentile of final equity distribution
bo.AddCustomMetric("FinalEq25", mc.GetValue( "FinalEquity",
25 ) );
}
}
It implements fast 4th-order infinite impulse response filter.
Analytically it is:
y[ n ] = b0 * x[ n ] + b1 * x[ n - 1 ] + b2 * x[ n - 2 ] + b3 * x[ n - 3
] + b4 * x[ n - 4 ]
+ a1 * y[ n - 1 ] + a2 * y[ n - 2 ] + a3 * y[ n - 4 ] + a4 * y[ n -4 ];
AFL equivalent:
y = x; // init so no glitches at the beginning appear
for( n = 4; n < BarCount; n++ )
{
y[ n ] = b0 * x[ n ] + b1 * x[ n - 1 ] + b2 * x[ n - 2 ] + b3 * x[ n - 3 ]
+ b4 * x[ n - 4 ]
+ a1 * y[ n - 1 ] + a2 * y[ n - 2 ] + a3 * y[ n - 4 ] + a4 * y[ n - 4 ];
}
Filters of orders 3 and 2 can be implemented by leaving unneeded arguments at default value of zero.
Coefficients b0, b1, b2, b3, b4 multiply the input signal x[n] and are referred to as the feedforward coefficients. Coefficients a1, a2, a3, a4 multiply the output signal y[n] and are referred to as the feedback coefficients. Pay careful attention to the sign of the feedback coefficients. Some design tools flip the sign of the feedback coefficients. In this case the feedback coefficients must be negated.
This convention is used so feedback coefficients work the same as in AMA2 in case of first order filter, so
IIR( array, factor, 1-factor )
is the same as
AMA2( array, factor, 1-factor )
(with very minor difference is that IIR uses internally double precision arithmetic while AMA2 uses single precision)
simple ema:
factor = 2/(period+1);
IIR( input, factor, 1- factor );
wilders:
factor = 1/period
IIR( input, factor, 1-factor );
Ehlers Supersmoother
Periods = 10;
c1 = 1.41421 * 3.14159 /
Periods;
c2 = 2.71828^-c1;
a1 = 2 * c2 * cos(
c1 );
a2 = -c2^2;
b0 = (1 - a1 - a2)/2;
b1 = b0;
x = IIR( Close, b0, a1, b1, a2 );
Plot( x, "Super Smoother", colorRed );
CHANGES FOR VERSION 5.94.0 (as compared to 5.93.0)
AmiBroker's built-in Monte Carlo simulator is high speed (30+ million trades
per second) simulator that runs series of random trade sequences based on
backtest output.
It uses high-quality Mersene Twister random number generator.
It is run automatically after backtest and produces a series of CDF charts
(see extra tabs in the New Analysis window). These charts are probably going
to be moved
to the report at later stage.
Monte Carlo simulator is by default available only during portfolio backtest
runs. It is NOT available/running during optimization or individual optimization.
(I may enable it in the future).
You can control process of Monte Carlo simulation using new Settings page:
"Enable Monte Carlo Simulation" - turns on/off MC simulator
"Number of runs" - defines how many MC simulation runs is done (default 1000)
"Position sizing" - defines position sizing used by Monte Carlo
simulator.
Position sizing algorithm used by MC process is independent from that used
by backtest. To do so MC may apply special processing to trade list obtained
from backtester depending on this option setting.
- "Don't change" - uses trades as they are coming from the backtester
without changing position size and profit as it is reported from the backtester
- "Fixed size: N shares/contracts" - trade fixed number of shares/contracts.
It takes per-share profit as reported by backtester and muliplies it by N
contracts as entered in the settings. Per-share profit is calculated by dividing
profit reported by the backtester by number of shares/contracts reported
by the backtester
- "Constant value: X" - trades fixed amount per trade. Takes percent
profit reported by backtester and multiplies it by constant value entered
to get the profit.
returns TRUE or FALSE whenever string matches searchstring or not.
Searchstring is can contain wild-card characters such as:
* - matches any string, including empty strings
? - matches any single character
This function is case sensitive (of course except wildcard characters).
If you want case insensitive matching - convert both string and searchstring
to lowercase or uppercase
prior to matching (StrLower/StrUpper)
Example:
x = StrMatch("Every breath you take", "Every * you *");
// x will be TRUE
x = StrMatch("Every step you make", "Every * you *");
// x will be TRUE
Tables of all UCN/Unicode characters
http://www.unicode.org
http://unicode-table.com/
http://www.unicodemap.org
http://en.wikipedia.org/wiki/List_of_Unicode_characters
Various arrows:
http://www.unicode.org/charts/PDF/U2190.pdf
Enclosed alphanumerics:
http://www.unicode.org/charts/PDF/U2460.pdf
(note: NOT all glyphs (graphical representations of characters) are actually
present in current font. This depends on your operating system. For example
Segoe UI in Windows 7 has lots of characters, but Windows 8 has more,
if a glyph is missing usually an empty rectangle is drawn). DejaVu free font
has lots of glyphs, Symbola free font has lots of weird shapes.
Plot( C, "", colorDefault );
PlotTextSetFont( "♥Ω↑⇑⓮☝", "Segoe
UI", 30, 20, HighestVisibleValue( C )/2 + LowestVisibleValue( C )/2
, colorRed );
Title = "A demo of UCN: "+EncodeColor(colorRed)+"♥Ω↑€Σβ☂☎";
CHANGES FOR VERSION 5.93.0 (as compared to 5.92.0)
WHITE_BRUSH 0
LTGRAY_BRUSH 1
GRAY_BRUSH 2
DKGRAY_BRUSH 3
BLACK_BRUSH 4
NULL_BRUSH 5 (the same as hollow brush)
HOLLOW_BRUSH 5
WHITE_PEN 6
BLACK_PEN 7
NULL_PEN 8
OEM_FIXED_FONT 10
ANSI_FIXED_FONT 11
ANSI_VAR_FONT 12
SYSTEM_FONT 13
DEVICE_DEFAULT_FONT 14
SYSTEM_FIXED_FONT 16
DEFAULT_GUI_FONT 17
Example circle with hollow interior:
GfxSelectPen( colorOrange, 4 );
GfxSelectStockObject( 5 ); // hollow brush
GfxCircle(100, 100, 20 );
HS_HORIZONTAL 0 /* ----- */
HS_VERTICAL 1 /* ||||| */
HS_FDIAGONAL 2 /* \\\\\ */
HS_BDIAGONAL 3 /* ///// */
HS_CROSS 4 /* +++++ */
HS_DIAGCROSS 5 /* xxxxx */
Hatch color is specified by color parameter, hatch background is specified
by current background color
see: GfxSetBkColor()
GfxSelectPen( colorOrange, 4 );
GfxSetBkColor( colorLightGrey );
GfxSelectHatchBrush( colorBlue, Param("Hatch pattern", 5, 0,
5 ) );
GfxCircle(100, 100, 20 );
bi = BarIndex();
x = Percentile( Close, bi, 50 );
Plot( x, "Cumulative 50% Percentile", colorRed );
Plot( Close, "Price", colorDefault, styleCandle );
XYChartSetAxis(chartname, "[x]", "[sinx/x]", styleLine
| styleDots ); // bar style
for( x = -10; x < 10; x += 0.2 )
{
y = sin(x ) / x;
XYChartAddPoint( chartname, "", x, y, colorGreen, colorRed );
}
XYChartAddPoint( chartname, "", Null, Null ); // add a NULL point
to begin new line
for( x = -10; x < 10; x += 0.2 )
{
y = sin( 2 * x ) / x;
XYChartAddPoint( chartname, "", x, y, colorOrange, colorBlue );
}
You can turn it off from Settings, Reporting
Buy-and-hold simulation uses current symbol when doing single-symbol backtests/optimization.
When doing portfolio backtest for more than one symbol, it uses "Portfolio
B&H symbol" as a benchmark for buy and hold.
Current rates used are listed in the Detailed Log
1. Add a symbol that will hold interest rates. It does not need to have
quotes every day,
you can have only quotes on days when interest rate changes.
Interest rates should be expressed in PERCENTS. So if interest is 5% you
should enter 5 in "close" price field for particular date
2. Enter the rate symbol into "Dynamic interest symbol" in the Settings.
3. Enter "Fixed interest rate" in the Settings. It will be used for days PRIOR to very first date available in intrest rate symbol.
CHANGES FOR VERSION 5.92.0 (as compared to 5.91.1)
Example of bar style usage (this is EXPLORATION code):
chartname = "example";
XYChartSetAxis( chartname, "[x]", "[sinx/x]", 1 ); //
bar style
for ( x = -10;
x < 10; x += 0.2 )
{
y = sin( x ) / x;
XYChartAddPoint( chartname, "",
x, y, colorGreen );
}
Second example:
chartname = "gaussian";
XYChartSetAxis( chartname, "[x]", "[gaussian]", 1 );
for ( x = -3;
x < 3; x += 0.125 )
{
y = exp( - x ^ 2 );
XYChartAddPoint( chartname, "",
x, y, IIf( abs(
x ) <= 1, colorGreen, colorRed )
);
}
CHANGES FOR VERSION 5.91.0 (as compared to 5.90.1)
SetOption("NoDefaultColumns", True );
Filter = 1;
AddColumn( Close, "Column1" );
AddColumn( Null, "Column2" );
for( i = 0;
i < 10; i++ )
{
AddRow( StrFormat( "row
%g\tsecond column", i ) );
}
only_when = ( Month() % 2 )
== 0; // even months only
x = SparseCompress( only_when, Close ); // compact
sparse data
y = MA( x, 10 ); //
regular calculation
y = SparseExpand( only_when, y ); //
expand sparse data
Plot( C, "Price", colorDefault, styleBar );
Plot( y, "Sparse MA from
even months", colorRed );
function SparseCompressEquiv( sparse_array,
data_array )
{
result = Null;
j = BarCount - 1;
for( i = BarCount - 1;
i >= 0; i-- )
{
if( sparse_array[ i ] ) result[ j-- ] =
data_array[ i ];
}
return result;
}
function SparseExpandEquiv( sparse_array,
data_array )
{
result = Null;
j = BarCount - 1;
for( i = BarCount - 1;
i >= 0; i-- )
{
if( sparse_array[ i ] ) result[ i ] = data_array[
j-- ];
}
return result;
}
HOW TO REPORT BUGS
If you experience any problem with this beta version please send detailed description of the problem (especially the steps needed to reproduce it) to support at amibroker.com