Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Backtesting
===========================================================================
======================================================================================
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
======================================================================================
======================================================================================
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
======================================================================================
======================================================================================
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
======================================================================================
===========================================================================
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
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
======================================================================================
======================================================================================
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 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
======================================================================================
======================================================================================
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
======================================================================================
======================================================================================
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
===========================================================================
======================================================================================
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
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
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)
======================================================================================
======================================================================================
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
======================================================================================
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
======================================================================================
======================================================================================
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
======================================================================================
=====================================================================================
Added Link
AmiBroker SetPositionSize
AmiBroker Position sizing based on risk
=====================================================================================
======================================================================================
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.
======================================================================================
Meaning
Stock rating via RSI indicator. 100 - RSI means high value
will not be good.
======================================================================================
Added link
AmiBroker PositionScore
=====================================================================================
======================================================================================
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
======================================================================================
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
[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
======================================================================================
ApplyStop: amount
Is the amount that may be a number or an Array variable.
======================================================================================
======================================================================================
======================================================================================
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
======================================================================================
======================================================================================
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
======================================================================================
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
======================================================================================
======================================================================================
Details, improvements
======================================================================================
Added link
AmiBroker Backtesting
AmiBroker Buy Sell Code
AmiBroker ApplyStop
======================================================================================
======================================================================================
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%
======================================================================================
(Gambar)
Keywords that are analyzed
How is the system
======================================================================================
======================================================================================
[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) ]
=======================================
===============================================
[9] Risk Adjusted Return (RAR) is the annual return divided by the percentage of impact. To the market
======================================================================================
======================================================================================
Added link
AmiBroker Reading Backtest Report