Sei sulla pagina 1di 34

AMIBROKER FOR EVERYONE

Backtesting
===========================================================================

INTRODUCTION TO AMIBROKER FOR


3-1 Testing the AmiBroker Backtest stock trading system
===========================================================================
Objective
 Able to understand the user interface for back testing of AmiBroker program
 The basic understanding of the Analysis window elements
 The basic understanding of the Formula window component

======================================================================================

In summary
 Backtest is a test that How much profit or loss is our system traded in?
 Analysis Document is a window element for Backtest.
 There are 3 components of the Analysis Document which are (1) Formula (2) Apply to (3) Rang

======================================================================================

AmiBroker Backtest
 Is the test that How much profit or loss is our system traded in?
 It is a very important and difficult part of System trading
======================================================================================

Analysis Document
 Are the elements of the window. Backtest

======================================================================================

How to open the Analysis Document


1. Click the left link for the symbol + for Windows.

======================================================================================

How to open the Analysis Document


2. Select New Analysis.
======================================================================================

Components of Analysis Document


======================================================================================

Apply to
1. Is the name of the stock that has been tested for the system by being able to filter the name of the stock
2. Normally use "* All symbols" to test stocks every day

===========================================================================
Rang
1. Is the duration of the Back Test.
2. It should be noted that what kind of settings are correct for Windows, for example month-day-year or
month-year
===========================================================================
Formula
1. Is the formula that we want to test
2. The formula itself is in the "Custom" folder.

===========================================================================
How to open Formula
1. Click the left link for the symbol + for Windows.
===========================================================================
How to open Formula
2. Select "New Formula"

===========================================================================
Added link
 AmiBroker Backtest
 AmiBroker Analysis Window
 AmiBroker Formula

======================================================================================

AMIBROKER FOR EVERYONE


3-2 Test setting for Analysis Document system
===========================================================================
Objective
 Able to understand the user interface of the Analysis Document.
 Understanding The default setting is for Backtest.
 Can be preliminary values of Analysis Document.

======================================================================================

In summary
 Analysis Document consists of 3 parts which are (1) Apply to (2) Rang (3) Setting
 Apply to is the name of the stock that must be tested.
 Rang is the time period for testing
 There are 4 known elements of Setting: (1) General Tab (2) Tarde Tab (3) Stop Tab (4) Report

======================================================================================

Components of Analysis Document


1. Apply to
2. Rang
3. Setting

===========================================================================
Apply to
 Is the name of the stock that we want to test
 It is a part that cannot be coded. Must be specified in the Analysis Document..

===========================================================================
Rang
 Is the period that the test will be scheduled, month, year, beginning and end
 It is a part that cannot be coded. Must be specified in the Analysis Document.

===========================================================================
Setting

 Use general settings for use in Backtest.


======================================================================================

Tab about Setting


======================================================================================

General Tab
 Consisting of Initial Equity Positions Periodicity Min Shares etc.
======================================================================================

Trade TAB
 It consists of various conditions that we will trade, such as when buying at closing price or opening price,
selling when closing price or opening price.
==================================================================================

Stops TAB
 Will consist of Maximum loss stop, Profit target, Trailing Stop, N-bar Stop etc.
==================================================================================

Report
 Will display the report, such as Trade list or Summary
==================================================================================

Added link
 AmiBroker Analysis Window
 AmiBroker Setting

======================================================================================

AMIBROKER FOR EVERYONE


3-3 AFL Share Trading System Structure
===========================================================================
Objective
 Can understand the AFL formula
 Understand various components Of the formula
 Understanding of the basics of implementing basic systems

======================================================================================

In summary
 The structure of the AFL stock trading system is a component that requires formulas.
 There are 5 components in Formula: (1) Set Option (2) Buy and Sell (3) Position Size (4) Position Scores
(5) Apply Stop
======================================================================================

Structure of the AFL stock trading system


 Is a component that must be used in Formula consisting of 5 parts

Structure of a
trading system

===========================================================================
Skewed details The beginning of the stock trading system formula
1. Set Option: Part of the "Baseline Fee" in the Back Test, such as the initial capital, the maximum number
of shares that can be received, etc.
2. Buy and Sell: Part specifying the trading signal such as when buying MACD> 0, selling when MACD <0,
etc..
3. Position Size: Specifying the "amount of money from a drama" such as having 1 million baht but wanting
to buy one hundred thousand baht etc.
4. Position Scores: What are the "order of magnitude" of stocks that are used in conditions that have more
liquidity than the budget? For example, if Go to the budget for 10 days, but the money is not enough to
buy. Only 2 times.
5. Apply Stop: Part of the definition of "selling points", after the purchase of shares, which are such as loss
points (Stoploss), points of profit (Trailing Stop) and others

===========================================================================
Conditions for creating a stock trading system formula
It is only necessary Code or set in Setting.
to Code

===========================================================================
Added link
 AmiBroker Formula Language (AFL)
 AmiBroker AFL Reference Manual
 AmiBroker view menu

======================================================================================

AMIBROKER FOR EVERYONE


3-4 System test settings, SetOption Code
===========================================================================
Objective
 Understand the default settings for the Set Option
 Can use Google to find the structure of Code
 Understanding the meaning of various codes

======================================================================================

In summary
 SetOption is the basics of how the system should be set
 In the code, if you do not understand "Variety" or "Kasang", search on google
 There are 6 parameters of SetOption in the chapter: (1) InitialEquity (2) MaxOpenPosition (3)
MinShare (4) RoundLotSize (5) CommisionMode (6) CommisionAmount

======================================================================================

SetOption Code
 Is to set the basics of how the system will perform the configuration, such as commission, the
amount of initial Miriam to be tested, etc
 Code reading of SetOption Purpose for simplicity and reducing error in setting setting parameters
======================================================================================

Finding AmiBroker Information


 In the code, if you do not understand "Variety" or "Kasang", search on google
 How to search: Open www.google.com> Search for AmiBroker {Keyword Search}

======================================================================================

Caliber of SetOption
======================================================================================

InitialEquity
 It is to determine the initial capital.
 Format: SetOption ("InitialEquity", value);
 Example: SetOption ("InitialEquity", 1000000); Means the initial capital at 1 million baht

===========================================================================
MaxOpenPosition
 Is the maximum number of positions that the AmiBroker program can open.
 Format: SetOption ("MaxOpenPosition", value);
 Example: SetOption ("MaxOpenPosition", 20); Referring to the highest closing position = 20

======================================================================================

MinShare
 Is a small amount that can be bought
 Format: SetOption ("MinShare", value);
 Example: SetOption ("MinShare", 100); Means the smallest number of shares that can be received
is 100 baht
===========================================================================
RoundLotSize
 Is to specify the number of shares per round of purchase by making BackTest
 Format: RoundLotSize = value;
 Example: RoundLotSize = 100; Means the number of shares which must be divided 100 times, such
as 1000, 2200 etc.

===========================================================================
CommisionMode
 Is the form of commission fees (see the form of commission fees at
https://www.amibroker.com/guide/afl/setoption.html)
 Format: SetOption ("CommisionMode", value);
 Example: SetOption ("CommissionMode", 1); Means Commissions are set to%
===========================================================================
CommisionAmount
 Is the commission configuration
 Format: SetOption ("CommisionAmount", value);
 Example: SetOption ("CommisionAmount", 0.2); Means Commissions are set to%

===========================================================================
Added Link
 AmiBroker SetOption
 • AmiBroker Formula Language (AFL)
 • AmiBroker AFL Reference Manual

===========================================================================

INTRODUCTION TO AMIBROKER FOR


3-5 Formula AFL Buy and Sell Code
===========================================================================
Objective
 Understand how to create, sell, or sell stocks in the AmiBroker program.
 Understand the meaning of the Code in buying or selling in the beginning
 Understand the meaning of SetTradeDelay
 Understand the operation of the AmiBroker program

======================================================================================
In summary
 The AFL Code for buying and selling shares is "Buy" and "Sell".
 Structure
- Buy = True Condition or 1. If the condition is true, the purchase will be made.
- Sell = True Condition (1) If the condition is true, it will sell
 It is recommended to create small terms and then come together with the Buy or Sell conditions
because they are easy to understand and reduce mistakes too.

===========================================================================
Structure of purchase and sale

======================================================================================

Buy

 Meaning "buy" shares


 Create the contract: Buy = True Condition (1). If the condition is true, the purchase will be made.
 Example: Buy = Cross (MA (C, 40), MA (C, 200)); Means that if the line 40 Cross Over is higher
than the line 200, the program will buy (BUY)

Note C means the closing price which will also be used for other cases, such as O = Open, H = High, L = Low or
V = Volume

===========================================================================
Sell
 Is "selling" shares
 Create the contract: Sell = True Condition (1). If the condition is true, it will sell.
 Example: Sell = Cross (MA (C, 200), MA (C, 40)); Means that if Line 40 cross over below 200 line,
the program will sell

Note C means the closing price which will also be used for other cases, such as O = Open, H = High, L = Low or
V = Volume

===========================================================================
SetTradeDelay
 Is the trading conditions for when to trade
 Build a price tag: SetTradeDelays (buydelay, selldelay, shortdelay, coverdelay);
 Example: SetTradeDelay (1,1,0,0) = If the purchase of this day will buy the opening of this day, if
the sale is This will be sold at the opening price of tomorrow.

===========================================================================
Sub conditions
 Code writing for real use. ThaiQuants.com recommends To create small conditions and then come
together to buy or sell conditions because it is easier to understand and reduce errors as well.
 Sample

BuyCon1 = Cross(MA (C,40) , MA (C, 200));

BuyCon2 = MACD () > 0;

Buy = BuyCon1 AND BuyCon2;

 Means condition 1 when line 40 cross over is higher than line 200 condition condition 2 when
MACD> 0 purchase shares in condition 1 And condition 2 is both true

===========================================================================
Added link
 AmiBroker The Examples of Buy Sell Code
 AmiBroker SetTradeDelays
 AmiBroker Formula Language (AFL)

======================================================================================

AMIBROKER FOR EVERYONE


3-6 Investment with SetPositionSize
===========================================================================
Objective
 Understand the meaning of PositionSize.
 Understand the positionSize, SetPositionSize
 Understand the relationship between the SetPositionSIze command and the other

======================================================================================

In summary
 PositionSize is the amount of the “amount” of the shares purchased.
 PositionSize is the code used in the old version of AmiBroker, SetPositionSize is the new version of
AmiBroker code.
 PositionSize must be consistent with the SetOption section of MaxOpenPositions.

======================================================================================

PositionSize

 Is the determination of the "number" of shares which (using AmiBroker, Old Version)


 Speaker construction: PositionSize AAA;
 AAA is the quantity required. If desired, in%, put the symbol "-" in front.
 Absolutely
- PositionSize -5; Referring to the size of PositionSize is 5%
- PositionSize 100,000; Means to buy 100,000 baht of shares at a fixed amount regardless of
whether the capital increase or decrease

======================================================================================

SetPositionSize
 Is the "number" setting for the shares of the new version of AmiBroker.
 Create a post: SetPositionSize (size, method)
 Size is the size of the trade.
 method is to specify what the program will calculate from

======================================================================================

The type of method


1. spsValue is the amount
2. spsPercentOfEquity คือ ขนาดของ Equity คิดเป็ น เปอร์เซ็นต์ โดยกา หนดจากระดบั ของ Portfolio Equity
3. spsShares is the size of a stock or sign
4. spsPercentOfPosition is the size setting in percentage position position.
5. spsNoChange is to not value by using the size of Previous PosisitonSize

======================================================================================

Information
 PositionSize must be consistent with the SetOption section of MaxOpenPositions. If it is not
compliant, AmiBroker will not be able to perform the BackTest
 For example, if setting MaxOpenPositions = 20, it means the maximum number of shares is no
more than = 20. The PositionSize = 5% must be set because it allows you to buy as much as 20
baht

======================================================================================

Moving Average Parameter


1. Price Field : The cost of the program to calculate, such as the opening price of the candle (Open), the
closing price of the candle (Close)
2. Periods : How long does it take for the program to calculate the use of candles, such as using 25
candlesticks or using 200 candlesticks ?
3. Color : The color to be displayed, such as red, green, yellow, white etc.
4. Style : Lines that are displayed such as patch lines, solid lines, etc.

=====================================================================================

Added Link
 AmiBroker SetPositionSize
 AmiBroker Position sizing based on risk

=====================================================================================

AMIBROKER FOR EVERYONE


3-7 order, purchase positionScore
===========================================================================
Objective
 Understand the PositionScore
 Able to make the Jalaportal program interesting to share
 Understand the compatibility between PositionScore and Portfolio.

======================================================================================

In summary
 PositionScore is a calculation of the rating of the AmiBroker program to be used in cases where
more criteria are met than the number of eligible shares.
 PositionScore gives a pulse result, not a True / False value.

======================================================================================

PositionScore
 PositionScore is the calculation of the score of the AmiBroker program for use in cases where there
are stocks. More criteria than the number of eligible shares
 For example, if a stock has 20 shares but the stock is only able to buy 5 times, then we need to
score points in order to find that the stock is Should buy into the port while backtest
 PositionScore gives a pulse result, not a True / False value.

======================================================================================

PositionScore Code Examples

Meaning

Rating according to the volume, the higher


the volume, the higher the score

Stock rating via RSI indicator. 100 - RSI means high value
will not be good.

Rate according to volume divided by 10 moving average


values

======================================================================================

PositionScore Code Examples


======================================================================================

Added link
 AmiBroker PositionScore

=====================================================================================

AMIBROKER FOR EVERYONE


3-8 Risk and profit ApplyStop
===========================================================================
Objective
 Understand that Maximum Drawdown
 Understand the application, ApplyStop to use
 Able to apply ApplyStop to use in risk management Portfolio

======================================================================================

In summary
 ApplyStop is a shopping cart that looks for loss points and protects capital.
 The ApplyStop structure consists of 3 components which are
(1) type is to specify what ApplyStop will use to do (2) mode is to specify "type" of ApplyStop (3)
amount is amount in number
 The maximum drawdown (MDD) is the maximum draw value (Unrealized type) which is calculated
from Equity

======================================================================================

ApplyStop
 Is a coupon that looks for loss points, ports, and protects capital
 ApplyStop will sell Stop Loss or Trailing Stop depending on the user level, how it will be used.
======================================================================================

Structure of ApplyStop

 The structure of the structure is ApplyStop (type, mode, amount);


 type, which specifies what ApplyStop will do, such as selling at a loss, selling at a profit etc.
 mode is to specify the "ethnic" of ApplyStop, such as stop loss, using%, use margin
 amount is the amount that may be an indicator or an Array variable.

======================================================================================

ApplyStop: Type
 It is what determines what ApplyStop will do "what", such as selling at a loss, selling at a profit, etc.
 4 types of types of discs

[1] stopTypeLoss is a cost that can make a loss.

[2] stopTypeProfit is a profit that has already been sold

[3] stopTypeTrailing is the Trailing Stop, when the profit is at the point where the program is
needed. Profitability and expansion of strategy will be extended until the price is made. The fall to
the point of the program. Expelled to sell. Most of them will Specify the distance between the
prices, for example, the price is higher than 5 baht. Trailling is done at 1 baht.

[4] stopTypeNBar is to stop by using the Bar to apply ApplyStop, for example how many more bars
will be stopped.

======================================================================================
ApplyStop: Type
 4 types of types of discs

[3] stopTypeTrailing is the Trailing Stop, when the profit is at the point where the program is
needed. Profitability and expansion of strategy will be extended until the price is made. The fall to
the point of the program. Expelled to sell. Most of them will Specify the distance between the
prices, for example, the price is higher than 5 baht. Trailling is done at 1 baht.

[4] stopTypeNBar is to stop by using the Bar to apply ApplyStop, for example how many more bars
will be stopped.

======================================================================================

ApplyStop: Mode
 Is the "chandi" part of ApplyStop, such as Stop Loss using%, Price Spread
 4 types of modes in different modes

[1] stopModeDisable is to stop using StopLoss.

[2] stopModePercent is to stop loss by using percentage.

[3] stopModePoint is to stoploss using margin.

[4] risk is to use profit percentage.

======================================================================================

ApplyStop: amount
 Is the amount that may be a number or an Array variable.

======================================================================================

ApplyStop: Code Example


 ApplyStop (stopTypeLoss, StopModePercent, 15)
Meaning when 15% of losses are sold
 ApplyStop (stopTypeTrailing, stopModePercent, 20)
Means when the profit is sold when the price decreases by 20% from the highest price
 ApplyStop (stopTypeProfit, StopModePercent, 15)
Means when there is a 15% profit for disposal

======================================================================================

ApplyStop: Code Example

======================================================================================
Maximum Drawdown (MaxDD)
 Which is Ngoc Thort Dei (Unrealized), which is calculated from Equity
 Already 100 baht already, the financial system has gone 200 baht, but the stock has lost a loss,
which does not sell shares at a loss of 40 baht, the system has MaxDD at 20 % Etc.

Added link
 AmiBroker ApplyStop
 Using price levels with ApplyStop function
 AmiBroker How to plot a trailing stop in the Price chart

======================================================================================

AMIBROKER FOR EVERYONE


3-9 Example Improving Result from Backtesting
===========================================================================
Objective
 Understand the process Customizing the system for better results
 Understand the characteristics of the Trend Follower system.
 Understand the size of the stock price

======================================================================================

In summary
 Improving Result from Backtesting is the development of a system to increase profits or maximum
drawdown.
 Chapter 3 amendments to improve the system are (1) ApplyStop (2) Sell (3) Buy

======================================================================================

Improving Result from Backtesting

 Is the development of a system for better quality system by giving good results such as profits or
maximum drawdown
 With the aim of allowing the student to develop the system better
======================================================================================

As for the improvements in this lesson

======================================================================================
Details, improvements

Cancel stopTypeProfit and increase


Trailing distance to 50

SellCon2 = MACD () <0; It uses


Operator OR to connect sellCon1 and
sellCon2.

Set the price of the stock to be in the price


range of 2 to 10 baht by using buyCon3 = C> 2
AND C <10;

Added Calculation of Volume by


using buyCon4 = V * C> 10 000
000

======================================================================================

Code already updated


======================================================================================

Added link
 AmiBroker Backtesting
 AmiBroker Buy Sell Code
 AmiBroker ApplyStop

======================================================================================

AMIBROKER FOR EVERYONE


3-10 Ways to Read Test Results Backtest Results
===========================================================================
Objective
 Understand the reading of the BackTest Result.
 Understand the meaning of values in the BackTest Resul
 A system for finding system errors whether the system meets the requirements or not

======================================================================================

In summary
 Improving Result from Backtesting is the development of a system to increase profits or maximum
drawdown.
 This method of reading the Backtest Results is to interpret how the system is built, with
disadvantages, whether it is correct or not, in order to develop the system to meet the desired
future.
 The system analysis has 10 values: [1] Ending capital [2] Net Profit [3] Net Profit% [4] Annual
Return% [5] All trades [6] Max. System% drawdown [7] CAR / MaxDD [8] RAR / MaxDD [9] Risk
Adjusted Return (RAR) [10] Exposure%

======================================================================================

Reading Test Results Backtest Results


 Is the transformation that the system How should it be created? Is there a disadvantage that should
be corrected or not, such as the compensation in the past or if there is inappropriate trading, etc.
 The goal is to develop the system to be in accordance with We want to continue
======================================================================================

(Gambar)
Keywords that are analyzed
How is the system
======================================================================================

Value for money


[1] Ending capital is the final money in our portfolio, which includes capital + profit / loss
======================================================================================

Value for money


[2] Net Profit is the profit of the system that can be made at the test period.

[3] Net Profit% is profit as a percentage when compared to the cost.

[4] Annual Return% is the annual return.

======================================================================================

Value for money


[5] All trades are from all Nakhon Nayok system. At the time of normal testing, the cost is 30-50 times per year.
======================================================================================

Value for money


[6] Max. System% drawdown is the maximum loss of the system (As mentioned in the previous chapter.)

[7] CAR / MDD is the return divided by the percentage divided by MaxDD. The value of water more than 2 would
be good. [CAR (Compound Annual% Return) ]

=======================================
===============================================

Value for money


[8] RAR / MDD is the value of Risk Adjusted Return divided by MaxDD. Values less than 2 would be good.

[9] Risk Adjusted Return (RAR) is the annual return divided by the percentage of impact. To the market
======================================================================================

Value for money


[10] Exposure% is money that remains in stocks

======================================================================================

Added link
 AmiBroker Reading Backtest Report

Potrebbero piacerti anche