-
Notifications
You must be signed in to change notification settings - Fork 0
/
v1.0 Test Log
135 lines (113 loc) · 10.3 KB
/
v1.0 Test Log
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Update!!!
2019-11-07
- This is the first day that the Rolling Position Bot real trading. In this moment, we finished the core trade design: 2019-11-07 做T多仓.
- In this part, we want to do a circulation, which will be triggered while profit rate < -10%, BTC Contract, HuobiDM.
- Now, I will upload the whole trading strategy:
1. Open Position Due to the Indicators
Use MA, RSI, MACD, MFI and others indicator to judge the open position(price), set the trading target, put the order (1).
a). In the longer period judgement, use 10% of balance to set up the position. Maximum amount less than 30% of balance.
b). If in short period judgement, the real price goes in the opposite direction (Profit rate > N or price increased 150-200 ppi, depends on the Long Period Judgement), raise the position 5%.
2. Close Total Position Due to Indicators
Use the indicators to judge the holding position, if the indicator shows the market direction changed, Close Position (2).
a). Stop Lose\ Stop Profit
3. T-Trading Strategy
Use the 做T strategy, will start doing the rolling Open Price when profit rate < 10%. The trading in each time will hold 5% of total hold position amount. (3)
a). Once the profit rate < -10%, 5% of total position will be Closed.
b). Check new_amount, if new_amount != initial amount(Close Position succeeded).
c). Open new position, the amount will same as the amount in Close Position. The price equation: Closed Price * (1+\- r/m). (4)
4. Rolling Stop Profit
a). Once the profit rate > 30%, 20% of total holding position will be Closed.
b). In each 10% increased above 30%, 20 of total holding position will be Closed, until position = 0.
c). If in this situation that after Close 20% of total holding position and the left position amount less than initial amount while the profit rate < 0%, make supplement in same price as the Open Price until the holding position amount = initial amount.
Annotation:
(1). Use the Algorithm to indicate the Open Position
(2). This operation is for close position while the Black Swan.
(3). T-Trading Theory: After the trading strategy judged future market trend, to make the trading before the market.
(4). The Closed Price will suit for Long and Short operation both. In Buy order: P * (1-r/m); In Sell order: P * (1+r/m).
(r = Satisfy percentage of the price gap; m = Margin Level)
中文:
中长趋势判断函数及初始仓位设置
1. 根据MA、RSI、MACD、MFI等指标进行判断中长期趋势,首次开仓保证金10%。最大持仓比例不超过保证金30%。
2. 如达到策略止盈目标,全部平仓
做T函数
1. 做T函数是基于股票做T策略进行修改而来,其理论原理是在短期趋势判断正确的情况下,如亏损超过10%(Profit Rate < -10%),则按持仓5%数量,当前价格,平仓。
2. 在平仓操作后再次获取持仓数,如新持仓数不等于初始持仓数,则判断为交易成功,进行开仓操作,挂单数等于平仓数。
3. 挂单价计算公式:平仓成交价X(1 +/- r/m),加减取决于持仓方向。
4. 再次获取持仓数,如最新持仓数等于初始持仓数,则判断为交易成功。
滚动止盈(补仓)
1. 当盈利率超过30%,平仓总持仓数20%;
2. 当盈利率超过30%,每当收益率继续增加10%,则再次平仓总持仓数20%(最大盈利率80%,最大平仓数5次)
3. 当前持仓数小于初始持仓数,且收益率小于0%时,按开仓均价补仓,补仓操作后持仓数必须等于初始仓位。
# Update!!!
2019-11-09
After tons of problems of the original code, I recognized one seriously BUG, which is we need to sum up the time of the T-Trading due to the FEE!
So that, in the Rolling Stop Profit part, we can not use the constant Profit Rate 30%.
Actually, we need to calculate profit + total Fee which in T-Trading happened, to get the new Stop Point.
Once we finished first round about T-Trading testing, I will start a new round. In this period, I will calculate when the profitrate reached
30%, and to find our the relationship between 30% profit and Fee.
中文:
在过去4天的测试中,策略代码中的反复开单BUG,使我发现现有的策略中有一个严重的漏洞:当行情处于持续亏损阶段,即做T策略进行多次开平仓后,且尚未盈利前,
我们会产生未知数量的手续费。
因此,我们在动态滚仓止盈部分,不能将30%作为固定的止盈目标,我们需要计算心理盈利位之外,还需要加上在次轮操作期间产生的手续费用。
但因为当前我们在做T时,已经将手续费部分加入,所以在当下做T代码初步测试完毕后,下一轮测试将进行手续费计算,并且在达到30%盈利点位时计算利润与手续费关系。
# Update!!!
2019-11-10
Today Dulior edited the code for T-Trading, right now the problem, Repeat trading, has been solved. There has a doubt that when the
market price has a wild fluctuation, what will happen in the strategy?
We can guess that, in the T-Trading strategy 1st vision, we set P as the real time market price, C as the successed close trade price,
X as the price after calculate.
For example, when the profit rate reached < -10% target. The new Close Order will be putted in price C; pretend that the Close Order dealed,
follow the strategy, the new Open Order will be placed in X = C*(1+r/m). Once the P reached price same as X, the Open Order will be dealed.
So in this situation, the bot can open a new Close Order, and set up a new Open Order. This loop will appear when the profit rate < =10%
forever.
In this moment we will get the good result as our expectation.
BUT! If the market has a wild fluctuation, will the strategy finish the job well?
In this case, we need a new test for this doubt.
中文:
今天Dulior修改了做T策略的代码,目前测试情况表明,重复开单的BUG已经修复。但是目前有一个新的可能出现的问题,当市场出现剧烈波动时,策略能否迅速做出反应?
假设在当前版本代码下,P = 实时行价,C = 平仓成交价, X = C*(1+r/m)。 当前行情继续上涨,但如果出现黑天鹅事件(极端行情),实时价格大幅度上涨时,
策略能否良好的进行,我们则需要进一步测试。
举例: P = 9000USD时,实时收益率小于-10%成立,在C = 9050平仓10张,成交后在X= 9063.6挂单,但挂单后P已经大于X很多,交易所是否能够按照交叉成交的方式继续成交,
抑或是不成交,导致机器人无法继续循环操作,我们需要进一步实盘测试!!!
# Update!!!
2019-11-11
In BTC trading, there always has a wild fuctuation like today, in 1 minute decreased/increased more than 1%, the strategy could not
deal successeful. So in this moment, the bot will not continue to loop the new order.
In this case, we can use manual control to make up the strategy, so that, we need to add altinative plan.
Rightnow, I have a preliminary plan: we can set a altinative judgment inside 'if profitrate < -10%', which is 'if the previous operation
did not deal, and market price already over/less than the previous order, put a new Close order, and loop left 'while' judgment.'
# New!
While the previous Open Order did not be dealling, but the profit rate increasing. In this situation, we need to cancle the previous
one, and let the bot re-start the main loop.
# New!
After manual operating, the amount will changed, so if the previous order dealed, the strategy needs to re-calculate the 'iniamount'.
中文:
在BTC交易中,经常出现剧烈价格波动,例如:1分钟内,价格上涨/下跌超过1%,在这个情况下,策略出现无法成交的情况,原因是,在下单之后,价格已远远超过/低于
挂单价格,导致后续循环无法进行。
在此基础上,我有一个初步的替代方案:在'if profitrate < -10%' 函数内,添加附加条件判断,如果previous order没有成交的情况下,市场价格已进一步下跌/上涨,
则替代策略按当前行情执行Close,按照计算公式完成全部循环。
这一替代方案可能出现代码问题,即,iniamount与new_amount判断不准确(主要原因,暂不知是否需要撤销前单),关于这一点需要进一步测试!!!
今日剧烈波动后,当前策略已经进行到Log'开仓已挂单',前单处于较低位置平仓,行情暂无法达到公式计算点位,所以手动撤销挂单,并且手动开多之后,strategy成功
读取到最新持仓,完成了loop,进行了新操作。
假设,因为价格剧烈波动,bot无法完成平仓操作,此时也无法走出while iniamount != new_amount,关于这一点,需要进一步测试!!!
# New!
当前一次策略运行后,挂单尚未成交,但收益率已高于-10%,此时需要撤销挂单,重新循环main.
# New!
人工做单之后,如前挂单成交,则策略需要重新计算iniamount
# Update!!!
2019-11-14
Timeout of the connection!
机器人出现断开连接,需要重启!
# Update!!! 2019-11-19
There are many bugs in the strategy! Not in the code, it's in the strategy!!!
First, the strategy need to consider the market price changing too fast, the bot can't finish the operation on time, so the strategy
need to have a altinative plan as I said in the before.
Second, ADD NEW strategy, while the older order did not successed, but the profit rate resume to 0%, need to place new buy or close to
get the same iniamount.
Third, the code need to change in the judgment part, the amount of the position is not clearly, so we need to use exchange.GetOrder
to do a better judgment for the bot.
中文
策略有许多BUG,注意!不是代码,是策略需要改进!!!
首先,我们需要考虑当黑天鹅事件出现(价格变动速度大于机器人处理速度),此时我们需要判断是否跳过前一订单重新平/开仓!
第二,策略需要添加一条新指令:当最后一次平仓成功,但挂单未成交,此时市场价格已经上涨/下跌,使profit rate上升到0%,此时需要补齐为成交数量仓位。
第三,代码需要修改判断条件,Position数量判断不准确,出现成交数量有误,此条需要进一步检测是否错误率过高!