Name
大中小三周期跃迁策略V20_现货_测试
Author
区班量化
Strategy Description
大中小三周期跃迁策略。总的来说,就是大周期指明了市场方向,中周期是当前的操作周期,小周期指出了趋势止步信号。当你进场时,只要你参看了大中小三周期的状态,就可如诸葛亮一般,采取千变万化的策略来应付复杂的市场。如果你的操作周期频率是一天几次,那大周期可以选择日线,中周期可以选择4小时,小周期可以选择30分钟;如果你的操作周期频率是一天几十次,那大周期可以选择4小时,中周期可以选择30分钟,小周期可以选择5分钟;上一个周期始终和下一个周期相差6倍到8倍。
然后我们再把每个周期的K线与布林线的关系罗列出来,一共有8种状态,三个周期就有888=512种状态,这512种状态足以应付所有可能出现的盘面,技术能力强的程序员可以把每一种状态的最佳下单点位和止损点位预先设计出来。为了大家有一个讨论的基础,区班主也在发明者平台把策略公开了,欢迎大家在此基础上进行完善。
然后我们来回测一下,我们可以看到年化29,回撤有点高,达到36%。我们把日志下载下来,并针对回撤进行分析,这就是发明者平台的优势。
分析下来,主要有以下几个原因:
1、大中小周期架构虽然比较好,但是小周期对中周期怎样影响的策略不好构思,可以先简化,后面再补上;
2、行情走空时,应该坚决抛弃仓位
3、5日均线的指向作用很重要,在策略里没有体现
4、布林线之外的快速下跌,应该抛售
5、上涨理由跌破时,应该及时止盈和止损
经过有针对性的改进后,迭代了几十次,我们终于把年化率做到了210,回撤为16.4,交易次数也降了下来。
Strategy Arguments
Argument | Default | Description |
---|---|---|
Interval | 10 | 轮询周期(秒) |
Source (javascript)
/*backtest
start: 2019-01-01 00:00:00
end: 2019-10-10 00:00:00
period: 1d
exchanges: [{"eid":"OKEX","currency":"ETH_USDT","stocks":0}]
args: [["OpMode",1,10989],["MaxAmount",1,10989],["TradeFee",0.001,10989]]
*/
//注册币乎后https://m.bihu.com/signup?i=1ewtKO&s=4&c=4
//搜索 物联网区块链 可以联系到作者区班主 你也可以给我写邮件[email protected]
var midStatus = 0; //中周期状态
var bigStatus = 0; //大周期状态
var beforeBigStatus = 0; //之前大周期状态
var operPrice;
var markTime=0;
function mySell(rate){
var account = _C(exchange.GetAccount);
var ticker = _C(exchange.GetTicker);
var nowPrice=ticker.Sell;
//以下开始卖出
var allAmount=account.Balance+account.Stocks*ticker.Sell; //计算出总金额
var cashRatio=account.Balance*100/allAmount;
if(cashRatio<90){ //现金比率小于10,才可以卖出
if(rate==1){ //卖出1份
if(cashRatio<80){
$.Sell(allAmount*0.1/nowPrice);
Log("现金比率",cashRatio+10);
}else{
$.Sell(allAmount*0.05/nowPrice);
Log("现金比率",cashRatio+5);
}
}else{
if(cashRatio<75){
$.Sell(allAmount*0.2/nowPrice);
Log("现金比率",cashRatio+20);
}else{
$.Sell(allAmount*0.1/nowPrice);
Log("现金比率",cashRatio+10);
}
}
}
}
function myBuy(rate){
var account = _C(exchange.GetAccount);
var ticker = _C(exchange.GetTicker);
var nowPrice=ticker.Sell;
//以下开始买入
var allAmount=account.Balance+account.Stocks*ticker.Sell; //计算出总金额
var cashRatio=account.Balance*100/allAmount;
//Log("需要买入比率",rate);
if(cashRatio>10){ //现金比率大于10,才可以买入
if(rate==1){ //买入1份
if(cashRatio>20){
$.Buy(allAmount*0.1/nowPrice);
Log("现金比率",cashRatio-10);
}else{
$.Buy(allAmount*0.05/nowPrice);
Log("现金比率",cashRatio-5);
}
}else{
if(cashRatio>25){
$.Buy(allAmount*0.2/nowPrice);
Log("现金比率",cashRatio-20);
}else{
$.Buy(allAmount*0.1/nowPrice);
Log("现金比率",cashRatio-10);
}
}
}
}
function oper(){
var ticker = _C(exchange.GetTicker);
var nowPrice=ticker.Sell;
var h1records = exchange.GetRecords(PERIOD_H1);
var h1boll;var h1upLine;var h1midLine;var h1downLine;
var h1bw;
if(h1records && h1records.length > 20) {
h1boll = TA.BOLL(h1records, 20, 2);
h1upLine = h1boll[0][h1records.length-1];
h1midLine = h1boll[1][h1records.length-1];
h1downLine = h1boll[2][h1records.length-1];
}
var drecords = exchange.GetRecords(PERIOD_D1);
var dboll;var dupLine;var dmidLine;var ddownLine;
var dbw;var beforePrice;
if(drecords && drecords.length > 20) {
dboll = TA.BOLL(drecords, 20, 2);
dupLine = dboll[0][drecords.length-1];
dmidLine = dboll[1][drecords.length-1];
ddownLine = dboll[2][drecords.length-1];
dbw=dupLine-dmidLine;
beforePrice=(drecords[drecords.length-2].Open+drecords[drecords.length-2].Close)/2;
}
if(ticker.Time-markTime<15*60*1000){ //只有满足15分钟间隔,才允许判断状态
return;
}else{
markTime=ticker.Time;
}
if(h1records && h1records.length > 20 && drecords && drecords.length > 20) {
if(nowPrice>dupLine+dbw*0.1){
bigStatus=0;
}else if(nowPrice>dupLine-dbw*0.1){
bigStatus=1;
}else if(nowPrice>dmidLine+dbw*0.1){
bigStatus=2;
}else if(nowPrice>dmidLine){
bigStatus=3;
}else if(nowPrice>dmidLine-dbw*0.1){
bigStatus=4;
}else if(nowPrice>ddownLine+dbw*0.1){
bigStatus=5;
}else if(nowPrice>ddownLine-dbw*0.1){
bigStatus=6;
}else{
bigStatus=7;
}
if(beforePrice>dupLine+dbw*0.1){
beforeBigStatus=0;
}else if(beforePrice>dupLine-dbw*0.1){
beforeBigStatus=1;
}else if(beforePrice>dmidLine+dbw*0.1){
beforeBigStatus=2;
}else if(beforePrice>dmidLine){
beforeBigStatus=3;
}else if(beforePrice>dmidLine-dbw*0.1){
beforeBigStatus=4;
}else if(beforePrice>ddownLine+dbw*0.1){
beforeBigStatus=5;
}else if(beforePrice>ddownLine-dbw*0.1){
beforeBigStatus=6;
}else{
beforeBigStatus=7;
}
if(nowPrice>h1upLine+h1bw*0.1){
midStatus=0;
}else if(nowPrice>h1upLine-h1bw*0.1){
midStatus=1;
}else if(nowPrice>h1midLine+h1bw*0.1){
midStatus=2;
}else if(nowPrice>h1midLine){
midStatus=3;
}else if(nowPrice>h1midLine-h1bw*0.1){
midStatus=4;
}else if(nowPrice>h1downLine+h1bw*0.1){
midStatus=5;
}else if(nowPrice>h1downLine-h1bw*0.1){
midStatus=6;
}else{
midStatus=7;
}
if(bigStatus-beforeBigStatus>0){ //当前有一个大周期下跌跃迁
if(midStatus==6||midStatus==7){
//Log("卖2份 当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
//买2份
mySell(2);
}else if(midStatus==3||midStatus==4){
//Log("卖1份 当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
//买1份
mySell(1);
}else{
//Log("当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
}
}else if(bigStatus-beforeBigStatus<0){ //当前有一个大周期上涨跃迁
if(midStatus==6||midStatus==7){
//Log("买2份 当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
//买2份
myBuy(2);
}else if(midStatus==3||midStatus==4){
//Log("买1份 当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
//买1份
myBuy(1);
}else{
//Log("当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
}
}else{
//Log("当大",bigStatus,"前大",beforeBigStatus,"中",midStatus," dup",dupLine," 长度",dboll[0].length);
}
}
}
function main() {
var initAccount = _C(exchange.GetAccount);
Log(initAccount);
exchange.SetCurrency("LTC_USDT")
Log("BTC_USDT的计价币名称:", exchange.GetQuoteCurrency())
while (true) {
oper();
Sleep(Interval*1000);
}
}
Detail
https://www.fmz.com/strategy/177631
Last Modified
2024-01-28 18:15:48