That's right! That's right, it's 30 lines of code! Just 30 lines of code, I'm used to looking at the code first, so you can get a macro view!
The policy parameters are:
Parameters | Describe | Types | The default |
---|---|---|---|
FastPeriod | Fast-track cycle | Numbers (number) | 3 |
SlowPeriod | Slow line cycle | Numbers (number) | 7 |
EnterPeriod | Observation period of entry into the market | Numbers (number) | 3 |
ExitFastPeriod | Off-market fast-line cycle | Numbers (number) | 3 |
ExitSlowPeriod | Off-market slow-line cycle | Numbers (number) | 7 |
ExitPeriod | Observation period after discontinuation | Numbers (number) | 1 |
PositionRatio | Proportion of positions | Numbers (number) | 0.8 |
Interval | Round-up period ((seconds)) | Numbers (number) | 10 |
交易类库
It's easy to write a strategy, without having to worry about whether to buy or sell.function main() {
var STATE_IDLE = -1;
var state = STATE_IDLE;
var opAmount = 0;
var initAccount = $.GetAccount();
Log(initAccount);
while (true) {
if (state === STATE_IDLE) {
var n = $.Cross(FastPeriod, SlowPeriod);
if (Math.abs(n) >= EnterPeriod) {
opAmount = parseFloat((initAccount.Stocks * PositionRatio).toFixed(3));
var obj = n > 0 ? $.Buy(opAmount) : $.Sell(opAmount);
if (obj) {
opAmount = obj.amount;
state = n > 0 ? PD_LONG : PD_SHORT;
Log("开仓详情", obj, "交叉周期", n);
}
}
} else {
var n = $.Cross(ExitFastPeriod, ExitSlowPeriod);
if (Math.abs(n) >= ExitPeriod && ((state === PD_LONG && n < 0) || (state === PD_SHORT && n > 0))) {
var obj = state === PD_LONG ? $.Sell(opAmount) : $.Buy(opAmount);
state = STATE_IDLE;
var nowAccount = $.GetAccount();
LogProfit(nowAccount.Balance - initAccount.Balance, '钱:', nowAccount.Balance, '币:', nowAccount.Stocks, '平仓详情:', obj, "交叉周期", n);
}
}
Sleep(Interval*1000);
}
}
Variable declaration
Use the keywordvar
+ variable name, for examplevar name = “小明”
Circulation
while(循环条件){
// 将会重复执行的代码
}
The loop condition is true if the code inside {} is executed repeatedly. The loop condition is false if the loop is skipped.
Conditional Branch
if (判断条件){
// 执行代码
} else {
// 执行代码
}
It's very simple, translated as If (true) {executes this code} its its case {executes this code}
Assignment
One=
The number is the assignment, for example.
name = “张三”;
It's easy to confuse attribution with comparison.
For example,==
The two equals.
Examples“张三”==“李四”
It's clear that Zhang is not Li.“张三”==“李四”
I'm going to fake it.
Related APIs
Before we demonstrate the policy, we'll take a look at the API and template export functions used in the policy, with detailed API documentation and template source code instructions on Inventor Quantification.
The policy code also uses Javascript library functions, object methods, etc.
You can find more information about JavaScript above at: JavaScript Number Objecthttp://www.w3school.com.cn/jsref/jsref_obj_number.aspStudying on the job
The program's flowchart is hand-drawn, without tools, amateurish.
Step by step, build our strategy
All the strategic procedures are at the entrance.main()
A function, i.e. the policy starts from the main function.
The real thing
The simple 30-line strategy is done! Deploy the code to the host robot, and you'll be able to use it to create your own website. The Running! strategy is running, buy the operation.
Thanks to Inventor Quantify for providing such a streamlined code, there are a lot of open source strategies on Inventor Quantification to learn and improve alongside a lot of great ones.
官方QQ群定期更新学习资源,为量化学习者铺平道路,登堂入室。
Supporting video teaching
http://v.youku.com/v_show/id_XMTUyNDY1NjQ2NA==.html
References
FMZ_JHHas the $.GetAccount function in the API been updated to exchange.GetAccount (())?
wojiushizhemedeshuaiqidemeinanziI understand the code, but I don't know exactly what this strategy does.
:)Thank you little dream, your article is very well written.
lrj2uThe owner's tutorial is very well written, thank you!
bincoinThanks to the landlord, I'm going to study hard.
The short-line king won selling the high-price strategyI'm not going to go into detail.
Inventors quantify - small dreams$.GetAccount is the export function of the FMZ template (the template is reusable code, see the description of the template in the API documentation). $.GetAccount is the export function of this template: https://www.fmz.com/strategy/10989. The above strategies are only a part of the code, with no policy parameter set, and the complete strategy can be searched in the Strategy Square in 30 lines.
wojiushizhemedeshuaiqidemeinanziThat's what happened. Thank you very much.
Inventors quantify - small dreamsThere are two straight lines, the slow line on the fast line is usually a buy signal, with a higher probability of upward movement (automatic buy operation); the slow line on the fast line is generally a sell signal, with a higher probability of downward movement (automatic sell operation); by doing this, you can earn a profit in the upward trend of the market.
Inventors quantify - small dreamsThank you for your support, I will be doing more learning material later!
Inventors quantify - small dreamsWe will continue to offer our products later! Thank you for your support.