This commit is contained in:
Zero
2018-12-23 21:00:42 +08:00
parent d9c3182152
commit 9a4ff483a3
38 changed files with 2421 additions and 850 deletions
+649
View File
@@ -0,0 +1,649 @@
> 策略名称
CTP 期货
> 策略作者
tyz
> 策略描述
- 只支持操作CTP商品期货
- 支持自动或手动恢复进度
- 可同时操作多个不同品种
- 增加时间段区分与各种网络错误问题的应对处理
- 移仓功能目前正在加入中
请下载最新托管者并比较版本号是否最新
``` text
$ ./robot -v
BotVS docker 3.0 compiled at 2016-07-05T09:56:18+0800
```
https://dn-filebox.qbox.me/d33687abb648c489b6883296685e8717ea3f44ca.png
> 策略参数
|参数|默认值|描述|
|----|----|----|
|Instruments|MA701,CF701,zn1701,SR701,pp1701,l1701,hc1610,ni1701,i1701,v1701,rb1610,jm1701,ag1612,al1701,jd1701,cs1701,p1701|合约列表|
|LoopInterval|3|轮询周期(秒)|
|RiskRatio|true|% Risk Per N ( 0 - 100)|
|ATRLength|20|ATR计算周期|
|EnterPeriodA|20|系统一入市周期|
|LeavePeriodA|10|系统一离市周期|
|EnterPeriodB|55|系统二入市周期|
|LeavePeriodB|20|系统二离市周期|
|UseEnterFilter|true|使用入市过滤|
|IncSpace|0.5|加仓间隔(N的倍数)|
|StopLossRatio|2|止损系数(N的倍数)|
|MaxLots|4|单品种加仓次数|
|RMode|0|进度恢复模式: 自动|手动|
|VMStatus|{}|手动恢复字符串|
|WXPush|true|推送交易信息|
|MaxTaskRetry|5|开仓最多重试次数|
|KeepRatio|10|预留保证金比例|
|按钮|默认值|描述|
|----|----|----|
|暂停/继续|__button__|暂停/继续|
> 源码 (javascript)
``` javascript
/*backtest
start: 2016-03-01 00:00:00
end: 2016-12-30 00:00:00
period: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/
var _bot = $.NewPositionManager();
var TTManager = {
New: function(needRestore, symbol, keepBalance, riskRatio, atrLen, enterPeriodA, leavePeriodA, enterPeriodB, leavePeriodB, useFilter,
multiplierN, multiplierS, maxLots) {
// subscribe
var symbolDetail = _C(exchange.SetContractType, symbol);
if (symbolDetail.VolumeMultiple == 0 || symbolDetail.MaxLimitOrderVolume == 0 || symbolDetail.MinLimitOrderVolume == 0 || symbolDetail.LongMarginRatio == 0 || symbolDetail.ShortMarginRatio == 0) {
Log(symbolDetail);
throw "合约信息异常";
} else {
Log("合约", symbolDetail.InstrumentName, "一手", symbolDetail.VolumeMultiple, "份, 最大下单量", symbolDetail.MaxLimitOrderVolume, "保证金率:", _N(symbolDetail.LongMarginRatio), _N(symbolDetail.ShortMarginRatio), "交割日期", symbolDetail.StartDelivDate);
}
var ACT_IDLE = 0;
var ACT_LONG = 1;
var ACT_SHORT = 2;
var ACT_COVER = 3;
var ERR_SUCCESS = 0;
var ERR_SET_SYMBOL = 1;
var ERR_GET_ORDERS = 2;
var ERR_GET_POS = 3;
var ERR_TRADE = 4;
var ERR_GET_DEPTH = 5;
var ERR_NOT_TRADING = 6;
var errMsg = ["成功", "切换合约失败", "获取订单失败", "获取持仓失败", "交易下单失败", "获取深度失败", "不在交易时间"];
var obj = {
symbol: symbol,
keepBalance: keepBalance,
riskRatio: riskRatio,
atrLen: atrLen,
enterPeriodA: enterPeriodA,
leavePeriodA: leavePeriodA,
enterPeriodB: enterPeriodB,
leavePeriodB: leavePeriodB,
useFilter: useFilter,
multiplierN: multiplierN,
multiplierS: multiplierS
};
obj.task = {
action: ACT_IDLE,
amount: 0,
dealAmount: 0,
avgPrice: 0,
preCost: 0,
preAmount: 0,
init: false,
retry: 0,
desc: "空闲",
onFinish: null
}
obj.maxLots = maxLots;
obj.lastPrice = 0;
obj.symbolDetail = symbolDetail;
obj.status = {
symbol: symbol,
recordsLen: 0,
vm: [],
open: 0,
cover: 0,
st: 0,
marketPosition: 0,
lastPrice: 0,
holdPrice: 0,
holdAmount: 0,
holdProfit: 0,
N: 0,
upLine: 0,
downLine: 0,
symbolDetail: symbolDetail,
lastErr: "",
lastErrTime: "",
stopPrice: '',
leavePrice: '',
isTrading: false
};
obj.setLastError = function(err) {
if (typeof(err) === 'undefined' || err === '') {
obj.status.lastErr = "";
obj.status.lastErrTime = "";
return;
}
var t = new Date();
obj.status.lastErr = err;
obj.status.lastErrTime = t.toLocaleString();
};
obj.reset = function(marketPosition, openPrice, N, leavePeriod, preBreakoutFailure) {
if (typeof(marketPosition) !== 'undefined') {
obj.marketPosition = marketPosition;
obj.openPrice = openPrice;
obj.preBreakoutFailure = preBreakoutFailure;
obj.N = N;
obj.leavePeriod = leavePeriod;
var pos = _bot.GetPosition(obj.symbol, marketPosition > 0 ? PD_LONG : PD_SHORT);
if (pos) {
obj.holdPrice = pos.Price;
obj.holdAmount = pos.Amount;
Log(obj.symbol, "仓位", pos);
} else {
throw "恢复" + obj.symbol + "的持仓状态出错, 没有找到仓位信息";
}
Log("恢复", obj.symbol, "加仓次数", obj.marketPosition, "持仓均价:", obj.holdPrice, "持仓数量:", obj.holdAmount, "最后一次加仓价", obj.openPrice, "N值", obj.N, "离市周期:", leavePeriod, "上次突破:", obj.preBreakoutFailure ? "失败" : "成功");
obj.status.open = 1;
obj.status.vm = [obj.marketPosition, obj.openPrice, obj.N, obj.leavePeriod, obj.preBreakoutFailure];
} else {
obj.marketPosition = 0;
obj.holdPrice = 0;
obj.openPrice = 0;
obj.holdAmount = 0;
obj.holdProfit = 0;
obj.preBreakoutFailure = true; // test system A
obj.N = 0;
obj.leavePeriod = leavePeriodA;
}
obj.holdProfit = 0;
obj.lastErr = "";
obj.lastErrTime = "";
};
obj.Status = function() {
obj.status.N = obj.N;
obj.status.marketPosition = obj.marketPosition;
obj.status.holdPrice = obj.holdPrice;
obj.status.holdAmount = obj.holdAmount;
obj.status.lastPrice = obj.lastPrice;
if (obj.lastPrice > 0 && obj.holdAmount > 0 && obj.marketPosition !== 0) {
obj.status.holdProfit = _N((obj.lastPrice - obj.holdPrice) * obj.holdAmount * symbolDetail.VolumeMultiple, 4) * (obj.marketPosition > 0 ? 1 : -1);
} else {
obj.status.holdProfit = 0;
}
return obj.status;
};
obj.setTask = function(action, amount, onFinish) {
obj.task.init = false;
obj.task.retry = 0;
obj.task.action = action;
obj.task.preAmount = 0;
obj.task.preCost = 0;
obj.task.amount = typeof(amount) === 'number' ? amount : 0;
obj.task.onFinish = onFinish;
if (action == ACT_IDLE) {
obj.task.desc = "空闲";
obj.task.onFinish = null;
} else {
if (action !== ACT_COVER) {
obj.task.desc = (action == ACT_LONG ? "加多仓" : "加空仓") + "(" + amount + ")";
} else {
obj.task.desc = "平仓";
}
Log("接收到任务", obj.symbol, obj.task.desc);
// process immediately
obj.Poll(true);
}
};
obj.processTask = function() {
var insDetail = exchange.SetContractType(obj.symbol);
if (!insDetail) {
return ERR_SET_SYMBOL;
}
var SlideTick = 1;
var ret = false;
if (obj.task.action == ACT_COVER) {
var hasPosition = false;
do {
if (!$.IsTrading(obj.symbol)) {
return ERR_NOT_TRADING;
}
hasPosition = false;
var positions = exchange.GetPosition();
if (!positions) {
return ERR_GET_POS;
}
var depth = exchange.GetDepth();
if (!depth) {
return ERR_GET_DEPTH;
}
var orderId = null;
for (var i = 0; i < positions.length; i++) {
if (positions[i].ContractType !== obj.symbol) {
continue;
}
var amount = Math.min(insDetail.MaxLimitOrderVolume, positions[i].Amount);
if (positions[i].Type == PD_LONG || positions[i].Type == PD_LONG_YD) {
exchange.SetDirection(positions[i].Type == PD_LONG ? "closebuy_today" : "closebuy");
orderId = exchange.Sell(_N(depth.Bids[0].Price - (insDetail.PriceTick * SlideTick), 2), Math.min(amount, depth.Bids[0].Amount), obj.symbol, positions[i].Type == PD_LONG ? "平今" : "平昨", 'Bid', depth.Bids[0]);
hasPosition = true;
} else if (positions[i].Type == PD_SHORT || positions[i].Type == PD_SHORT_YD) {
exchange.SetDirection(positions[i].Type == PD_SHORT ? "closesell_today" : "closesell");
orderId = exchange.Buy(_N(depth.Asks[0].Price + (insDetail.PriceTick * SlideTick), 2), Math.min(amount, depth.Asks[0].Amount), obj.symbol, positions[i].Type == PD_SHORT ? "平今" : "平昨", 'Ask', depth.Asks[0]);
hasPosition = true;
}
}
if (hasPosition) {
if (!orderId) {
return ERR_TRADE;
}
Sleep(1000);
while (true) {
// Wait order, not retry
var orders = exchange.GetOrders();
if (!orders) {
return ERR_GET_ORDERS;
}
if (orders.length == 0) {
break;
}
for (var i = 0; i < orders.length; i++) {
exchange.CancelOrder(orders[i].Id);
Sleep(500);
}
}
}
} while (hasPosition);
ret = true;
} else if (obj.task.action == ACT_LONG || obj.task.action == ACT_SHORT) {
do {
if (!$.IsTrading(obj.symbol)) {
return ERR_NOT_TRADING;
}
Sleep(1000);
while (true) {
// Wait order, not retry
var orders = exchange.GetOrders();
if (!orders) {
return ERR_GET_ORDERS;
}
if (orders.length == 0) {
break;
}
for (var i = 0; i < orders.length; i++) {
exchange.CancelOrder(orders[i].Id);
Sleep(500);
}
}
var positions = exchange.GetPosition();
// Error
if (!positions) {
return ERR_GET_POS;
}
// search position
var pos = null;
for (var i = 0; i < positions.length; i++) {
if (positions[i].ContractType == obj.symbol && (((positions[i].Type == PD_LONG || positions[i].Type == PD_LONG_YD) && obj.task.action == ACT_LONG) || ((positions[i].Type == PD_SHORT || positions[i].Type == PD_SHORT_YD) && obj.task.action == ACT_SHORT))) {
if (!pos) {
pos = positions[i];
pos.Cost = positions[i].Price * positions[i].Amount;
} else {
pos.Amount += positions[i].Amount;
pos.Profit += positions[i].Profit;
pos.Cost += positions[i].Price * positions[i].Amount;
}
}
}
// record pre position
if (!obj.task.init) {
obj.task.init = true;
if (pos) {
obj.task.preAmount = pos.Amount;
obj.task.preCost = pos.Cost;
} else {
obj.task.preAmount = 0;
obj.task.preCost = 0;
}
}
var remain = obj.task.amount;
if (pos) {
obj.task.dealAmount = pos.Amount - obj.task.preAmount;
remain = parseInt(obj.task.amount - obj.task.dealAmount);
if (remain <= 0 || obj.task.retry >= MaxTaskRetry) {
ret = {
price: (pos.Cost - obj.task.preCost) / (pos.Amount - obj.task.preAmount),
amount: (pos.Amount - obj.task.preAmount),
position: pos
};
break;
}
} else if (obj.task.retry >= MaxTaskRetry) {
ret = null;
break;
}
var depth = exchange.GetDepth();
if (!depth) {
return ERR_GET_DEPTH;
}
var orderId = null;
if (obj.task.action == ACT_LONG) {
exchange.SetDirection("buy");
orderId = exchange.Buy(_N(depth.Asks[0].Price + (insDetail.PriceTick * SlideTick), 2), Math.min(remain, depth.Asks[0].Amount), obj.symbol, 'Ask', depth.Asks[0]);
} else {
exchange.SetDirection("sell");
orderId = exchange.Sell(_N(depth.Bids[0].Price - (insDetail.PriceTick * SlideTick), 2), Math.min(remain, depth.Bids[0].Amount), obj.symbol, 'Bid', depth.Bids[0]);
}
// symbol not in trading or other else happend
if (!orderId) {
obj.task.retry++;
return ERR_TRADE;
}
} while (true);
}
if (obj.task.onFinish) {
obj.task.onFinish(ret);
}
obj.setTask(ACT_IDLE);
return ERR_SUCCESS;
};
obj.Poll = function(subroutine) {
obj.status.isTrading = $.IsTrading(obj.symbol);
if (!obj.status.isTrading) {
return;
}
if (obj.task.action != ACT_IDLE) {
var retCode = obj.processTask();
if (obj.task.action != ACT_IDLE) {
obj.setLastError("任务没有处理成功: " + errMsg[retCode] + ", " + obj.task.desc + ", 重试: " + obj.task.retry);
} else {
obj.setLastError();
}
return;
}
if (typeof(subroutine) !== 'undefined' && subroutine) {
return;
}
// Loop
var suffix = WXPush ? '@' : '';
// switch symbol
_C(exchange.SetContractType, obj.symbol);
var records = exchange.GetRecords();
if (!records) {
obj.setLastError("获取K线失败");
return;
}
obj.status.recordsLen = records.length;
if (records.length < obj.atrLen) {
obj.setLastError("K线长度小于 " + obj.atrLen);
return;
}
var opCode = 0; // 0: IDLE, 1: LONG, 2: SHORT, 3: CoverALL
var lastPrice = records[records.length - 1].Close;
obj.lastPrice = lastPrice;
if (obj.marketPosition === 0) {
obj.status.stopPrice = '--';
obj.status.leavePrice = '--';
obj.status.upLine = 0;
obj.status.downLine = 0;
for (var i = 0; i < 2; i++) {
if (i == 0 && obj.useFilter && !obj.preBreakoutFailure) {
continue;
}
var enterPeriod = i == 0 ? obj.enterPeriodA : obj.enterPeriodB;
if (records.length < (enterPeriod + 1)) {
continue;
}
var highest = TA.Highest(records, enterPeriod, 'High');
var lowest = TA.Lowest(records, enterPeriod, 'Low');
obj.status.upLine = obj.status.upLine == 0 ? highest : Math.min(obj.status.upLine, highest);
obj.status.downLine = obj.status.downLine == 0 ? lowest : Math.max(obj.status.downLine, lowest);
if (lastPrice > highest) {
opCode = 1;
} else if (lastPrice < lowest) {
opCode = 2;
}
if (opCode != 0) {
obj.leavePeriod = (enterPeriod == obj.enterPeriodA) ? obj.leavePeriodA : obj.leavePeriodB;
break;
}
}
} else {
var spread = obj.marketPosition > 0 ? (obj.openPrice - lastPrice) : (lastPrice - obj.openPrice);
obj.status.stopPrice = _N(obj.openPrice + (obj.N * StopLossRatio * (obj.marketPosition > 0 ? -1 : 1)));
if (spread > (obj.N * StopLossRatio)) {
opCode = 3;
obj.preBreakoutFailure = true;
Log(obj.symbolDetail.InstrumentName, "止损平仓", suffix);
obj.status.st++;
} else if (-spread > (IncSpace * obj.N)) {
opCode = obj.marketPosition > 0 ? 1 : 2;
}
if (opCode == 0 && records.length > obj.leavePeriod) {
obj.status.leavePrice = obj.marketPosition > 0 ? TA.Lowest(records, obj.leavePeriod, 'Low') : TA.Highest(records, obj.leavePeriod, 'High');
if ((obj.marketPosition > 0 && lastPrice < obj.status.leavePrice) ||
(obj.marketPosition < 0 && lastPrice > obj.status.leavePrice)) {
obj.preBreakoutFailure = false;
Log(obj.symbolDetail.InstrumentName, "正常平仓", suffix);
opCode = 3;
obj.status.cover++;
}
}
}
if (opCode == 0) {
return;
}
if (opCode == 3) {
obj.setTask(ACT_COVER, 0, function(ret) {
obj.reset();
_G(obj.symbol, null);
});
return;
}
// Open
if (Math.abs(obj.marketPosition) >= obj.maxLots) {
obj.setLastError("禁止开仓, 超过最大持仓 " + obj.maxLots);
return;
}
var atrs = TA.ATR(records, atrLen);
var N = _N(atrs[atrs.length - 1], 4);
var account = _bot.GetAccount();
var currMargin = JSON.parse(exchange.GetRawJSON()).CurrMargin;
var unit = parseInt((account.Balance+currMargin-obj.keepBalance) * (obj.riskRatio / 100) / N / obj.symbolDetail.VolumeMultiple);
var canOpen = parseInt((account.Balance-obj.keepBalance) / (opCode == 1 ? obj.symbolDetail.LongMarginRatio : obj.symbolDetail.ShortMarginRatio) / (lastPrice * 1.2) / obj.symbolDetail.VolumeMultiple);
unit = Math.min(unit, canOpen);
if (unit < obj.symbolDetail.MinLimitOrderVolume) {
obj.setLastError("可开 " + unit + " 手 无法开仓, " + (canOpen >= obj.symbolDetail.MinLimitOrderVolume ? "风控触发" : "资金限制"));
return;
}
obj.setTask((opCode == 1 ? ACT_LONG : ACT_SHORT), unit, function(ret) {
if (!ret) {
obj.setLastError("下单失败");
return;
}
Log(obj.symbolDetail.InstrumentName, obj.marketPosition == 0 ? "开仓" : "加仓", "离市周期", obj.leavePeriod, suffix);
obj.N = N;
obj.openPrice = ret.price;
obj.holdPrice = ret.position.Price;
if (obj.marketPosition == 0) {
obj.status.open++;
}
obj.holdAmount = ret.position.Amount;
obj.marketPosition += opCode == 1 ? 1 : -1;
obj.status.vm = [obj.marketPosition, obj.openPrice, N, obj.leavePeriod, obj.preBreakoutFailure];
_G(obj.symbol, obj.status.vm);
});
};
var vm = null;
if (RMode === 0) {
vm = _G(obj.symbol);
} else {
vm = JSON.parse(VMStatus)[obj.symbol];
}
if (vm) {
Log("准备恢复进度, 当前合约状态为", vm);
obj.reset(vm[0], vm[1], vm[2], vm[3], vm[4]);
} else {
if (needRestore) {
Log("没有找到" + obj.symbol + "的进度恢复信息");
}
obj.reset();
}
return obj;
}
};
function onexit() {
Log("已退出策略...");
}
function main() {
if (exchange.GetName().indexOf('CTP') == -1) {
throw "只支持商品期货CTP";
}
SetErrorFilter("login|ready|流控|连接失败|初始|Timeout");
var mode = exchange.IO("mode", 0);
if (typeof(mode) !== 'number') {
throw "切换模式失败, 请更新到最新托管者!";
}
while (!exchange.IO("status")) {
Sleep(3000);
LogStatus("正在等待与交易服务器连接, " + new Date());
}
var positions = _C(exchange.GetPosition);
if (positions.length > 0) {
Log("检测到当前持有仓位, 系统将开始尝试恢复进度...");
Log("持仓信息", positions);
}
Log("风险系数:", RiskRatio, "N值周期:", ATRLength, "系统1: 入市周期", EnterPeriodA, "离市周期", LeavePeriodA, "系统二: 入市周期", EnterPeriodB, "离市周期", LeavePeriodB, "加仓系数:", IncSpace, "止损系数:", StopLossRatio, "单品种最多开仓:", MaxLots, "次");
var initAccount = _bot.GetAccount();
var initMargin = JSON.parse(exchange.GetRawJSON()).CurrMargin;
var keepBalance = _N((initAccount.Balance + initMargin) * (KeepRatio/100), 3);
Log("资产信息", initAccount, "保留资金:", keepBalance);
var tts = [];
var filter = [];
var arr = Instruments.split(',');
for (var i = 0; i < arr.length; i++) {
var symbol = arr[i].replace(/^\s+/g, "").replace(/\s+$/g, "");
if (typeof(filter[symbol]) !== 'undefined') {
Log(symbol, "已经存在, 系统已自动过滤");
continue;
}
filter[symbol] = true;
var hasPosition = false;
for (var j = 0; j < positions.length; j++) {
if (positions[j].ContractType == symbol) {
hasPosition = true;
break;
}
}
var obj = TTManager.New(hasPosition, symbol, keepBalance, RiskRatio, ATRLength, EnterPeriodA, LeavePeriodA, EnterPeriodB, LeavePeriodB, UseEnterFilter, IncSpace, StopLossRatio, MaxLots);
tts.push(obj);
}
var preTotalHold = -1;
var lastStatus = '';
while (true) {
if (GetCommand() === "暂停/继续") {
Log("暂停交易中...");
while (GetCommand() !== "暂停/继续") {
Sleep(1000);
}
Log("继续交易中...");
}
while (!exchange.IO("status")) {
Sleep(3000);
LogStatus("正在等待与交易服务器连接, " + new Date() + "\n" + lastStatus);
}
var tblStatus = {
type: "table",
title: "持仓信息",
cols: ["合约名称", "持仓方向", "持仓均价", "持仓数量", "持仓盈亏", "加仓次数", "开仓次数", "止损次数", "成功次数", "当前价格", "N"],
rows: []
};
var tblMarket = {
type: "table",
title: "运行状态",
cols: ["合约名称", "合约乘数", "保证金率", "交易时间", "柱线长度", "上线", "下线", "止损价", "离市价", "异常描述", "发生时间"],
rows: []
};
var totalHold = 0;
var vmStatus = {};
var ts = new Date().getTime();
var holdSymbol = 0;
for (var i = 0; i < tts.length; i++) {
tts[i].Poll();
var d = tts[i].Status();
if (d.holdAmount > 0) {
vmStatus[d.symbol] = d.vm;
holdSymbol++;
}
tblStatus.rows.push([d.symbolDetail.InstrumentName, d.holdAmount == 0 ? '--' : (d.marketPosition > 0 ? '多' : '空'), d.holdPrice, d.holdAmount, d.holdProfit, Math.abs(d.marketPosition), d.open, d.st, d.cover, d.lastPrice, d.N]);
tblMarket.rows.push([d.symbolDetail.InstrumentName, d.symbolDetail.VolumeMultiple, _N(d.symbolDetail.LongMarginRatio, 4) + '/' + _N(d.symbolDetail.ShortMarginRatio, 4), (d.isTrading ? '是#0000ff' : '否#ff0000'), d.recordsLen, d.upLine, d.downLine, d.stopPrice, d.leavePrice, d.lastErr, d.lastErrTime]);
totalHold += Math.abs(d.holdAmount);
}
var now = new Date();
var elapsed = now.getTime() - ts;
var tblAssets = _bot.GetAccount(true);
var nowAccount = _bot.Account();
if (tblAssets.rows.length > 10) {
// replace AccountId
tblAssets.rows[0] = ["InitAccount", "初始资产", initAccount];
} else {
tblAssets.rows.unshift(["NowAccount", "当前可用", nowAccount], ["InitAccount", "初始资产", initAccount]);
}
lastStatus = '`' + JSON.stringify([tblStatus, tblMarket, tblAssets]) + '`\n轮询耗时: ' + elapsed + ' 毫秒, 当前时间: ' + now.toLocaleString() + ', 星期' + ['日', '一', '二', '三', '四', '五', '六'][now.getDay()] + ", 持有品种个数: " + holdSymbol;
if (totalHold > 0) {
lastStatus += "\n手动恢复字符串: " + JSON.stringify(vmStatus);
}
LogStatus(lastStatus);
if (preTotalHold > 0 && totalHold == 0) {
LogProfit(nowAccount.Balance - initAccount.Balance - initMargin);
}
preTotalHold = totalHold;
Sleep(LoopInterval * 1000);
}
}
```
> 策略出处
https://www.fmz.com/strategy/130234
> 更新时间
2018-12-14 12:31:22
@@ -1,7 +1,7 @@
> 策略名称
Dual Thrust (麦语言版)
Dual Thrust (麦语言版)|Dual Thrust (MyLanguage version)
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
> 基本原理
- 在当天收盘,计算两个值: 最高价-收盘价,和收盘价-最低价。然后取这两个值较大的那个,乘以k值,结果称为触发值。
@@ -31,15 +32,35 @@ littleDreamXX
- 副图:
无
||
- Fundamental:
At the close of the day, two values are calculated: the highest price - the closing price, and the closing price - the lowest price. Then take the larger one and multiply it by the value of k. The result is called the trigger value.
At the opening of the next day, record the opening price, then buy immediately when the price exceeds (opening price + trigger value), or sell short when the price is lower than (opening price - trigger value).
This system is a reversal system with no separate stop loss. In other words, the reverse signal is also the closing signal.
![IMG](https://www.fmz.com/upload/asset/d2d373289db613f356811d9314775b83.jpg)
![IMG](https://www.fmz.com/upload/asset/c6c5a6c53fa4f0c9c5971df9349e1dca.png)
![IMG](https://www.fmz.com/upload/asset/65fd01ff1e7b844006ba18ad0ea3dedf.png)
- Main chart:
Upper track: formula: UPTRACK^^O+KSRG;
Lower track: formula: DOWNTRACK^^O-KXRG;
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N|4|计算周期|
|KS|0.5|上轨系数|
|KX|0.5|下轨系数|
|N|4|计算周期|Period: calculate period|
|KS|0.5|上轨系数|upper track coefficient|
|KX|0.5|下轨系数|lower track coefficient|
> 源码 (麦语言)
@@ -62,10 +83,10 @@ RG:=MAX(HH-LC,HC-LL);
UPTRACK^^O+KS*RG;
DOWNTRACK^^O-KX*RG;
// 交易信号
C>UPTRACK,BPK;
C<DOWNTRACK,SPK;
// 嵌入的JS 代码调整至 手册,有兴趣 可以研究。
```
> 策略出处
@@ -74,4 +95,4 @@ https://www.fmz.com/strategy/128884
> 更新时间
2018-12-06 12:09:22
2018-12-18 11:28:40
-106
View File
@@ -1,106 +0,0 @@
> 策略名称
Dynamic Balance Strategy
> 策略作者
ruby
> 策略参数
|参数|默认值|描述|
|----|----|----|
|threshold|0.05|threshold|
|ZPrecision|8|Price Precision|
|XPrecision|4|Amount Precision|
|MinStock|0.001|minimum buying amount|
|Interval|2000|error retry interval|
|LoopInterval|60|Polling Interval|
> 源码 (javascript)
``` javascript
var InitAccount = null;
function onTick(){
var acc = _C(exchange.GetAccount);
var ticker = _C(exchange.GetTicker);
var spread = ticker.Sell - ticker.Buy;
var diffAsset = (acc.Balance - (acc.Stocks * ticker.Sell))/2;
var ratio = diffAsset / acc.Balance;
LogStatus('ratio:', ratio, _D());
if(Math.abs(ratio) < threshold){
return false;
}
if(ratio > 0){
var buyPrice = _N(ticker.Sell + spread, ZPrecision);
var buyAmount = _N(diffAsset / buyPrice, XPrecision);
if(buyAmount < MinStock){
return false;
}
exchange.Buy(buyPrice, buyAmount);
} else {
var sellPrice = _N(ticker.Buy - spread, ZPrecision);
var sellAmount = _N(-diffAsset / sellPrice, XPrecision);
if (sellAmount < MinStock) {
return false;
}
exchange.Sell(sellPrice, sellAmount, diffAsset, ratio);
}
return true;
}
function CancelPendingOrders(){
var ret = false;
while(true){
var orders = null;
while(!(orders = exchange.GetOrders())){
Sleep(Interval);
}
if(orders.length == 0){
return ret;
}
for(var j = 0; j < orders.length; j++){
exchange.CancelOrder(orders[j],Id);
ret = true;
if(j < (orders.length - 1)){
Sleep(Interval);
}
}
}
}
function main() {
InitAccount = _C(exchange.GetAccount);
while(true){
if(onTick()){
Sleep(1000);
CancelPendingOrders();
Log(_C(exchange.GetAccount));
}
Sleep(LoopInterval * 1000);
}
}
```
> 策略出处
https://www.fmz.com/strategy/110900
> 更新时间
2018-08-13 12:35:18
+1 -13
View File
@@ -49,18 +49,6 @@ period: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*)
// MACD计算参数 已经添加到,策略参数
// FASTLENGTH:=12;
// SLOWLENGTH:=26;
// MACDLENGTH:=9;
// 均线长度 已经添加到,策略参数
// L1:=50;
// L2:=120;
// 止损5% 已经添加到,策略参数
// STOPLOSS:=5;
//MACD
MACDVALUE:=EMA(CLOSE,FASTLENGTH)-EMA(CLOSE,SLOWLENGTH);
AVGMACD:=EMA(MACDVALUE,MACDLENGTH);
@@ -96,4 +84,4 @@ https://www.fmz.com/strategy/128134
> 更新时间
2018-12-05 11:48:12
2018-12-18 15:30:12
+30 -26
View File
@@ -4,36 +4,42 @@
> 开源策略
- [RUMI策略](https://www.fmz.com/strategy/129082)
- [日本云图简化版策略](https://www.fmz.com/strategy/129083)
- [高胜率ORB交易策略](https://www.fmz.com/strategy/129084)
- [麦语言海龟策略体验](https://www.fmz.com/strategy/126968)
- [升级版恒温器策略](https://www.fmz.com/strategy/129086)
- [Dual Thrust (麦语言版)](https://www.fmz.com/strategy/128884)
- [传统均线指标与KD指标的交易策略](https://www.fmz.com/strategy/128249)
- [双均线策略与相对强弱RSI指标组合](https://www.fmz.com/strategy/128250)
- [抛物线转向SAR与价格高低点策略](https://www.fmz.com/strategy/128251)
- [波动率ATR轨道突破策略](https://www.fmz.com/strategy/128252)
- [价格高低点与一目均线双重趋势策略](https://www.fmz.com/strategy/128415)
- [动向指数(DMI)与高低点策略](https://www.fmz.com/strategy/128418)
- [测试火币macd金叉](https://www.fmz.com/strategy/92839)
- [基于ATR波动率指标构建的通道策略|Channel strategy based on ATR volatility indicator](https://www.fmz.com/strategy/127691)
- [商品期货跟单系统](https://www.fmz.com/strategy/79351)
- [升级版恒温器策略|Upgraded Thermostat Strategy](https://www.fmz.com/strategy/129086)
- [MACD+MA指标组合策略](https://www.fmz.com/strategy/128134)
- [双均线DDI策略](https://www.fmz.com/strategy/128133)
- [高低点突破成交量指数加权策略](https://www.fmz.com/strategy/128125)
- [标准差价格通道策略](https://www.fmz.com/strategy/128121)
- [基于ATR波动率指标构建的通道策略](https://www.fmz.com/strategy/128126)
- [三均线顺势价格突破策略](https://www.fmz.com/strategy/128130)
- [高低点与波动率ROC指标策略](https://www.fmz.com/strategy/128417)
- [瀑布线策略](https://www.fmz.com/strategy/128420)
- [基于ATR波动率指标构建的通道策略|Channel strategy based on ATR](https://www.fmz.com/strategy/128126)
- [三轨道波动率策略|Three-track Volatility Strategy](https://www.fmz.com/strategy/128129)
- [Dual Thrust (麦语言版)|Dual Thrust (MyLanguage version)](https://www.fmz.com/strategy/128884)
- [高胜率ORB交易策略|High Winning Rate - ORB Trading Strategy](https://www.fmz.com/strategy/129084)
- [混沌操作法策略|Trading Chaos Strategy](https://www.fmz.com/strategy/129077)
- [均线和高低点相对强弱策略|Relative Strength Strategy Based on Price](https://www.fmz.com/strategy/129078)
- [日本云图简化版策略|Simplified Version of ICHIMOKU KINKO HYO Strategy](https://www.fmz.com/strategy/129083)
- [双均线与形态策略|Double MA and Formation Strategy](https://www.fmz.com/strategy/129079)
- [RUMI策略|RUMI Strategy](https://www.fmz.com/strategy/129082)
- [瀑布线策略|PBX Strategy](https://www.fmz.com/strategy/128420)
- [动向指数(DMI)与高低点策略|DMI and High-Low Strategy](https://www.fmz.com/strategy/128418)
- [价格高低点与一目均线双重趋势策略|Price high and low - Ichimoku trend strategy](https://www.fmz.com/strategy/128415)
- [高低点与波动率ROC指标策略|Price high and low - ROC index strategy](https://www.fmz.com/strategy/128417)
- [波动率ATR轨道突破策略|Volatility ATR - Track Breakthrough Strategy](https://www.fmz.com/strategy/128252)
- [抛物线转向SAR与价格高低点策略|SAR and Price High and Low Strategy](https://www.fmz.com/strategy/128251)
- [三均线顺势价格突破策略|Three-MA Price Breakthrough Strategy](https://www.fmz.com/strategy/128130)
- [多级止盈趋势策略|Multilevel Take Profit Strategy](https://www.fmz.com/strategy/128122)
- [传统均线指标与KD指标的交易策略|Trading Strategy of Traditional MA Index and KD Index](https://www.fmz.com/strategy/128249)
- [双均线策略与相对强弱RSI指标组合|Combination of Double MA and RSI](https://www.fmz.com/strategy/128250)
- [开收盘均价差ATR策略|The average of difference - combined with ATR](https://www.fmz.com/strategy/128136)
- [双均线DDI策略|Double Average Lines -DDI Strategy](https://www.fmz.com/strategy/128133)
- [高低点突破成交量指数加权策略|Break High and Low - Volume Index Weighting Strategy](https://www.fmz.com/strategy/128125)
- [标准差价格通道策略|Standard deviation price channel strategy](https://www.fmz.com/strategy/128121)
- [CTP 期货](https://www.fmz.com/strategy/130234)
- [你不知道的MACD+MA指标组合策略|MACD+MA Indicator Combination Strategy](https://www.fmz.com/strategy/127101)
- [麦语言海龟策略体验](https://www.fmz.com/strategy/126968)
- [Bitmex仓位变化推送微信(wss协议,需要bitmex api ID)|Bitmex position-change push(websocket)](https://www.fmz.com/strategy/128624)
- [开收盘均价差ATR策略](https://www.fmz.com/strategy/128136)
- [多级止盈趋势策略](https://www.fmz.com/strategy/128122)
- [三轨道波动率策略](https://www.fmz.com/strategy/128129)
- [基于ATR波动率指标构建的通道策略](https://www.fmz.com/strategy/127691)
- [海龟](https://www.fmz.com/strategy/128382)
- [OKEX期现对冲](https://www.fmz.com/strategy/127939)
- [商品期货交易类库(旧版)](https://www.fmz.com/strategy/127341)
- [现现对冲(搬砖)](https://www.fmz.com/strategy/127154)
- [你不知道的MACD+MA指标组合策略](https://www.fmz.com/strategy/127101)
- [BitMEX 高级API功能 V.1.1.0 (期货:批量下单,编辑订单,冰山订单,一键撤单,定时撤单) Python2/3](https://www.fmz.com/strategy/114148)
- [OkEX 高级API功能 V.1.1.0 (期货:批量下单,现货;TBD) Python2/3](https://www.fmz.com/strategy/113979)
- [多交易所集合行情/下单 策略 范例](https://www.fmz.com/strategy/125569)
@@ -78,7 +84,6 @@
- [50行多平台对冲策略(教学)](https://www.fmz.com/strategy/113278)
- [Dual Thrust OKEX期货 (教学)](https://www.fmz.com/strategy/112425)
- [[VNC] SVM Test](https://www.fmz.com/strategy/112188)
- [Dynamic Balance Strategy](https://www.fmz.com/strategy/110900)
- [区块链量化投资系列课程(3) - 跨期套利](https://www.fmz.com/strategy/104964)
- [区块链量化投资系列课程(4) - 动态平衡策略](https://www.fmz.com/strategy/110545)
- [单平台均衡策略](https://www.fmz.com/strategy/345)
@@ -87,7 +92,6 @@
- [画线类库|Plot library](https://www.fmz.com/strategy/27293)
- [Iceberg Buy Order](https://www.fmz.com/strategy/103319)
- [Dual Thrust OKEX Feature](https://www.fmz.com/strategy/103247)
- [商品期货跟单系统](https://www.fmz.com/strategy/79351)
- [转换任意K线周期管理模板(最近更新20180627)](https://www.fmz.com/strategy/41163)
- [检查https://quant.la/Argus/是否正常](https://www.fmz.com/strategy/100344)
- [2014年的简易短线机器人](https://www.fmz.com/strategy/1088)
+22 -5
View File
@@ -1,7 +1,7 @@
> 策略名称
RUMI策略
RUMI策略|RUMI Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:RUMI策略
- 适用周期:多周期
- 支持:商品期货、数字货币期货、数字货币现货
@@ -26,15 +27,31 @@ littleDreamXX
- 副图:
AOS指标,公式: AOS:MA(OS,N3);
||
- Strategy Name: RUMI Strategy
- Applicable cycle: multi-cycle
- Support: Commodity Futures, Digital Currency Futures, Digital Currency Spot
![IMG](https://www.fmz.com/upload/asset/d0d4ae5dd9629a8e2b52c821c63f8873.png)
![IMG](https://www.fmz.com/upload/asset/2cd3d79c46dec610c116645b9a43ae80.png)
- Main chart:
none
- Secondary chart:
AOS index, formula: AOS:MA(OS,N3);
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N1|3|AOS指标参数1|
|N2|100|AOS指标参数2|
|N3|30|AOS指标参数3|
|N1|3|AOS指标参数1|AOS index parameter1|
|N2|100|AOS指标参数2|AOS index parameter2|
|N3|30|AOS指标参数3|AOS index parameter3|
> 源码 (麦语言)
@@ -63,4 +80,4 @@ https://www.fmz.com/strategy/129082
> 更新时间
2018-12-07 11:36:11
2018-12-17 18:19:15
@@ -1,7 +1,7 @@
> 策略名称
三均线顺势价格突破策略
三均线顺势价格突破策略|Three-MA Price Breakthrough Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 公式名称:三均线顺势价格突破策略
- 数据周期:多周期
- 数据合约:指数合约
@@ -18,16 +19,27 @@ littleDreamXX
![IMG](https://www.fmz.com/upload/asset/4327c3e54a8618bb6f5b0ac3ea54dfc2.png)
||
- Data cycle: multiple cycles
- Data contract: index contract
- Trading contract: main contract
- Suitable for: commodity futures
![IMG](https://www.fmz.com/upload/asset/ed995f267589e43cdc0492a87952dcad.png)
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|SLOSS|2|止损百分比|
|N1|30|均线1参数|
|N2|60|均线2参数|
|N3|90|均线3参数|
|SLOSS|2|止损百分比|stop loss percentage|
|N1|30|均线1参数|MA1 parameter|
|N2|60|均线2参数|MA2 parameter|
|N3|90|均线3参数|MA3 parameter|
> 源码 (麦语言)
@@ -54,14 +66,15 @@ SELLP:=BKVOL>0 AND CROSS(MA2,C) AND MA1>C AND C>=BKPRICE*(1+2*SLOSS*0.01);
BUYK,BK(LOTS);
SELLK,SK(LOTS);
//止盈
// 止盈
// take profit
BUYP,BP(SKVOL);
SELLP,SP(BKVOL);
//止损
// 止损
// stop loss
C>=SKPRICE*(1+SLOSS*0.01),BP(SKVOL);
C<=BKPRICE*(1-SLOSS*0.01),SP(BKVOL);
//TRADE_OTHER('AUTO');
```
> 策略出处
@@ -70,4 +83,4 @@ https://www.fmz.com/strategy/128130
> 更新时间
2018-12-04 22:11:09
2018-12-17 12:23:47
-89
View File
@@ -1,89 +0,0 @@
> 策略名称
三轨道波动率策略
> 策略作者
littleDreamXX
> 策略描述
- K线走完下单:收盘价开仓、平仓
- 数据合约:螺纹指数,郑煤指数,热卷指数,铁矿指数,焦炭指数,棕榈指数,橡胶指数,郑醇指数,PP指数,沪铜指数;
- 交易合约:螺纹主连,郑煤主连,热卷主连,铁矿主连,焦炭主连,棕榈主连,橡胶主连,郑醇主连,PP主连,沪铜主连;
- 数据级别:日K线;
![IMG](https://www.fmz.com/upload/asset/785c3a0e4e8c164bc831b05dcdc355a3.png)
- 主图指标显示:
MIDTR^^MA(C,CN); // 确定MIDTR
UPTR^^MIDTR+2*STD(C,CN); // 确定UPTR
DOWNTR^^MIDTR-2*STD(C,CN); // 确定DOWNTR
HPOINT^^HV(H,CN),DOT,COLORRED; // 计算前一周期CN周期内最高价的最大值。
LPOINT^^LV(L,CN),DOT,COLORBLUE; // 计算前一周期CN周期内最低价的最小值。
- 副图:
无
> 策略参数
|参数|默认值|描述|
|----|----|----|
|AMOUNT|true|单仓|
|N|20|标准差周期数|
|MINN|20|CN最小值|
|MAXN|60|CN最大值|
|STOPRANGE|50|止损幅度|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2017-07-01 00:00:00
end: 2018-11-30 00:00:00
period: 1d
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*)
// 确定CN
VOLAT:=STD(C,N); // VOLAT(波动率):M周期收盘价的标准差
VOLATCHANGE:=(VOLAT-REF(VOLAT,1))/VOLAT; // 2个VOLAT的变化率
N1:=(1+VOLATCHANGE)*MINN; // VOLATCHANGE : 波动率变化
N2:=INTPART(N1); // 取整
N3:=MIN(N2,MAXN); // 确认CN不大于60
CN:=MAX(N3,MINN); // 确认CN不小于20
MIDTR^^MA(C,CN); // 确定MIDTR
UPTR^^MIDTR+2*STD(C,CN); // 确定UPTR
DOWNTR^^MIDTR-2*STD(C,CN); // 确定DOWNTR
HPOINT^^HV(H,CN),DOT,COLORRED; // 计算前一周期CN周期内最高价的最大值。
LPOINT^^LV(L,CN),DOT,COLORBLUE; // 计算前一周期CN周期内最低价的最小值。
// 开仓
L<=LPOINT AND L<DOWNTR AND BARPOS>MINN,SK(AMOUNT); // 当最低价小于DOWNTR和低点,且K线位置大于60,收盘价卖开
H>=HPOINT AND H>UPTR AND BARPOS>MINN,BK(AMOUNT); // 当最高价大于UPTR和高点,且K线位置大于60,收盘价买开
// 启动止损
C>=SKPRICE*(1+STOPRANGE*0.001),BP(SKVOL);
C<=BKPRICE*(1-STOPRANGE*0.001),SP(BKVOL);
// 平仓
C<MIDTR,SP(BKVOL); // 当收盘价小于MIDTR,收盘价卖平
C>MIDTR,BP(SKVOL); // 当收盘价大于MIDTR,收盘价买平
// 动态止损
REF(BKHIGH,1)>BKPRICE*(1+2*0.001*STOPRANGE) AND C<HV(C,BARSBK)*(1-STOPRANGE*0.001),SP(BKVOL); // 买开后最高价大于买开价*(1+2*0.001*STOPRANGE),且收盘价小于买开后最高收盘价*(1-STOPRANGE*0.001),收盘价卖平
REF(SKLOW,1)<SKPRICE*(1-2*0.001*STOPRANGE) AND C>LV(C,BARSSK)*(1+STOPRANGE*0.001),BP(SKVOL); // 卖开后最低价小于卖开价*(1-2*0.001*STOPRANGE),且收盘价大于卖开后最低收盘价*(1+STOPRANGE*0.001),收盘价买平
```
> 策略出处
https://www.fmz.com/strategy/128129
> 更新时间
2018-12-03 09:52:12
@@ -0,0 +1,131 @@
> 策略名称
三轨道波动率策略|Three-track Volatility Strategy
> 策略作者
littleDreamXX
> 策略描述
[trans]
- K线走完下单:收盘价开仓、平仓
- 数据级别:日K线;
![IMG](https://www.fmz.com/upload/asset/785c3a0e4e8c164bc831b05dcdc355a3.png)
- 主图指标显示:
MIDTR^^MA(C,CN); // 确定MIDTR
UPTR^^MIDTR+2*STD(C,CN); // 确定UPTR
DOWNTR^^MIDTR-2*STD(C,CN); // 确定DOWNTR
HPOINT^^HV(H,CN),DOT,COLORRED; // 计算前一周期CN周期内最高价的最大值。
LPOINT^^LV(L,CN),DOT,COLORBLUE; // 计算前一周期CN周期内最低价的最小值。
- 副图:
无
||
- Place order after K line is done, open or close position when closing price is determined
- Data Level: Daily K Line
![IMG](https://www.fmz.com/upload/asset/3a476a37c7f7a6939aab1d1ad7164e72.png)
![IMG](https://www.fmz.com/upload/asset/63c9bc0e146e9a3164e78055b0154be7.png)
- Main chart:
MIDTR^^MA(C,CN); // Determine MIDTR
UPTR^^MIDTR+2STD(C,CN); // Determine UPTR
DOWNTR^^MIDTR-2STD(C,CN); // Determine DOWNTR
HPOINT^^HV(H,CN), DOT, COLORRED;
// Calculate the maximum value of the highest price in the CN cycle of the previous cycle.
LPOINT^^LV(L,CN), DOT, COLORBLUE;
// Calculate the minimum value of the lowest price in the CN cycle of the previous cycle.
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|AMOUNT|true|单仓|single order opening amount|
|N|20|标准差周期数|cycles of standard deviation|
|MINN|20|CN最小值|minimum of CN|
|MAXN|60|CN最大值|maximum of CN|
|STOPRANGE|50|止损幅度|stop loss range|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2017-07-01 00:00:00
end: 2018-11-30 00:00:00
period: 1d
exchanges: [{"eid":"Futures_BitMEX","currency":"XBT_USD"}]
args: [["AMOUNT",1000],["TradeAmount",1000,126961],["ContractType","XBTUSD",126961]]
*)
// 确定CN
// Determine CN
VOLAT:=STD(C,N); // VOLAT(波动率):M周期收盘价的标准差
// VOLAT(volatility): Standard deviation of closing price in M-cycle
VOLATCHANGE:=(VOLAT-REF(VOLAT,1))/VOLAT; // 2个VOLAT的变化率
// Change rate of two VOLATs
N1:=(1+VOLATCHANGE)*MINN; // VOLATCHANGE : 波动率变化
// VOLATCHANGE : Volatility change
N2:=INTPART(N1); // 取整
// Rounding off an integer
N3:=MIN(N2,MAXN); // 确认CN不大于60
// Confirm that CN is no more than 60
CN:=MAX(N3,MINN); // 确认CN不小于20
// Confirm that CN is no less than 20
MIDTR^^MA(C,CN); // 确定MIDTR
// Determine MIDTR
UPTR^^MIDTR+2*STD(C,CN); // 确定UPTR
// Determine UPTR
DOWNTR^^MIDTR-2*STD(C,CN); // 确定DOWNTR
// Determine DOWNTR
HPOINT^^HV(H,CN),DOT,COLORRED; // 计算前一周期CN周期内最高价的最大值。
// see main chart
LPOINT^^LV(L,CN),DOT,COLORBLUE; // 计算前一周期CN周期内最低价的最小值。
// see main chart
// 开仓
// open position
L<=LPOINT AND L<DOWNTR AND BARPOS>MINN,SK(AMOUNT); // 当最低价小于DOWNTR和低点,且K线位置大于60,收盘价卖开
// when the lowest price < the lowest point and DOWNTR,and the K-line position > 60, sell short the closing price
H>=HPOINT AND H>UPTR AND BARPOS>MINN,BK(AMOUNT); // 当最高价大于UPTR和高点,且K线位置大于60,收盘价买开
// when the highest price > UPTR and the highest point, and the K-line position > 60, buy long the closing price
// 启动止损
// start stop loss
C>=SKPRICE*(1+STOPRANGE*0.001),BP(SKVOL);
C<=BKPRICE*(1-STOPRANGE*0.001),SP(BKVOL);
// 平仓
// close position
C<MIDTR,SP(BKVOL); // 当收盘价小于MIDTR,收盘价卖平
// when closing price < MIDTR, sell the closing price
C>MIDTR,BP(SKVOL); // 当收盘价大于MIDTR,收盘价买平
// when closing price > MIDTR, buy to cover the closing price
// 动态止损
// Dynamic stop loss
REF(BKHIGH,1)>BKPRICE*(1+2*0.001*STOPRANGE) AND C<HV(C,BARSBK)*(1-STOPRANGE*0.001),SP(BKVOL); // 买开后最高价大于买开价*(1+2*0.001*STOPRANGE),且收盘价小于买开后最高收盘价*(1-STOPRANGE*0.001),收盘价卖平
// the highest price after buying long > buy long price*(1+2*0.001*STOPRANGE), and closing price < the highest closing price after buying long*(1-STOPRANGE*0.001), then sell closing price
REF(SKLOW,1)<SKPRICE*(1-2*0.001*STOPRANGE) AND C>LV(C,BARSSK)*(1+STOPRANGE*0.001),BP(SKVOL); // 卖开后最低价小于卖开价*(1-2*0.001*STOPRANGE),且收盘价大于卖开后最低收盘价*(1+STOPRANGE*0.001),收盘价买平
// the lowest price after sellong short < sell short price *(1-2*0.001*STOPRANGE), and closing price > the lowest closing price after selling short*(1+STOPRANGE*0.001), then buy to cover closing price
```
> 策略出处
https://www.fmz.com/strategy/128129
> 更新时间
2018-12-18 12:21:38
@@ -1,7 +1,7 @@
> 策略名称
价格高低点与一目均线双重趋势策略
价格高低点与一目均线双重趋势策略|Price high and low - Ichimoku trend strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:价格高低点与一目均线双重趋势策略
- 数据周期:15M等
- 支持:商品期货
@@ -22,15 +23,31 @@ littleDreamXX
LINE2指标线,公式:LINE2^^(HHV(H,N2)+LLV(L,N2))*0.5;
||
- Strategy Name: Price high and low - Ichimoku trend strategy
- Data cycle: 15M, etc.
- Support: Commodity Futures
![IMG](https://www.fmz.com/upload/asset/5988d1b7eb989f7a2e345fba35201cc9.png)
![IMG](https://www.fmz.com/upload/asset/a0c6881a0bac6f2c89ffe8fc137be941.png)
![IMG](https://www.fmz.com/upload/asset/227a3bb45cd8ab1bf54e64cdda96650b.png)
- main chart:
LINE1 index line,formula:LINE1^^(HHV(H,N1)+LLV(L,N1))*0.5;
LINE2 index line,formula:LINE2^^(HHV(H,N2)+LLV(L,N2))*0.5;
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N1|150|高点低点均值1周期|
|N2|500|高点低点均值2周期|
|SLOSS|2|止损百分比|
|N1|150|高点低点均值1周期|the highest of high price N1 ago/ the lowest of low price N1 ago|
|N2|500|高点低点均值2周期|the highest of high price N2 ago/ the lowest of low price N2 ago|
|SLOSS|2|止损百分比|stop loss percentage|
> 源码 (麦语言)
@@ -64,4 +81,4 @@ https://www.fmz.com/strategy/128415
> 更新时间
2018-12-05 16:59:14
2018-12-17 17:16:35
@@ -1,73 +0,0 @@
> 策略名称
传统均线指标与KD指标的交易策略
> 策略作者
littleDreamXX
> 策略描述
- 策略名称:传统均线指标与KD指标的交易策略
- 数据周期:15M,30M等
- 支持:商品期货
- 指标使用了EMA,KD线,其中KD线使用的是默认参数(指标参数固定3,3,9)
- 官方网站:www.quant.la
![IMG](https://www.fmz.com/upload/asset/f842e44b0b8451cb562b8d5bd888e4c0.png)
- 主图
EMA均线,公式:MAC^^EMA(C,N);
- 副图
KD线中的K线,公式:K:SMA(RSV,M1,1);//RSV的移动平均值
KD线中的D线,公式:D:SMA(K,M2,1);//K的移动平均值
> 策略参数
|参数|默认值|描述|
|----|----|----|
|SLOSS|2|止损百分比|
|N|120|EMA参数|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-04-01 00:00:00
end: 2018-05-15 00:00:00
period: 30m
exchanges: [{"eid":"Futures_BitMEX","currency":"XBT_USD"}]
args: [["TradeAmount",100,126961],["ContractType","XBTUSD",126961]]
*)
MAC^^EMA(C,N);
NKD:=9;
M1:=3;
M2:=3;
RSV:=(CLOSE-LLV(LOW,NKD))/(HHV(HIGH,NKD)-LLV(LOW,NKD))*100;//收盘价与NKD周期最低值做差,NKD周期最高值与NKD周期最低值做差,两差之间做比值。
K:SMA(RSV,M1,1);//RSV的移动平均值
D:SMA(K,M2,1);//K的移动平均值
BARPOS>N AND C>MAC AND K<D,BK;
BARPOS>N AND C<MAC AND K>D,SK;
C<=BKPRICE*(1-SLOSS*0.01),SP(BKVOL);
C>=SKPRICE*(1+SLOSS*0.01),BP(SKVOL);
C>=BKPRICE*(1+SLOSS*0.01) AND C<MAC,SP(BKVOL);
C<=SKPRICE*(1-SLOSS*0.01) AND C>MAC,BP(SKVOL);
```
> 策略出处
https://www.fmz.com/strategy/128249
> 更新时间
2018-12-05 18:34:08
@@ -0,0 +1,98 @@
> 策略名称
传统均线指标与KD指标的交易策略|Trading Strategy of Traditional MA Index and KD Index
> 策略作者
littleDreamXX
> 策略描述
[trans]
- 策略名称:传统均线指标与KD指标的交易策略
- 数据周期:15M,30M等
- 支持:商品期货
- 指标使用了EMA,KD线,其中KD线使用的是默认参数(指标参数固定3,3,9)
- 官方网站:www.quant.la
![IMG](https://www.fmz.com/upload/asset/f842e44b0b8451cb562b8d5bd888e4c0.png)
- 主图
EMA均线,公式:MAC^^EMA(C,N);
- 副图
KD线中的K线,公式:K:SMA(RSV,M1,1);//RSV的移动平均值
KD线中的D线,公式:D:SMA(K,M2,1);//K的移动平均值
||
- Data Cycle: 15M, 30M, etc.
- Support: Commodity Futures
- Indicators are EMA, KD lines, and KD line use default parameters (index parameters fixed 3, 3, 9)
![IMG](https://www.fmz.com/upload/asset/320fafa2ce5d6f68a4260a028783580d.png)
![IMG](https://www.fmz.com/upload/asset/6753142c9c078ad25e9c913e82c0d999.png)
- Main chart:
EMA mean, formula: MAC ^^ EMA (C, N);
- Secondary chart:
K line in KD, formula: K: SMA (RSV, M1, 1); //RSV moving average
D line in KD, formula: D: SMA (K, M2, 1); //K moving average value
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|SLOSS|2|止损百分比|stop loss percentage|
|N|120|EMA参数|EMA parameter|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-04-01 00:00:00
end: 2018-05-15 00:00:00
period: 30m
exchanges: [{"eid":"Futures_BitMEX","currency":"XBT_USD"}]
args: [["TradeAmount",100,126961],["ContractType","XBTUSD",126961]]
*)
MAC^^EMA(C,N);
NKD:=9;
M1:=3;
M2:=3;
RSV:=(CLOSE-LLV(LOW,NKD))/(HHV(HIGH,NKD)-LLV(LOW,NKD))*100; //收盘价与NKD周期最低值做差,NKD周期最高值与NKD周期最低值做差,两差之间做比值。
// (1)closing price minus the lowest value in NKD cycle,
// (2)the highest value in NKD cycle minus the lowest value in NKD cycle, then (1) divided by (2).
K:SMA(RSV,M1,1); // RSV的移动平均值
// MA of RSV
D:SMA(K,M2,1); // K的移动平均值
// MA of K
BARPOS>N AND C>MAC AND K<D,BK;
BARPOS>N AND C<MAC AND K>D,SK;
C<=BKPRICE*(1-SLOSS*0.01),SP(BKVOL);
C>=SKPRICE*(1+SLOSS*0.01),BP(SKVOL);
C>=BKPRICE*(1+SLOSS*0.01) AND C<MAC,SP(BKVOL);
C<=SKPRICE*(1-SLOSS*0.01) AND C>MAC,BP(SKVOL);
```
> 策略出处
https://www.fmz.com/strategy/128249
> 更新时间
2018-12-15 16:06:00
@@ -1,79 +0,0 @@
> 策略名称
你不知道的MACD+MA指标组合策略
> 策略作者
Zero
> 策略描述
本期分享MACD+MA指标组合策略,在技术分析中,指标的组合使用是非常常见的,不同的指标组合在一起具有不同的操作要点和分析方法,指标的组合使用可以增强信号的准确性。该策略正是通过比较价格与MA的相互关系,再以MACD指标衡量价格运动加速度,来判断市场所处的状态,构建一种简单的择时交易策略。
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-11-01 00:00:00
end: 2018-11-22 00:00:00
period: 1h
exchanges: [{"eid":"OKCoin_EN","currency":"BTC_USD"}]
*)
// 公式名称:MACD+MA指标组合策略
// 数据周期:4小时
// 适合品种:商品期货/数字货币现货/数字货币期货
// MACD计算参数
FASTLENGTH:=12;
SLOWLENGTH:=26;
MACDLENGTH:=9;
// 均线长度
L1:=50;
L2:=120;
// 止损5%
STOPLOSS:=5;
//MACD
MACDVALUE:=EMA(CLOSE,FASTLENGTH)-EMA(CLOSE,SLOWLENGTH);
AVGMACD:=EMA(MACDVALUE,MACDLENGTH);
MACDDIFF:=MACDVALUE-AVGMACD;
//MA1、MA2
DMA1:=MA(C,L1);
DMA2:=MA(C,L2);
买入开仓价:=VALUEWHEN(BARSBK=1,O);
卖出开仓价:=VALUEWHEN(BARSSK=1,O);
BUYCONDITION:=MACDVALUE>0 && DMA1>DMA2 && MACDDIFF>0 && C>DMA1 && REF(C,1)>REF(DMA1,1);
SELLCONDITION:=MACDVALUE<0 && DMA1<DMA2 && MACDDIFF<0 && C<DMA1 && REF(C,1)<REF(DMA1,1);
//开仓条件
BKVOL=0 AND BUYCONDITION,BK;
SETSIGPRICETYPE(BK,NEW_ORDER);
SKVOL=0 AND SELLCONDITION,SK;
SETSIGPRICETYPE(SK,NEW_ORDER);
//离场条件
BKVOL>0 AND (REF(MACDVALUE,1)<0 OR REF(DMA1,1)<REF(DMA2,1)),SP;
SKVOL>0 AND (REF(MACDVALUE,1)>0 OR REF(DMA1,1)>REF(DMA2,1)),BP;
// 启动止损
SKVOL>0 AND HIGH>=卖出开仓价*(1+STOPLOSS*0.01),BP;
SETSIGPRICETYPE(BP,MAX(O,卖出开仓价*(1+STOPLOSS*0.01)));
BKVOL>0 AND LOW<=买入开仓价*(1-STOPLOSS*0.01),SP;
SETSIGPRICETYPE(SP,MIN(O,买入开仓价*(1-STOPLOSS*0.01)));
AUTOFILTER;
```
> 策略出处
https://www.fmz.com/strategy/127101
> 更新时间
2018-11-22 22:47:00
@@ -0,0 +1,79 @@
> 策略名称
你不知道的MACD+MA指标组合策略|MACD+MA Indicator Combination Strategy
> 策略作者
Zero
> 策略描述
[trans]
本期分享MACD+MA指标组合策略,在技术分析中,指标的组合使用是非常常见的,不同的指标组合在一起具有不同的操作要点和分析方法,指标的组合使用可以增强信号的准确性。该策略正是通过比较价格与MA的相互关系,再以MACD指标衡量价格运动加速度,来判断市场所处的状态,构建一种简单的择时交易策略。
||
The MA indicator is short for English(Moving average) and is called the moving average indicator. The moving average(MA) has a trending characteristic, which is relatively stable, unlike the day K line that will rise and fall. The longer the moving average, the more stable the performance. Not easily up and down, you must wait for the true clarity of the stock price trend. The moving average is, in the final analysis, a trend-tracking tool that makes it easy to identify whether a trend has ended or reversed and whether a new trend is emerging.
In this issue, we share the MACD+MA index combination strategy. In the technical analysis, the combination of indicators is very common. Different indicators have different operation points and analysis methods. The combination of indicators can enhance the accuracy of the signal. The strategy is to compare the relationship between price and MA, and then measure the price movement acceleration by MACD index to judge the state of the market and construct a simple timing trading strategy.
[/trans]
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-11-01 00:00:00
end: 2018-11-22 00:00:00
period: 1h
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*)
// MACD calculation
FASTLENGTH:=12;
SLOWLENGTH:=26;
MACDLENGTH:=9;
// Length of MA
L1:=50;
L2:=120;
// stop loss 止损 5%
STOPLOSS:=5;
//MACD
MACDVALUE:=EMA(CLOSE,FASTLENGTH)-EMA(CLOSE,SLOWLENGTH);
AVGMACD:=EMA(MACDVALUE,MACDLENGTH);
MACDDIFF:=MACDVALUE-AVGMACD;
//MA1、MA2
DMA1:=MA(C,L1);
DMA2:=MA(C,L2);
BUYCONDITION:=MACDVALUE>0 && DMA1>DMA2 && MACDDIFF>0 && C>DMA1 && REF(C,1)>REF(DMA1,1);
SELLCONDITION:=MACDVALUE<0 && DMA1<DMA2 && MACDDIFF<0 && C<DMA1 && REF(C,1)<REF(DMA1,1);
// 开仓条件 When to open position
BKVOL=0 AND BUYCONDITION,BK;
SETSIGPRICETYPE(BK,NEW_ORDER);
SKVOL=0 AND SELLCONDITION,SK;
SETSIGPRICETYPE(SK,NEW_ORDER);
// 离场条件 When to close position
BKVOL>0 AND (REF(MACDVALUE,1)<0 OR REF(DMA1,1)<REF(DMA2,1)),SP;
SKVOL>0 AND (REF(MACDVALUE,1)>0 OR REF(DMA1,1)>REF(DMA2,1)),BP;
// 启动止损 Start stop loss
SKVOL>0 AND HIGH>=SKPRICE*(1+STOPLOSS*0.01),BP;
BKVOL>0 AND LOW<=BKPRICE*(1-STOPLOSS*0.01),SP;
AUTOFILTER;
```
> 策略出处
https://www.fmz.com/strategy/127101
> 更新时间
2018-12-14 10:25:27
@@ -1,7 +1,7 @@
> 策略名称
动向指数(DMI)与高低点策略
动向指数(DMI)与高低点策略|DMI and High-Low Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:动向指数(DMI)与高低点策略
- 数据周期:5M
- 支持:商品期货
@@ -23,18 +24,33 @@ littleDreamXX
AMA2指标,公式:AMA2^^EMA(DMA(CLOSE,CQ2),2);
||
- Strategy Name: DMI and High-Low Strategy
- Data Cycle: 5M
- Support: Commodity Futures
![IMG](https://www.fmz.com/upload/asset/e373cde011ba569f143e399a6f51528d.png)
![IMG](https://www.fmz.com/upload/asset/9c51e404853a232c50c6ef12bb809e7d.png)
- Main chart:
AMA1 index, formula: AMA1 ^ ^ EMA (DMA (CLOSE, CQ1), 2);
AMA2 index, formula: AMA2 ^ ^ EMA (DMA (CLOSE, CQ2), 2);
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N|20|AMA1指标参数(1)|
|N1|4|AMA1指标参数(2)|
|N2|60|AMA1指标参数(3)|
|M|40|AMA2指标参数(1)|
|M1|8|AMA2指标参数(2)|
|M2|120|AMA2指标参数(3)|
|N|20|AMA1指标参数(1)|AMA1 index parameter(1)|
|N1|4|AMA1指标参数(2)|AMA1 index parameter(2)|
|N2|60|AMA1指标参数(3)|AMA1 index parameter(3)|
|M|40|AMA2指标参数(1)|AMA2 index parameter(1)|
|M1|8|AMA2指标参数(2)|AMA2 index parameter(2)|
|M2|120|AMA2指标参数(3)|AMA2 index parameter(3)|
> 源码 (麦语言)
@@ -76,4 +92,4 @@ https://www.fmz.com/strategy/128418
> 更新时间
2018-12-05 12:38:58
2018-12-17 17:40:05
-108
View File
@@ -1,108 +0,0 @@
> 策略名称
升级版恒温器策略
> 策略作者
littleDreamXX
> 策略描述
- 策略名称:升级版恒温器策略
- 数据周期:1H
- 支持:商品期货
- 官方网站:WWW.QUANT.LA
![IMG](https://www.fmz.com/upload/asset/bcf664987bac1aaff72110b1e3679d10.png)
- 主图:
上轨,公式:TOP^^MAC+N_TMP*TMP;//布林通道上轨
下轨,公式:BOTTOM^^MAC-N_TMP*TMP;//布林通道下轨
- 副图:
CMI,公式 : CMI:ABS(C-REF(C,N_CMI-1))/(HHV(H,N_CMI)-LLV(L,N_CMI))*100;//0-100 取值越大,说明趋势越强,CMI<20震荡模式,CMI>20为趋势
> 策略参数
|参数|默认值|描述|
|----|----|----|
|STOPLOSS|true|止损价格百分比|
|N|50|布林线指标参数1|
|N_TMP|2|布林线指标参数2|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-11-06 00:00:00
end: 2018-12-04 00:00:00
period: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*)
MAC:=MA(CLOSE,N);
TMP:=STD(CLOSE,N);
TOP^^MAC+N_TMP*TMP;//布林通道上轨
BOTTOM^^MAC-N_TMP*TMP;//布林通道下轨
BBOLL:=C>MAC;
SBOLL:=C<MAC;
N_CMI:=30;
CMI:ABS(C-REF(C,N_CMI-1))/(HHV(H,N_CMI)-LLV(L,N_CMI))*100;//0-100 取值越大,说明趋势越强,CMI<20震荡模式,CMI>20为趋势
N_KD:=9;
M1:=3;
M2:=3;
RSV:=(CLOSE-LLV(LOW,N_KD))/(HHV(HIGH,N_KD)-LLV(LOW,N_KD))*100;//收盘价与N周期最低值做差,N周期最高值与N周期最低值做差,两差之间做比值。
K:=SMA(RSV,M1,1);//RSV的移动平均值
D:=SMA(K,M2,1);//K的移动平均值
MIND:=30;
BKD:=K>D AND D<MIND;
SKD:=K<D AND D>100-MIND;
//震荡模式
BUYPK1:=CMI < 20 AND BKD;//震荡多单买平开
SELLPK1:=CMI < 20 AND SKD;//震荡空单卖平开
//趋势模式下原有震荡持仓的处理
SELLY1:=REF(CMI,BARSBK) < 20 AND C>BKPRICE*(1+0.01*STOPLOSS*3) AND K<D;//震荡多单止盈
BUYY1:=REF(CMI,BARSSK) < 20 AND C<SKPRICE*(1-0.01*STOPLOSS*3) AND K>D;//震荡空单止盈
//趋势模式
BUYPK2:=CMI >= 20 AND C > TOP;//趋势多单买平开
SELLPK2:=CMI >= 20 AND C < BOTTOM;//趋势空单卖平开
//趋势模式下原有震荡持仓的处理
SELLY2:=REF(CMI,BARSBK) >= 20 AND C>BKPRICE*(1+0.01*STOPLOSS*3) AND SBOLL;//趋势多单止盈
BUYY2:=REF(CMI,BARSSK) >= 20 AND C<SKPRICE*(1-0.01*STOPLOSS*3) AND BBOLL;//趋势空单止盈
SELLS2:=REF(CMI,BARSBK) >= 20 AND C<BKPRICE*(1-0.01*STOPLOSS) AND SBOLL;//趋势多单止损
BUYS2:=REF(CMI,BARSSK) >= 20 AND C>SKPRICE*(1+0.01*STOPLOSS) AND BBOLL;//趋势空单止损
IF BARPOS>N THEN BEGIN
BUYPK1,BPK;
SELLPK1,SPK;
BUYPK2,BPK;
SELLPK2,SPK;
END
BUYY1,BP(SKVOL);
BUYY2,BP(SKVOL);
BUYS2,BP(SKVOL);
SELLY1,SP(BKVOL);
SELLY2,SP(BKVOL);
SELLS2,SP(BKVOL);
```
> 策略出处
https://www.fmz.com/strategy/129086
> 更新时间
2018-12-06 13:39:54
@@ -0,0 +1,148 @@
> 策略名称
升级版恒温器策略|Upgraded Thermostat Strategy
> 策略作者
littleDreamXX
> 策略描述
[trans]
- 策略名称:升级版恒温器策略
- 数据周期:1H
- 支持:商品期货、数字货币期货、数字货币现货
- 官方网站:WWW.QUANT.LA
![IMG](https://www.fmz.com/upload/asset/bcf664987bac1aaff72110b1e3679d10.png)
- 主图:
上轨,公式:TOP^^MAC+N_TMP*TMP;//布林通道上轨
下轨,公式:BOTTOM^^MAC-N_TMP*TMP;//布林通道下轨
- 副图:
CMI,公式 : CMI:ABS(C-REF(C,N_CMI-1))/(HHV(H,N_CMI)-LLV(L,N_CMI))*100;//0-100 取值越大,说明趋势越强,CMI<20震荡模式,CMI>20为趋势
||
- Strategy Name: Upgraded Thermostat Strategy
- Data cycle: 1H
- Support: Commodity Futures, Digital Currency Futures, Digital Currency Spot
![IMG](https://www.fmz.com/upload/asset/0e0a008b14ac42a86128e2b86c3b990a.png)
![IMG](https://www.fmz.com/upload/asset/925a0c3eae66fb4e6f2e94b9c775a90f.png)
- Main chart:
upper track, formula: TOP^^MAC+N_TMPTMP; / / upper track of boll
lower track, formula: BOTTOM^^MAC-N_TMPTMP;//lower track of boll
- Secondary chart:
CMI, formula: CMI: ABS(C-REF(C,N_CMI-1))/(HHV(H,N_CMI)-LLV(L,N_CMI))*100;
//0-100 the larger the value, the stronger the trend, CMI <20 is oscillation, CMI>20 is trend
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|STOPLOSS|true|止损价格百分比|stop loss price percentage|
|N|50|布林线指标参数1|boll index parameter 1|
|N_TMP|2|布林线指标参数2|boll index parameter 2|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-11-06 00:00:00
end: 2018-12-04 00:00:00
period: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*)
MAC:=MA(CLOSE,N);
TMP:=STD(CLOSE,N);
TOP^^MAC+N_TMP*TMP; // 布林通道上轨
// upper track of ball
BOTTOM^^MAC-N_TMP*TMP; // 布林通道下轨
// lower track of ball
BBOLL:=C>MAC;
SBOLL:=C<MAC;
N_CMI:=30;
CMI:ABS(C-REF(C,N_CMI-1))/(HHV(H,N_CMI)-LLV(L,N_CMI))*100; // 0-100 取值越大,说明趋势越强,CMI<20震荡模式,CMI>20为趋势
// 0-100 the larger the value, the stronger the trend, CMI <20 is oscillation mode, CMI>20 is the trend
N_KD:=9;
M1:=3;
M2:=3;
RSV:=(CLOSE-LLV(LOW,N_KD))/(HHV(HIGH,N_KD)-LLV(LOW,N_KD))*100; // 收盘价与N周期最低值做差,N周期最高值与N周期最低值做差,两差之间做比值。
// (1)closing price - the lowest of cycle N, (2)the highest of cycle N - the lowest of cycle N, (1)/(2)
K:=SMA(RSV,M1,1); // RSV的移动平均值
// MA of RSV
D:=SMA(K,M2,1); // K的移动平均值
// MA of K
MIND:=30;
BKD:=K>D AND D<MIND;
SKD:=K<D AND D>100-MIND;
// 震荡模式
// oscillation mode
BUYPK1:=CMI < 20 AND BKD; // 震荡多单买平开
// if it's oscillation, buy to cover and buy long immediately
SELLPK1:=CMI < 20 AND SKD; // 震荡空单卖平开
// if it's oscillation, sell to close long position and sell short to open position immediately
// 趋势模式下原有震荡持仓的处理
// Disposal of the original oscillating position under the trend mode
SELLY1:=REF(CMI,BARSBK) < 20 AND C>BKPRICE*(1+0.01*STOPLOSS*3) AND K<D; // 震荡多单止盈
// if it's oscillation, long position take profit
BUYY1:=REF(CMI,BARSSK) < 20 AND C<SKPRICE*(1-0.01*STOPLOSS*3) AND K>D; // 震荡空单止盈
// if it's oscillation, short position take profit
// 趋势模式
// trend mode
BUYPK2:=CMI >= 20 AND C > TOP; // 趋势多单买平开
// if it's trend, buy to cover and buy long immediately
SELLPK2:=CMI >= 20 AND C < BOTTOM; // 趋势空单卖平开
// if it's trend, sell to close long position and sell short to open position immediately
// 趋势模式下原有震荡持仓的处理
// Disposal of the original oscillating position under the trend mode
SELLY2:=REF(CMI,BARSBK) >= 20 AND C>BKPRICE*(1+0.01*STOPLOSS*3) AND SBOLL; // 趋势多单止盈
// if it's trend, long position take profit
BUYY2:=REF(CMI,BARSSK) >= 20 AND C<SKPRICE*(1-0.01*STOPLOSS*3) AND BBOLL; // 趋势空单止盈
// if it's trend, short position take profit
SELLS2:=REF(CMI,BARSBK) >= 20 AND C<BKPRICE*(1-0.01*STOPLOSS) AND SBOLL; // 趋势多单止损
// if it's trend, long position stop loss
BUYS2:=REF(CMI,BARSSK) >= 20 AND C>SKPRICE*(1+0.01*STOPLOSS) AND BBOLL; // 趋势空单止损
// if it's trend, short position stop loss
IF BARPOS>N THEN BEGIN
BUYPK1,BPK;
SELLPK1,SPK;
BUYPK2,BPK;
SELLPK2,SPK;
END
BUYY1,BP(SKVOL);
BUYY2,BP(SKVOL);
BUYS2,BP(SKVOL);
SELLY1,SP(BKVOL);
SELLY2,SP(BKVOL);
SELLS2,SP(BKVOL);
```
> 策略出处
https://www.fmz.com/strategy/129086
> 更新时间
2018-12-18 15:48:27
@@ -1,7 +1,7 @@
> 策略名称
双均线DDI策略
双均线DDI策略|Double Average Lines -DDI Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略思路:双均线确定方向,用DDI指标,确定进场时点,比例止损和回撤止盈
- 数据周期:15M
- 数据合约:指数合约
@@ -27,29 +28,51 @@ littleDreamXX
![IMG](https://www.fmz.com/upload/asset/e83641b0567b242687792b105de8e211.png)
||
- Strategy idea: Use double average lines to determine the direction;
- use the DDI indicator to determine when to open position;
- proportional to determine the stop loss and take profit
- Data cycle: 15M
![IMG](https://www.fmz.com/upload/asset/09e140c314c2cd3829cb03f89f502ac6.png)
![IMG](https://www.fmz.com/upload/asset/5a2ed54d056607b1432ae31cb5c0903d.png)
- Main chart:
VAR2^^MA(C, PARAM2);
VAR3^^MA(VAR2, PARAM1);
- Secondary chart:
VAR9: MA (VAR8, 2*PARAM1);
VAR10: MA (VAR9, PARAM1);
VAR8: VAR6-VAR7;
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|PARAM1|60|均线2的参数|
|PARAM2|300|均线1的参数|
|PARAM3|true|价格系数|
|PARAM1|60|均线2的参数|parameter of average line 2|
|PARAM2|300|均线1的参数|parameter of average line 1|
|PARAM3|true|价格系数|price coefficient|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2017-01-01 00:00:00
end: 2017-02-20 00:00:00
start: 2018-11-01 00:00:00
end: 2018-12-14 00:00:00
period: 15m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES","balance":20000}]
exchanges: [{"eid":"Futures_BitMEX","currency":"XBT_USD"}]
args: [["TradeAmount",100,126961],["ContractType","XBTUSD",126961]]
*)
VAR1:=MAX(1,INTPART(MONEYTOT/(O*UNIT*0.1)));
VAR2^^MA(C,PARAM2);
VAR3^^MA(VAR2,PARAM1);
@@ -70,21 +93,14 @@ BUYY:=C>VAR2 AND C<SKPRICE*(1-0.01*PARAM3);
SELLS:=C<BKPRICE*(1-PARAM3*0.01);
BUYS:=C>SKPRICE*(1+PARAM3*0.01);
BKVOL=0 AND BUYK,BK(VAR1);
SKVOL=0 AND SELLK,SK(VAR1);
BKVOL=0 AND BUYK,BK;
SKVOL=0 AND SELLK,SK;
SELLS,SP(BKVOL);
BUYS,BP(SKVOL);
SELLY,SP(BKVOL);
BUYY,BP(SKVOL);
// DRAWCOLORKLINE(BKVOL=0 AND SKVOL=0,COLORWHITE,0);
// DRAWCOLORKLINE(SKVOL>0,COLORGREEN,0);
// DRAWCOLORKLINE(BKVOL>0,COLORRED,0);
// 累计盈亏..OFFSETPROFIT1,COLORWHITE,BOLD;
// PROFITSUM..OFFSETPROFIT1,COLORWHITE,BOLD;
//TRVAR10E_OTHER('AUTO');
```
> 策略出处
@@ -93,4 +109,4 @@ https://www.fmz.com/strategy/128133
> 更新时间
2018-12-05 11:47:14
2018-12-15 15:43:04
@@ -0,0 +1,98 @@
> 策略名称
双均线与形态策略|Double MA and Formation Strategy
> 策略作者
littleDreamXX
> 策略描述
[trans]
- 策略名称:双均线与形态策略
- 数据周期:15M
- 支持:商品期货,数字货币,数字货币期货
- 官方网站:WWW.QUANT.LA
![IMG](https://www.fmz.com/upload/asset/cf5ac5fdf4f33ed438ed4498e1a7b142.png)
- 主图:
MA指标,公式: VAR3^^MA(VAR2,PARAM1);
EMA指标,公式:VAR4^^EMA(VAR3,PARAM2);
- 副图:
无
||
- Strategy Name: Double MA and Formation Strategy
- Support: Commodity Futures, Digital Currency Spot, Digital Currency Futures
- Data cycle: 15M
![IMG](https://www.fmz.com/upload/asset/a11b6dffb660edef84c785a9d1d88f87.png)
![IMG](https://www.fmz.com/upload/asset/c2498b876b57cce1e887fa052ac8a298.png)
- Main chart:
MA index, formula: VAR3 ^^ MA (VAR2, PARAM1);
EMA index, formula: VAR4 ^ ^ EMA (VAR3, PARAM2);
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|PARAM1|200|MA指标参数|MA index parameter|
|PARAM2|10|EMA指标参数|EMA index parameter|
|PARAM3|true|止盈止损百分比|take profit percentage and stop loss percentage|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-05-02 00:00:00
end: 2018-06-21 00:00:00
period: 15m
exchanges: [{"eid":"Futures_BitMEX","currency":"XBT_USD"}]
args: [["TradeAmount",1000,126961],["SlideTick",10,126961],["ContractType","XBTUSD",126961]]
*)
DIRECTION:=0; // 方向控制
// Direction control
VAR2:=(HIGH+LOW+CLOSE)/3;
VAR3^^MA(VAR2,PARAM1);
VAR4^^EMA(VAR3,PARAM2);
BOOL1:=CLOSE>REF(C,1) AND HIGH>REF(HIGH,1) AND CLOSE>OPEN;
BOOL2:=CLOSE<REF(C,1) AND LOW<REF(LOW,1) AND CLOSE<OPEN;
BUYPK:=BARPOS>PARAM1 AND CLOSE>VAR3 AND BOOL1 AND VAR3>VAR4;
SELLPK:=BARPOS>PARAM1 AND CLOSE<VAR3 AND BOOL2 AND VAR3<VAR4;
BUYJ:=CLOSE>BKPRICE AND BUYPK;
SELLJ:=CLOSE<SKPRICE AND SELLPK;
SELLS:=CLOSE<BKPRICE*(1-PARAM3*0.01);
BUYS:=CLOSE>SKPRICE*(1+PARAM3*0.01);
BKVOL=0 AND BUYPK AND DIRECTION>=0,BPK;
SKVOL=0 AND SELLPK AND DIRECTION<=0,SPK;
BKVOL>0 AND BUYJ,BK;
SKVOL>0 AND SELLJ,SK;
SELLS,SP;
BUYS,BP;
AUTOFILTER;
```
> 策略出处
https://www.fmz.com/strategy/129079
> 更新时间
2018-12-17 18:31:58
@@ -1,7 +1,7 @@
> 策略名称
双均线策略与相对强弱RSI指标组合
双均线策略与相对强弱RSI指标组合|Combination of Double MA and RSI
> 策略作者
@@ -9,6 +9,8 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:双均线策略与相对强弱RSI指标组合
- 数据周期:15M,30M等
- 支持:商品期货
@@ -23,15 +25,35 @@ littleDreamXX
- 副图:
RSI,公式:RSIVALUE:SMA(MAX(CLOSE-REF(CLOSE,1),0),LENGTH,1)/SMA(ABS(CLOSE-REF(CLOSE,1)),LENGTH,1)*100;
||
- Strategy Name: Combination of Double MA and RSI
- Data Cycle: 15M, 30M, etc.
- Support: Commodity Futures
![IMG](https://www.fmz.com/upload/asset/3115dab65deb2ed7d795cdabb32d88be.png)
![IMG](https://www.fmz.com/upload/asset/1a352942b56f16cddab02f1692c909f2.png)
- Main chart:
MA 1, formula: MA1 ^^ EMA (C, N1);
MA 2, formula: MA2 ^^ EMA (C, N2);
- Secondary chart:
RSI, formula:
RSIVALUE:SMA(MAX(CLOSE-REF(CLOSE,1),0),LENGTH,1)/SMA(ABS(CLOSE-REF(CLOSE,1)),LENGTH,1)*100;
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|SLOSS|true|止损百分比|
|N1|50|均线1参数|
|N2|300|均线2参数|
|SLOSS|true|止损百分比|Stop Loss Percentage|
|N1|50|均线1参数|MA1 parameter|
|N2|300|均线2参数|MA2 parameter|
> 源码 (麦语言)
@@ -73,4 +95,4 @@ https://www.fmz.com/strategy/128250
> 更新时间
2018-12-05 18:20:59
2018-12-15 15:44:22
+57 -76
View File
@@ -16,126 +16,107 @@ Hukybo
``` javascript
var arr = [];
//下单
//下单函数
function trade(symbol, type, unit) {
var acc = _C(exchanges[0].GetAccount).Balance; //主账户
symbol = symbol.substring(0, symbol.length - 1);
var acc = _C(exchanges[0].GetAccount).Info.Balance;
for (var i = 1; i < exchanges.length; i++) {
var ac = _C(exchanges[i].GetAccount).Balance; //子账户
var dw = Math.floor(unit / (acc / ac)); //按资金比例下单
var ac = _C(exchanges[i].GetAccount).Info.Balance;
var dws = unit / (acc / ac);
var dw;
if (type == "buy" || type == "sell") {
dw = Math.floor(dws);
} else {
dw = Math.round(dws);
}
if (dw < 1) {
Log(i, ' 号账户资金不足');
continue;
}
var mp = _C(exchanges[i].GetPosition); //子持仓
var npm = $.NewPositionManager(exchanges[i]);
if (type == 11) {
npm.OpenLong(symbol, dw);
Log(i, ' 号账户:', symbol, ':多开:', dw, ' 张');
} else if (type == -11) {
npm.OpenShort(symbol, dw);
Log(i, ' 号账户:', symbol, ':空开:', dw, ' 张');
} else if (type == 10 || type == -10) {
for (var v = 0; v < mp.length; v++) {
if (mp[v].ContractType == symbol) {
npm.Cover(symbol, dw);
if (type == 10) {
Log(i, ' 号账户:', symbol, ':多平:', dw, ' 张');
} else {
Log(i, ' 号账户:', symbol, ':空平:', dw, ' 张');
}
}
}
} else if (type == 100 || type == -100) {
for (var k = 0; k < mp.length; k++) {
if (mp[k].ContractType == symbol) {
npm.Cover(symbol, mp[k].Amount);
Log(i, ' 号账户:', symbol, ':全平');
}
}
var ntq = $.NewTaskQueue();
ntq.pushTask(exchanges[i], symbol, type, unit, function(task, ret) {
Log(i, ' 号账户 @ ', task.desc, "手, 成交价格:", ret.price);
});
while (ntq.tasks.length > 0) {
ntq.poll();
}
}
}
//匹配
function Comparison(arr) {
//匹配函数
function comparison(arr) {
for (var y in arr[0]) {
if (!arr[1][y]) {
if (arr[0][y].Type == "多") {
trade(y, "closebuy", arr[0][y].Amount);
} else if (arr[0][y].Type == "空") {
trade(y, "closesell", arr[0][y].Amount);
}
}
}
for (var x in arr[1]) {
if (arr[0][x]) {
if (arr[1][x].Type == arr[0][x].Type) {
if (arr[1][x].Amount - arr[0][x].Amount > 0) {
if (arr[1][x].Type == "多") {
trade(x, 11, arr[1][x].Amount - arr[0][x].Amount); //多头加仓
} else if (arr[1][x].Type == "空") {
trade(x, -11, arr[1][x].Amount - arr[0][x].Amount); //空头加仓
}
} else if (arr[1][x].Amount - arr[0][x].Amount < 0) {
if (arr[1][x].Type == "多") {
trade(x, 10, arr[0][x].Amount - arr[1][x].Amount); //多头减仓
} else if (arr[1][x].Type == "空") {
trade(x, -10, arr[0][x].Amount - arr[1][x].Amount); //空头减仓
}
}
} else {
if (arr[1][x].Amount - arr[0][x].Amount === 0) {
continue;
} else if (arr[1][x].Amount - arr[0][x].Amount > 0) {
if (arr[1][x].Type == "多") {
trade(x, -100, arr[0][x].Amount);
trade(x, 11, arr[1][x].Amount); //空头反手为多头
trade(x, "buy", arr[1][x].Amount - arr[0][x].Amount);
} else if (arr[1][x].Type == "空") {
trade(x, 100, arr[0][x].Amount);
trade(x, -11, arr[1][x].Amount); //多头反手为空头
trade(x, "sell", arr[1][x].Amount - arr[0][x].Amount);
}
} else if (arr[1][x].Amount - arr[0][x].Amount < 0) {
if (arr[1][x].Type == "多") {
trade(x, "closebuy", arr[0][x].Amount - arr[1][x].Amount);
} else if (arr[1][x].Type == "空") {
trade(x, "closesell", arr[0][x].Amount - arr[1][x].Amount);
}
}
} else {
if (arr[1][x].Type == "多") {
trade(x, 11, arr[1][x].Amount); //多开
trade(x, "buy", arr[1][x].Amount);
} else if (arr[1][x].Type == "空") {
trade(x, -11, arr[1][x].Amount); //空开
}
}
}
for (var y in arr[0]) {
if (!arr[1][y]) {
if (arr[0][y].Type == "多") {
trade(y, 100, arr[0][y].Amount); //多平
} else if (arr[0][y].Type == "空") {
trade(y, -100, arr[0][y].Amount); //空平
trade(x, "sell", arr[1][x].Amount);
}
}
}
}
//数据处理
//数据处理函数
function data() {
var mp = _C(exchanges[0].GetPosition);
var allDic = {};
for (var v = 0; v < mp.length; v++) {
var name = mp[v].ContractType;
allDic[name] = {};
allDic[name]["Amount"] = mp[v].Amount;
var bs = "";
if (mp[v].Type == 0 || mp[v].Type == 2) {
bs = "多"
} else {
bs = "空"
for (var i = 0; i < mp.length; i++) {
var bs, name;
if (mp[i].Type == 0 || mp[i].Type == 2) {
bs = "多";
name = mp[i].ContractType + bs;
} else if (mp[i].Type == 1 || mp[i].Type == 3) {
bs = "空";
name = mp[i].ContractType + bs;
}
allDic[name] = {};
allDic[name]["Amount"] = mp[i].Amount;
allDic[name]["Type"] = bs;
}
arr.push(allDic);
if (arr.length > 2) {
arr.shift();
Comparison(arr);
comparison(arr);
}
}
// 主函数
function main() {
for (var i = 0; i < exchanges.length; i++) {
if (exchanges[i].GetName() !== 'Futures_CTP') {
throw '只支持 CTP !请检查第 ' + i + ' 个账户'
throw '只支持 CTP !请检查第 ' + i + ' 个账户';
}
}
SetErrorFilter("not login|ready|初始化");
while (true) {
if (exchanges[0].IO("status")) {
data();
LogStatus("开盘时间,与交易服务器连接成功。")
LogStatus("与交易服务器连接成功");
} else {
LogStatus("\n警告! 与交易服务器连接断开", "#DF0101", "\n", "\n未登录状态或该交易所已经闭市。", "#DF0101");
}
@@ -150,4 +131,4 @@ https://www.fmz.com/strategy/79351
> 更新时间
2018-07-02 20:59:56
2018-12-20 14:35:11
@@ -0,0 +1,96 @@
> 策略名称
均线和高低点相对强弱策略|Relative Strength Strategy Based on Price
> 策略作者
littleDreamXX
> 策略描述
[trans]
- 策略名称:基于价格相对强的弱策略
- 数据周期:1H
- 支持:商品期货、数字货币、数字货币期货
- 官方网站:www.quant.la
![IMG](https://www.fmz.com/upload/asset/2e346e6e3b2edda65576ffe7d35e104b.png)
- 主图:
均线,公式: MAN^^MA(C,N);
- 副图:
无
||
- Strategy Name: Relative Strength Strategy Based on Price
- Data cycle: 1H
- Support: Commodity Futures, Digital Currency and Digital Currency Futures
![IMG](https://www.fmz.com/upload/asset/45096a9dbc8e6361219bd4957494ac60.png)
![IMG](https://www.fmz.com/upload/asset/bcf5916794bbc6d9e5e8332b6fa9798c.png)
- Main chart:
MA, formula: MAN^^MA(C,N);
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N|100|均线指标参数|MA index parameter|
|M|2|止损差价系数|stop loss difference coefficient|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-02-01 00:00:00
end: 2018-04-27 00:00:00
period: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","rb888",126961]]
*)
MAN^^MA(C,N);
B_MA:=C>MAN;
S_MA:=C<MAN;
S_K1:=SUM((H-C)*V,N)/SUM((H-L)*V,N)>0.5;
B_K1:=SUM((C-L)*V,N)/SUM((H-L)*V,N)>0.5;
CO:=IF(C>O,C-O,0);
OC:=IF(C<O,O-C,0);
S_K2:=SUM(OC*V,N)/SUM(ABS(C-O)*V,N)>0.5;
B_K2:=SUM(CO*V,N)/SUM(ABS(C-O)*V,N)>0.5;
B_K1 AND B_K2 AND B_MA AND H>=HHV(H,N),BPK;
S_K1 AND S_K2 AND S_MA AND L<=LLV(L,N),SPK;
STOPLOSS:=M*MA(H-L,N);
C<BKPRICE-STOPLOSS,SP(BKVOL);
C>SKPRICE+STOPLOSS,BP(SKVOL);
S_MA AND BKHIGH>BKPRICE+STOPLOSS,SP(BKVOL);
B_MA AND SKLOW<SKPRICE-STOPLOSS,BP(SKVOL);
```
> 策略出处
https://www.fmz.com/strategy/129078
> 更新时间
2018-12-18 10:25:23
@@ -1,56 +0,0 @@
> 策略名称
基于ATR波动率指标构建的通道策略
> 策略作者
Zero
> 策略描述
思路:通道自适应策略,固定止损+浮动止盈
适用软件:发明者最最化/文华财经
数据周期:多周期
数据合约:指数合约
交易合约:商品期货/数字货币
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-11-01 00:00:00
end: 2018-12-01 00:00:00
period: 1h
exchanges: [{"eid":"Futures_OKCoin","currency":"BTC_USD"}]
args: [["ContractType","this_week",126961]]
*)
SLOSS:=2;
N:=200;
M:=4;
X:UNIT;
TR1:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
ATR:=MA(TR1,N);
MAC:=MA(C,N);
UBAND:=MAC+M*ATR;
DBAND:=MAC-M*ATR;
H>=HHV(H,N),BPK;
L<=LLV(L,N),SPK;
(H>=HHV(H,M*N) OR C<=UBAND) AND BKHIGH>=BKPRICE*(1+M*SLOSS*0.01),SP;
(L<=LLV(L,M*N) OR C>=DBAND) AND SKLOW<=SKPRICE*(1-M*SLOSS*0.01),BP;
//止损
C>=SKPRICE*(1+SLOSS*0.01),BP;
C<=BKPRICE*(1-SLOSS*0.01),SP;
AUTOFILTER;
```
> 策略出处
https://www.fmz.com/strategy/127691
> 更新时间
2018-12-01 15:13:23
@@ -0,0 +1,76 @@
> 策略名称
基于ATR波动率指标构建的通道策略|Channel strategy based on ATR volatility indicator
> 策略作者
Zero
> 策略描述
[trans]
思路:通道自适应策略,固定止损+浮动止盈
适用软件:发明者最最化/文华财经
数据周期:多周期
数据合约:指数合约
交易合约:商品期货/数字货币
||
ATR, also known as Average true range, was invented by J. Welles Wilder. The ATR indicator is mainly used to measure the intensity of market volatility, that is, the indicator to show the market change rate.
This indicator is mainly used to measure price fluctuations.
It is important to remember that ATR does not provide an indication of price direction, just volatility.
This indicator is typical for long periods of sustained marginal movement, which usually occurs at the top of the market or during price consolidation. The principle of prediction according to this indicator can be expressed as: the higher the value of the indicator, the higher the possibility of the trend change; the lower the value of the indicator, the weaker the mobility of the trend.
Idea: channel adaptive strategy, fixed stop loss + floating take profit
Applicable software: FMZ Quant / webstock
Data cycle: multiple cycles
Data contract: index contract
Trading Contract: Commodity Futures /Digital Currency
[/trans]
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-11-01 00:00:00
end: 2018-12-01 00:00:00
period: 1h
exchanges: [{"eid":"Futures_BitMEX","currency":"XBT_USD"}]
args: [["ContractType","XBTUSD",126961]]
*)
SLOSS:=2;
N:=200;
M:=4;
TR1:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
ATR:=MA(TR1,N);
MAC:=MA(C,N);
UBAND^^MAC+M*ATR;
DBAND^^MAC-M*ATR;
NH^^HHV(H,N);
NL^^LLV(L,N);
H>=NH,BPK;
L<=NL,SPK;
(H>=HHV(H,M*N) OR C<=UBAND) AND BKHIGH>=BKPRICE*(1+M*SLOSS*0.01),SP;
(L<=LLV(L,M*N) OR C>=DBAND) AND SKLOW<=SKPRICE*(1-M*SLOSS*0.01),BP;
//止损 StopLoss
C>=SKPRICE*(1+SLOSS*0.01),BP;
C<=BKPRICE*(1-SLOSS*0.01),SP;
AUTOFILTER;
```
> 策略出处
https://www.fmz.com/strategy/127691
> 更新时间
2018-12-21 16:13:58
@@ -0,0 +1,91 @@
> 策略名称
基于ATR波动率指标构建的通道策略|Channel strategy based on ATR
> 策略作者
littleDreamXX
> 策略描述
[trans]
- 名称: 基于ATR波动率指标构建的通道策略
- 思路:通道自适应策略,固定止损+浮动止盈
- 数据周期:多周期
- OKEX期货
- 合约 : this_week 当周
- 官方网站:www.quant.la
![IMG](https://www.fmz.com/upload/asset/b2ebaacbe7dbb1bb45bb59ceb80dd37f.png)
- 主图:
画UBAND, 公式:UBAND^^MAC+M*ATR;
画DBAND, 公式:DBAND^^MAC-M*ATR;
- 副图:
无
||
- Strategy name: Channel strategy based on ATR volatility index
- Strategy idea: Channel Adaptive Strategy, Fixed Stop + Floating Stop
- Data Cycle: Multi-Cycle
![IMG](https://www.fmz.com/upload/asset/24c0c7b896060cf639540b56028e8d99.png)
![IMG](https://www.fmz.com/upload/asset/e403406e31b9a3ca04da6ce76e3abe2d.png)
- Main chart:
Draw UBAND, formula: UBAND ^^ MAC + MATR;
Draw DBAND, formula: DBAND ^^ MAC-MATR;
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|SLOSS|2|止损百分比|stop loss percentage|
|N|200|ATR指标参数|ATR index parameter|
|M|4|上下轨系数|upper and lower track coefficients|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-06-01 00:00:00
end: 2018-07-01 00:00:00
period: 1h
exchanges: [{"eid":"Futures_OKCoin","currency":"BTC_USD"}]
args: [["TradeAmount",10,126961],["ContractType","this_week",126961]]
*)
TR1:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
ATR:=MA(TR1,N);
MAC:=MA(C,N);
UBAND^^MAC+M*ATR;
DBAND^^MAC-M*ATR;
H>=HHV(H,N),BPK;
L<=LLV(L,N),SPK;
(H>=HHV(H,M*N) OR C<=UBAND) AND BKHIGH>=BKPRICE*(1+M*SLOSS*0.01),SP;
(L<=LLV(L,M*N) OR C>=DBAND) AND SKLOW<=SKPRICE*(1-M*SLOSS*0.01),BP;
// 止损
// stop loss
C>=SKPRICE*(1+SLOSS*0.01),BP;
C<=BKPRICE*(1-SLOSS*0.01),SP;
AUTOFILTER;
```
> 策略出处
https://www.fmz.com/strategy/128126
> 更新时间
2018-12-18 12:55:34
-110
View File
@@ -1,110 +0,0 @@
> 策略名称
多级止盈趋势策略
> 策略作者
littleDreamXX
> 策略描述
- 策略名称: 多级止盈趋势策略
- 数据周期:多周期
- 支持:商品期货、数字货币
- 官方网站:www.quant.la
![IMG](https://www.fmz.com/upload/asset/b8d89a704605b72bc44a56575a570bf6.png)
- 主图:
上线,公式 :UPPERLINE^^今开+BAND;
下线,公式 :LOWERLINE^^今开-BAND;
均线,公式 :均线^^MA(CLOSE,LENGTH);
- 副图:
无
> 策略参数
|参数|默认值|描述|
|----|----|----|
|LENGTH|200|均线指标参数|
|STOPRANGE|3|止损幅度|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-01-01 00:00:00
end: 2018-04-09 00:00:00
period: 1d
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
args: [["LENGTH",80]]
*)
STARTPER1:=5; //1级跟踪止盈,盈利5%启动
STOPPER1:=100; //1级跟踪止盈,盈利回撤100%触发
STARTPER2:=10; //2级跟踪止盈,盈利10%启动
STOPPER2:=50; //2级跟踪止盈,盈利回撤50%触发
STARTPER3:=20; //3级跟踪止盈,盈利20%启动
STOPPER3:=20; //3级跟踪止盈,盈利回撤20%触发
//上下区间
NN:=BARSLAST(DATE<>REF(DATE,1))+1;//今天开盘到目前为止的周期数
今开:=VALUEWHEN(NN=1,O);//当天的开盘价
今高:=HHV(H,NN);//今天全天的最高价
今低:=LLV(L,NN);//今天全天的最低价
昨高:=REF(今高,NN);//昨天全天的最高价
昨低:=REF(今低,NN);//昨天全天的最低价
BAND:=昨高-昨低;
UPPERLINE^^今开+BAND;
LOWERLINE^^今开-BAND;
//均线
均线^^MA(CLOSE,LENGTH);
//开平仓条件
卖开条件: = C<LOWERLINE AND LOWERLINE<均线;
买开条件: = C>UPPERLINE AND UPPERLINE>均线;
买平空单: = C>UPPERLINE OR C>均线;
卖平多单: = C<LOWERLINE OR C<均线;
//程序主体
//开仓
卖开条件,SK;
买开条件,BK;
//平仓
卖平多单,SP;
买平空单,BP;
//止盈
SKLOW<=SKPRICE*(1-0.01*STARTPER3) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER3,BP;//最大盈利达到"STARTPER3"%之后盈利回撤"STOPPER3"%,平空
BKHIGH>=BKPRICE*(1+0.01*STARTPER3) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER3,SP;//最大盈利达到"STARTPER3"%之后盈利回撤"STOPPER3"%,平多
SKLOW<=SKPRICE*(1-0.01*STARTPER2) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER2,BP;//最大盈利达到"STARTPER2"%之后盈利回撤"STOPPER2"%,平空
BKHIGH>=BKPRICE*(1+0.01*STARTPER2) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER2,SP;//最大盈利达到"STARTPER2"%之后盈利回撤"STOPPER2"%,平多
SKLOW<=SKPRICE*(1-0.01*STARTPER1) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER1,BP;//最大盈利达到"STARTPER1"%之后盈利回撤"STOPPER1"%,平空
BKHIGH>=BKPRICE*(1+0.01*STARTPER1) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER1,SP;//最大盈利达到"STARTPER1"%之后盈利回撤"STOPPER1"%,平多
//止损
C>=SKPRICE*(1+STOPRANGE*0.01),BP;//空头止损
C<=BKPRICE*(1-STOPRANGE*0.01),SP;//多头止损
SETSIGPRICETYPE(BK,NEW_ORDER);
SETSIGPRICETYPE(SK,NEW_ORDER);
SETSIGPRICETYPE(BP,NEW_ORDER);
SETSIGPRICETYPE(SP,NEW_ORDER);
AUTOFILTER;
```
> 策略出处
https://www.fmz.com/strategy/128122
> 更新时间
2018-12-03 11:41:22
@@ -0,0 +1,157 @@
> 策略名称
多级止盈趋势策略|Multilevel Take Profit Strategy
> 策略作者
littleDreamXX
> 策略描述
[trans]
- 策略名称: 多级止盈趋势策略
- 数据周期:多周期
- 支持:商品期货、数字货币
- 官方网站:www.quant.la
![IMG](https://www.fmz.com/upload/asset/b8d89a704605b72bc44a56575a570bf6.png)
- 主图:
上线,公式 :UPPERLINE^^今开+BAND;
下线,公式 :LOWERLINE^^今开-BAND;
均线,公式 :均线^^MA(CLOSE,LENGTH);
- 副图:
无
||
- Strategy Name: Multilevel Take Profit Strategy
- Data Cycle: Multi-Cycle
- Support: Commodity Futures, Digital Currency
![IMG](https://www.fmz.com/upload/asset/f5eedaf080c1616d41426efe01b6861d.png)
![IMG](https://www.fmz.com/upload/asset/4f6ef3c138dfb6a669dcda326222520b.png)
- Main chart:
Upper line, formula:UPPERLINE^^TODAYOPEN+BAND;
Lower line, formula:LOWERLINE^^TODAYOPEN-BAND;
MA, formula:MALINE^^MA(CLOSE,LENGTH);
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|LENGTH|200|均线指标参数|MA index parameter|
|STOPRANGE|3|止损幅度|stop loss range|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-01-01 00:00:00
end: 2018-04-09 00:00:00
period: 1d
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
args: [["LENGTH",80]]
*)
STARTPER1:=5; // 1级跟踪止盈,盈利5%启动
// 1 level tracking take profit, if profit 5% then start
STOPPER1:=100; // 1级跟踪止盈,盈利回撤100%触发
// 1 level tracking take profit, if profit retracement is 100% then trigger
STARTPER2:=10; // 2级跟踪止盈,盈利10%启动
// 2 level tracking take profit, if profit 10% then start
STOPPER2:=50; // 2级跟踪止盈,盈利回撤50%触发
// 2 level tracking take profit, if profit retracement is 50% then trigger
STARTPER3:=20; // 3级跟踪止盈,盈利20%启动
// 3 level tracking take profit, if profit 20% then start
STOPPER3:=20; // 3级跟踪止盈,盈利回撤20%触发
// 3 level tracking take profit, if profit retracement is 20% then trigger
// 上下区间
// Upper and lower intervals
NN:=BARSLAST(DATE<>REF(DATE,1))+1; // 今天开盘到目前为止的周期数
// The number of cycles since the opening today
TODAYOPEN:=VALUEWHEN(NN=1,O); // 当天的开盘价
// Opening price of the day
TODAYHIGH:=HHV(H,NN); // 今天全天的最高价,today’s highest price
TODAYLOW:=LLV(L,NN); // 今天全天的最低价,today’s lowest price
YESTDAYHIGH:=REF(TODAYHIGH,NN); // 昨天全天的最高价,yesterday's highest price
YESTDAYLOW:=REF(TODAYLOW,NN); // 昨天全天的最低价,yesterday's lowest price
BAND:=YESTDAYHIGH-YESTDAYLOW;
UPPERLINE^^TODAYOPEN+BAND;
LOWERLINE^^TODAYOPEN-BAND;
//均线
// MA
MALINE^^MA(CLOSE,LENGTH);
//开平仓条件
// When to open and close position
SKCOND: = C<LOWERLINE AND LOWERLINE<MALINE;
BKCOND: = C>UPPERLINE AND UPPERLINE>MALINE;
BPSHORT: = C>UPPERLINE OR C>MALINE;
SPLONG: = C<LOWERLINE OR C<MALINE;
//程序主体
//the mainbody of program
//开仓
//open position
SKCOND,SK;
BKCOND,BK;
//平仓
//close position
SPLONG,SP;
BPSHORT,BP;
//止盈
//take profit
SKLOW<=SKPRICE*(1-0.01*STARTPER3) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER3,BP;// 最大盈利达到"STARTPER3"%之后盈利回撤"STOPPER3"%,平空
// If profit get “STARTPER3”% and profit retracement get “STOPPER3”%, then close short position
BKHIGH>=BKPRICE*(1+0.01*STARTPER3) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER3,SP;// 最大盈利达到"STARTPER3"%之后盈利回撤"STOPPER3"%,平多
// If profit get “STARTPER3”% and profit retracement get “STOPPER3”%, then close long position
SKLOW<=SKPRICE*(1-0.01*STARTPER2) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER2,BP; // 最大盈利达到"STARTPER2"%之后盈利回撤"STOPPER2"%,平空
// If profit get “STARTPER2”% and profit retracement get “STOPPER2”%, then close short position
BKHIGH>=BKPRICE*(1+0.01*STARTPER2) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER2,SP;// 最大盈利达到"STARTPER2"%之后盈利回撤"STOPPER2"%,平多
// If profit get “STARTPER2”% and profit retracement get “STOPPER2”%, then close long position
SKLOW<=SKPRICE*(1-0.01*STARTPER1) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER1,BP;// 最大盈利达到"STARTPER1"%之后盈利回撤"STOPPER1"%,平空
// If profit get “STARTPER1”% and profit retracement get “STOPPER1”%, then close short position
BKHIGH>=BKPRICE*(1+0.01*STARTPER1) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER1,SP;// 最大盈利达到"STARTPER1"%之后盈利回撤"STOPPER1"%,平多
// If profit get “STARTPER1”% and profit retracement get “STOPPER1”%, then close long position
//止损
//stop loss
C>=SKPRICE*(1+STOPRANGE*0.01),BP;
C<=BKPRICE*(1-STOPRANGE*0.01),SP;
AUTOFILTER;
```
> 策略出处
https://www.fmz.com/strategy/128122
> 更新时间
2018-12-15 18:44:14
@@ -1,7 +1,7 @@
> 策略名称
开收盘均价差ATR策略
开收盘均价差ATR策略|The average of difference - combined with ATR
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略进场:开盘价和收盘价均价差决定趋势,与ATR结合,进场点也是反向出场点;
- 策略出场:开仓就定好止损点,趋势转向出场;
- 数据周期:日线
@@ -26,14 +27,36 @@ littleDreamXX
![IMG](https://www.fmz.com/upload/asset/ab8d909c6464234b06ef1f116a4de200.png)
||
- Enter: The average of difference of opening price minus closing price determines the trend combined with ATR,
the entry point is also the exit point in reverse;
- Exit: Stop-loss point should be fixed at the opening of the position,
and if there is a reverse trend in price, close the position.
- Data Cycle: 1 Day
- Data contract: index contract
- Transaction contract: main contract
![IMG](https://www.fmz.com/upload/asset/0472d059ecdceca56fc7baaf5ff79deb.png)
![IMG](https://www.fmz.com/upload/asset/aa2ad84ec198efe3c4d6afdd25753f3b.png)
- Main chart:
none
- Secondary chart:
ATR, formula ATR ^^ MA (TR, N);
C_O, formula C_O: EMA (C, N) - EMA (O, N);
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N|20|ATR指标参数|
|M|5|BAND系数|
|N|20|ATR指标参数|ATR index parameter|
|M|5|BAND系数|BAND coefficient|
> 源码 (麦语言)
@@ -47,6 +70,8 @@ exchanges: [{"eid":"Futures_CTP","currency":"FUTURES","balance":20000}]
*)
// 变量
// variable
LOTS:=MAX(1,INTPART(MONEYTOT/(O*UNIT*0.1)));
C_O:EMA(C,N)-EMA(O,N);
B:=CROSSUP(C_O,0);
@@ -60,10 +85,12 @@ PRICE_SPK:=VALUEWHEN(S,L-BAND);
PRICE_BP:=VALUEWHEN(S,H+BAND);
// 策略逻辑
// strategy logic
BARPOS>N AND C_O>0 AND C>=PRICE_BPK,BPK(LOTS);
BARPOS>N AND C_O<0 AND C<=PRICE_SPK,SPK(LOTS);
// 下单
// place an order
S,SP(BKVOL);
B,BP(SKVOL);
@@ -77,4 +104,4 @@ https://www.fmz.com/strategy/128136
> 更新时间
2018-12-03 11:42:38
2018-12-15 15:43:24
@@ -1,7 +1,7 @@
> 策略名称
抛物线转向SAR与价格高低点策略
抛物线转向SAR与价格高低点策略|SAR and Price High and Low Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:SAR和价格高低点策略
- 数据周期:1H等
- 策略支持:商品期货、数字货币现货,数字货币期货
@@ -16,16 +17,27 @@ littleDreamXX
![IMG](https://www.fmz.com/upload/asset/4d9459b9af47702f7c2c6666212927c7.png)
||
- Strategy Name: SAR and Price High and Low Strategy
- Data cycle: 1H, etc.
- Strategic Support: Commodity Futures, Digital Currency Spot, Digital Currency Futures
![IMG](https://www.fmz.com/upload/asset/ca979cacba242461b34f320a71c2a1a9.png)
![IMG](https://www.fmz.com/upload/asset/89ed32f65277b4b1dc6d9d420508dfcd.png)
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|SLOSS|2|止损止盈百分比|
|N|60|收盘价高低点周期|
|IsCryptoCurrency|0|选择用于商品期货或者数字货币: 商品期货|数字货币现货|数字货币期货|
|CryptoCurrencyTradeAmount|true|用于数字货币市场时的每次交易下单量|
|SLOSS|2|止损止盈百分比|stop loss percentage and take profit percentage|
|N|60|收盘价高低点周期|cycle of closing price's high and low point|
|IsCryptoCurrency|0|选择用于商品期货或者数字货币|Choose for commodity futures or digital currency: 商品期货|Commodity Futures||数字货币现货|Digital Currency Spot||数字货币期货|Digital Currency Futures|
|CryptoCurrencyTradeAmount|true|用于数字货币市场时的每次交易下单量|Order quantity per transaction used in the digital currency market|
> 源码 (麦语言)
@@ -39,11 +51,6 @@ exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["IsCryptoCurrency",2],["ContractType","rb888",126961]]
*)
// 参数
// N:=60;
// SLOSS:=2;
// FUND:=20000;
LOTS:=IF(IsCryptoCurrency, IF(IsCryptoCurrency=1, CryptoCurrencyTradeAmount, MAX(1, INTPART(CryptoCurrencyTradeAmount))), MAX(1,INTPART(MONEYTOT/(O*UNIT*0.1))));
SARLINE:=SAR(4,2,20);
@@ -72,4 +79,4 @@ https://www.fmz.com/strategy/128251
> 更新时间
2018-12-05 18:14:25
2018-12-17 15:40:03
@@ -1,7 +1,7 @@
> 策略名称
日本云图简化版策略
日本云图简化版策略|Simplified Version of ICHIMOKU KINKO HYO Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:日本云图简化版策略
- 支持:商品期货
- 适用周期:多周期
@@ -22,16 +23,34 @@ littleDreamXX
- 副图:
无
||
- Strategy Name: Simplified Version of ICHIMOKU KINKO HYO Strategy
- Support: Commodity Futures
- Applicable cycle: multi-cycle
![IMG](https://www.fmz.com/upload/asset/6f4c8ca3330841b05f7fb0fcf311f7e0.png)
![IMG](https://www.fmz.com/upload/asset/bb88fe6d9191768a71c29361ed5cc0f3.png)
![IMG](https://www.fmz.com/upload/asset/1ce2e5d93a05cb49c0bd9a7113deeb0c.png)
- Main chart:
none
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N1|10|收盘价周期1|
|N4|177|收盘价周期2|
|N2|41|开盘价周期1|
|N3|52|开盘价周期2|
|N1|10|收盘价周期1|closing price Cycle 1|
|N4|177|收盘价周期2|closing price Cycle 2|
|N2|41|开盘价周期1|opening price cycle 1|
|N3|52|开盘价周期2|opening price cycle 2|
> 源码 (麦语言)
@@ -45,14 +64,17 @@ exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*)
//交易条件
//Trading terms
CONDITION1:=REF(CLOSE,1) > REF(CLOSE,N1) AND REF(CLOSE,8) > REF(CLOSE,N4) AND CLOSE > OPEN AND REF(CLOSE,137)>REF(OPEN,N2) AND CLOSE > REF(OPEN,N3);
CONDITION2:=REF(CLOSE,1) < REF(CLOSE,N1) AND REF(CLOSE,8) < REF(CLOSE,N4) AND CLOSE < OPEN AND REF(CLOSE,137)<REF(OPEN,N2) AND CLOSE < REF(OPEN,N3);
//交易系统
//Trading system
CONDITION1,BPK;
CONDITION2,SPK;
//过滤函数
//Filter function
AUTOFILTER;
```
@@ -62,4 +84,4 @@ https://www.fmz.com/strategy/129083
> 更新时间
2018-12-07 10:48:01
2018-12-17 18:41:44
@@ -1,7 +1,7 @@
> 策略名称
标准差价格通道策略
标准差价格通道策略|Standard deviation price channel strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 数据周期:30分钟左右
- 支持 数字货币现货、数字货币期货
- 支持 商品期货,适合品种:热卷、焦炭、豆粕、郑醇、沪镍、郑油、聚丙烯、螺纹、橡胶、锰硅、PTA、豆油
@@ -28,14 +29,38 @@ littleDreamXX
标准差,公式:STDS:STD(C,10);
标准差,公式:STDL:STD(C,60);
||
- Data cycle: about 30 minutes
- Support: Digital Currency Spot, Digital currency Futures
- Support: Commodity futures
- Digital Currency backtest:
![IMG](https://www.fmz.com/upload/asset/d5830a58e1b3aca111849d77173ac822.png)
![IMG](https://www.fmz.com/upload/asset/5bbb1e2f4030ce3116263aa6a65a4be9.png)
![IMG](https://www.fmz.com/upload/asset/e5a726a2bfe6570c06dd043c9ee5545c.png)
- Main chart:
upper line, formula: UPPERBAND^^AVGVALUE + SHIFTVALUE;
lower line, formula: LOWERBAND^^AVGVALUE - SHIFTVALUE;
- Secondary chart:
standard deviation, formula: STDS: STD (C, 10);
standard deviation, formula: STDL: STD (C, 60);
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|STOPRANGE|true|止损幅度|
|N|20|均线参数|
|STOPRANGE|true|止损幅度|Stop loss range|
|N|20|均线参数|average line index|
> 源码 (麦语言)
@@ -52,8 +77,11 @@ args: [["ContractType","this_week",126961]]
TPRICE:=(HIGH+LOW+OPEN+CLOSE)/4;
AVGVALUE:=MA(TPRICE,N);
//求最高价减去最低价,一个周期前的收盘价减去最高价的绝对值,一个周期前的收盘价减去最低价的绝对值,这三个值中的最大值
// Find the maximum of these three values: highest price minus lowest price, the absolute value of (closing price a cycle ago minus the highest price), the absolute value of (closing price a cycle ago minus the lowest price)
TR:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
SHIFTVALUE:=MA(TR,N);//求N个周期内的TR的简单移动平均
SHIFTVALUE:=MA(TR,N); // 求N个周期内的TR的简单移动平均
// Find the simple moving average of TR in N cycles
UPPERBAND^^AVGVALUE + SHIFTVALUE;
LOWERBAND^^AVGVALUE - SHIFTVALUE;
STDS:STD(C,10);
@@ -65,6 +93,8 @@ BKVOL>0 AND BKHIGH-BKPRICE>=0.2*CLOSE AND C<LOWERBAND,SP;
SKVOL>0 AND SKPRICE-SKLOW>=0.2*CLOSE AND C>UPPERBAND,BP;
//止损
//Stop loss
C>=SKPRICE*(1+STOPRANGE*0.01),BP;
C<=BKPRICE*(1-STOPRANGE*0.01),SP;
@@ -77,4 +107,4 @@ https://www.fmz.com/strategy/128121
> 更新时间
2018-12-05 10:53:14
2018-12-15 15:41:45
@@ -1,7 +1,7 @@
> 策略名称
波动率ATR轨道突破策略
波动率ATR轨道突破策略|Volatility ATR - Track Breakthrough Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 公式名称:波动率轨道突破策略
- 数据周期:15M,30M等
- 支持:商品期货、数字货币现货、数字货币期货
@@ -25,15 +26,34 @@ littleDreamXX
- 副图:
波动率,公式:ATR:=MA(TR,LENGTH2);
||
- Strategy name: Volatility ATR Track Breakthrough Strategy
- Data Cycle: 15M, 30M, etc.
- Support: Commodity Futures, Digital Currency Spot, Digital Currency Futures
![IMG](https://www.fmz.com/upload/asset/3ab48b24790ffa7df8578da42ee9890d.png)
![IMG](https://www.fmz.com/upload/asset/26254e88d3af8327dc70f9e4d0797b88.png)
- Main chart:
medium track, formula: MIDLINE ^^ MA ((H + L + C) / 3, LENGTH1);
up track, formula: UPBAND ^^ MIDLINE + NATR;
low track, formula: DOWNBAND ^ ^ MIDLINE - NATR;
- Secondary chart:
Volatility, formula: ATR:= MA (TR, LENGTH2);
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|LENGTH2|100|ATR指标参数|
|LENGTH1|300|均线指标参数|
|N|2|上下轨系数|
|LENGTH2|100|ATR指标参数|ATR index parameter|
|LENGTH1|300|均线指标参数|MA index parameter|
|N|2|上下轨系数|Upper and lower track coefficients|
> 源码 (麦语言)
@@ -69,4 +89,4 @@ https://www.fmz.com/strategy/128252
> 更新时间
2018-12-05 17:17:26
2018-12-17 16:18:06
+175
View File
@@ -0,0 +1,175 @@
> 策略名称
测试火币macd金叉
> 策略作者
量化新人
> 策略参数
|参数|默认值|描述|
|----|----|----|
|FastPeriod|5|入市快线周期|
|SlowPeriod|15|入市慢线周期|
|EnterPeriod|false|入市观察期|
|ExitFastPeriod|7|离市快线周期|
|ExitSlowPeriod|15|离市慢线周期|
|ExitPeriod|false|离市观察期|
|PositionRatio|0.8|仓位比例|
|Interval|10|轮询周期(秒)|
> 源码 (javascript)
``` javascript
function adjustFloat(v) {
return Math.floor(v*100)/100;
}
function CancelPendingOrders() {
while (true) {
var orders = null;
while (!(orders = exchange.GetOrders())) {
Sleep(Interval);
}
if (orders.length == 0) {
return;
}
for (var j = 0; j < orders.length; j++) {
exchange.CancelOrder(orders[j].Id, orders[j]);
if (j < (orders.length-1)) {
Sleep(Interval);
}
}
}
}
var records=[]
function MACD_Cross() { //检测MACD指标,交叉状态的函数
records = exchange.GetRecords(); //获取K线数据
while (!records && records.length < 45) { //K线数据不能为null,要大于45个柱,不符合标准 循环获取直到符合
records = exchange.GetRecords();
// Log("Sleep");
Sleep(1000);
}
// Log(records);
var macd = TA.MACD(records, 12, 26, 9); //调用指标函数, 参数为MACD 默认的参数。
// var ma5 = TA.MA(records,5);
// var ma25 = TA.MA(records, 25);
// var ma125 = TA.MA(records, 125);
// var ma250 = TA.MA(records, 250);
var dif = macd[0]; //dif线
var dea = macd[1]; //dea线
var macd = macd[2]; // MACD柱
var len = records.length; //K线周期长度
// ma30[len-1]<ma10[len-1] && ma10[len-1]<ma5[len-1]
// 判断当前涨幅 ((records[len-1].Close-records[len-1].Open)/records[len-1].Open) >0.02
if (dif[len - 1] > dea[len - 1] && dif[len - 2] < dea[len - 2] ) {
return 1;
// Log("买入",records[len-1].Time)
}
//macd[len-2]<macd[len-3]||
if ((dif[len - 1] < dea[len - 1] && dif[len - 2] > dea[len - 2])) {
// Log("卖出",records[len-1].Time)
return 2;
}
return 0;
}
function updateProfit(accountInit, accountNow, price) {
var netNow = accountNow.Balance + accountNow.FrozenBalance + ((accountNow.Stocks + accountNow.FrozenStocks) * price);
var netInit = accountInit.Balance + accountInit.FrozenBalance + ((accountInit.Stocks + accountInit.FrozenStocks) * initTicker.Buy);
LogProfit(adjustFloat(netNow - netInit));
}
var initTicker =null;
function main() {
var initAccount = exchange.GetAccount();
initTicker= exchange.GetTicker();
Log(initAccount);
var buyPrice = 0;
var sellPrice = 0;
var buyFlag = true;
var sellFlag = false;
// 如果策略临时中断重启了,此时已经买到币了就要考虑卖出了
// if(initAccount.Stocks>=1){
// sellFlag = true
// buyFlag = false
// }
var earn = 0;
var totalEarn =0 ;
while (true) {
CancelPendingOrders()
var ma = MACD_Cross();
var ticker = exchange.GetTicker();
var depth = exchange.GetDepth();
var price = 0;
var amount = 0;
var cost = 0;
var nowAccount = exchange.GetAccount()
if (ma == 1&&buyFlag) {
buyFlag = false;
sellFlag = true;
price = depth.Asks[0].Price;
amount = depth.Asks[0].Amount;
// cost = price*amount * 0.002
buyPrice = price;
// Log("买前当前账户:",nowAccount,"买价格:",buyPrice+"->@量->",0.1);
// 买的时候扣除的是 币的个数
var realBuy = _N((nowAccount.Balance/buyPrice)*(1-0.002),2)
exchange.Buy(buyPrice,realBuy);
nowAccount = exchange.GetAccount()
// Log("买后当前账户:",nowAccount,"买价格:",buyPrice+"->@量->",0.1);
// exchange.Log(LOG_TYPE_BUY, 123, 1,1);
Log("买入时间",new Date(records[records.length-1].Time).toLocaleTimeString())
// Log("买入时间",new Date(records[records.length-1].Time).toLocalTimeString())
// Log("买入时间",new Date(records[records.length-1].Time).toLocalString())
} else if(ma==2&&sellFlag) {
sellFlag = false;
buyFlag = true;
price = depth.Bids[0].Price;
amount = depth.Bids[0].Amount;
sellPrice = price ;
// cost = price*amount * 0.002
earn = ((sellPrice - buyPrice) / buyPrice) *100
totalEarn+=earn;
Log("卖出时间,",new Date(records[records.length-1].Time).toLocaleTimeString(),"当前收益:"+earn.toFixed(2)+"总收益:"+totalEarn.toFixed(2)+"%@");
// Log("卖前当前账户:",nowAccount,"卖价格:",sellPrice,"->@当前收益",earn.toFixed(2))
exchange.Sell(sellPrice,_N(nowAccount.Stocks,2))
// exchange.Log(LOG_TYPE_SELL, 123, 1,1);
nowAccount = exchange.GetAccount()
// Log("卖后当前账户:",nowAccount,"卖价格:",sellPrice,"->@量->",nowAccount.Stocks)
updateProfit(initAccount,nowAccount,price)
}else{
// LogProfit(0);
}
Sleep(5*1000);
}
}
```
> 策略出处
https://www.fmz.com/strategy/92839
> 更新时间
2018-12-23 14:04:05
@@ -0,0 +1,113 @@
> 策略名称
混沌操作法策略|Trading Chaos Strategy
> 策略作者
littleDreamXX
> 策略描述
[trans]
- 策略名称:混沌操作法策略
- 支持:商品期货 , 数字货币, 数字货币期货
- 使用周期:日线
- 官方网站:www.quant.la
![IMG](https://www.fmz.com/upload/asset/a740c3a88fe1e0accb0c6a77fb11721c.png)
- 主图:
Y线,公式:Y^^SMA(REF(HL,N3),N4,1);
YRG最大,公式:MAX_YRG^^MAX(MAX(Y,R),G);
YRG最小,公式:MIN_YRG^^MIN(MIN(Y,R),G);
TOP_FRACTAL,公式:TOP_FRACTAL^^VALUEWHEN(H>=MAX_YRG,TOP);
BOTTOM_FRACTAL,公式:BOTTOM_FRACTAL^^VALUEWHEN(L<=MIN_YRG,BOTTOM);
- 副图:
无
||
- Strategy Name: Trading Chaos Strategy
- Support: Commodity Futures, Digital Currency, Digital Currency Futures
- Cycle: Daily
![IMG](https://www.fmz.com/upload/asset/a0b8ae48baf0cb4acb6b5e85c0d34e28.png)
![IMG](https://www.fmz.com/upload/asset/5011913cd4b40176810ca8ce3067f0d3.png)
- Main chart:
Y line, formula: Y ^^ SMA (REF (HL, N3), N4, 1);
YRG maximum, formula: MAX_YRG^^ MAX (MAX (Y, R), G);
YRG minimum, formula: MIN_YRG^^^ MIN (MIN (Y, R), G);
TOP_FRACTAL, formula: TOP_FRACTAL^^^ VALUEWHEN (H >= MAX_YRG, TOP);
BOTTOM_FRACTAL, formula: BOTTOM_FRACTAL^^^ VALUEWHEN (L<=MIN_YRG, BOTTOM);
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N1|3|参数N1|parameter N1|
|N2|5|参数N2|parameter N2|
> 源码 (麦语言)
``` pascal
(*backtest
start: 2018-11-13 00:00:00
end: 2018-12-13 00:00:00
period: 1h
exchanges: [{"eid":"Huobi","currency":"BTC_USDT","balance":10000,"stocks":3}]
*)
N3:=N1+N2;
N4:=N2+N3;
HL:=(H+L)/2;
Y^^SMA(REF(HL,N3),N4,1);
R:=SMA(REF(HL,N2),N3,1);
G:=SMA(REF(HL,N1),N2,1);
TOP_N:=BARSLAST(REF(H,2)=HHV(H,5))+2;
BOTTOM_N:=BARSLAST(REF(L,2)=LLV(L,5))+2;
TOP:=REF(H,TOP_N);
BOTTOM:=REF(L,BOTTOM_N);
MAX_YRG^^MAX(MAX(Y,R),G);
MIN_YRG^^MIN(MIN(Y,R),G);
TOP_FRACTAL^^VALUEWHEN(H>=MAX_YRG,TOP);
BOTTOM_FRACTAL^^VALUEWHEN(L<=MIN_YRG,BOTTOM);
BKVOL=0 AND C>=TOP_FRACTAL AND TOP_FRACTAL>MAX_YRG,BPK;
SKVOL=0 AND C<=BOTTOM_FRACTAL AND BOTTOM_FRACTAL<MIN_YRG,SPK;
C<Y,SP(BKVOL);
C>Y,BP(SKVOL);
```
> 策略出处
https://www.fmz.com/strategy/129077
> 更新时间
2018-12-18 10:26:10
@@ -1,7 +1,7 @@
> 策略名称
瀑布线策略
瀑布线策略|PBX Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:瀑布线PUBU交易策略
- 数据周期:15M
- 支持:商品期货
@@ -21,15 +22,31 @@ littleDreamXX
瀑布线2,公式:PUBU2^^(EMA(C,N2)+EMA(C,N2*2)+EMA(C,N2*4))/3;
瀑布线3,公式:PUBU3^^(EMA(C,N3)+EMA(C,N3*2)+EMA(C,N3*4))/3;
||
- Strategy Name: PBX Strategy
- Data cycle: 15M
- Support: Commodity Futures
![IMG](https://www.fmz.com/upload/asset/7a091a85a4f8af0a587ebd533b70145e.png)
![IMG](https://www.fmz.com/upload/asset/151864a4e277271e6e9dce13515a0b4a.png)
- Main chart:
PBX1,formula:PUBU1^^(EMA(C,N1)+EMA(C,N12)+EMA(C,N14))/3;
PBX2,formula:PUBU2^^(EMA(C,N2)+EMA(C,N22)+EMA(C,N24))/3;
PBX3,formula:PUBU3^^(EMA(C,N3)+EMA(C,N32)+EMA(C,N34))/3;
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N1|20|瀑布线1参数|
|N2|50|瀑布线2参数|
|N3|70|瀑布线3参数|
|N1|20|瀑布线1参数|PBX1 parameter|
|N2|50|瀑布线2参数|PBX2 parameter|
|N3|70|瀑布线3参数|PBX3 parameter|
> 源码 (麦语言)
@@ -44,6 +61,7 @@ args: [["TradeAmount",10,126961],["ContractType","quarter",126961]]
*)
// 指标
// index
PUBU1^^(EMA(C,N1)+EMA(C,N1*2)+EMA(C,N1*4))/3;
PUBU2^^(EMA(C,N2)+EMA(C,N2*2)+EMA(C,N2*4))/3;
PUBU3^^(EMA(C,N3)+EMA(C,N3*2)+EMA(C,N3*4))/3;
@@ -64,4 +82,4 @@ https://www.fmz.com/strategy/128420
> 更新时间
2018-12-04 21:24:04
2018-12-17 17:54:10
@@ -1,7 +1,7 @@
> 策略名称
高低点与波动率ROC指标策略
高低点与波动率ROC指标策略|Price high and low - ROC index strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:高低点与波动率ROC指标策略
- 数据周期:15M等
- 支持:商品期货
@@ -24,15 +25,33 @@ littleDreamXX
- 副图:
ARC指标, 公式:ARC:SMA(RC,M,1);
||
- Strategy Name: Price high and low - ROC index strategy
- Data cycle: 15M, etc.
- Support: Commodity Futures
![IMG](https://www.fmz.com/upload/asset/b2adb08374654bb533bed3f55e502592.png)
![IMG](https://www.fmz.com/upload/asset/b10e5232882a919868802de72ba6f613.png)
- Main chart:
The highest price of N cycle, formula: HH ^^ HHV (H, N);
The lowest price of N cycle, formula: LL ^^ LLV (L, N);
- Secondary chart:
ARC index, formula: ARC: SMA (RC, M, 1);
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N|200|高低点周期参数|
|SLOSS|true|止损百分比|
|M|50|ARC参数|
|N|200|高低点周期参数|high and low cycle parameter|
|SLOSS|true|止损百分比|stop loss percentage|
|M|50|ARC参数|ARC index|
> 源码 (麦语言)
@@ -73,4 +92,4 @@ https://www.fmz.com/strategy/128417
> 更新时间
2018-12-04 22:06:21
2018-12-17 16:58:17
@@ -1,7 +1,7 @@
> 策略名称
高低点突破成交量指数加权策略
高低点突破成交量指数加权策略|Break High and Low - Volume Index Weighting Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:高低点突破成交量指数加权策略
- 数据周期:多周期
- 回测可以选择 OKEX期货
@@ -23,16 +24,33 @@ littleDreamXX
- 副图
VJQ, 计算公式: VJQ:EMA(V*(C-REF(C,NC)),N);//定义成交量加权指数为VJQ
||
- Data cycle: multiple cycles
- Backtest can choose OKEX futures
- Contract: this_week contract
![IMG](https://www.fmz.com/upload/asset/7ba0592df29f0e159c4d6f090c893339.png)
![IMG](https://www.fmz.com/upload/asset/7f9acd992f46482e5709402ae85abd77.png)
- Main chart:
none
- Secondary chart:
VJQ, calculation formula: VJQ: EMA (V* (C-REF (C, NC)), N)
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|SLOSS|2|止损百分比|
|N|300|EMA指标参数|
|NC|50|多少个周期前的收盘价|
|MINAMOUNT|true|最少一次下单数量|
|SLOSS|2|止损百分比|percentage of stop loss|
|N|300|EMA指标参数|EMA index parameter|
|NC|50|多少个周期前的收盘价|closing price of how many cycles ago|
|MINAMOUNT|true|最少一次下单数量|minimum order quantity at a time|
> 源码 (麦语言)
@@ -47,23 +65,26 @@ args: [["N",100],["MINAMOUNT",10],["TradeAmount",10,126961],["ContractType","thi
*)
LOTS:=MAX(MINAMOUNT,INTPART(MONEYTOT/O * 0.8));
VJQ:EMA(V*(C-REF(C,NC)),N);//定义成交量加权指数为VJQ
B:=VJQ>0;//定义多头势
S:=VJQ<0;//定义空头势
VJQ:EMA(V*(C-REF(C,NC)),N);
B:=VJQ>0;
S:=VJQ<0;
BUYPK:=BARPOS>N AND BKVOL=0 AND B AND H>=HHV(H,N);
SELLPK:=BARPOS>N AND SKVOL=0 AND S AND L<=LLV(L,N);
BUYP:=SKVOL>0 AND B;
SELLP:=BKVOL>0 AND S;
//入场
// 入场
// Enter
SELLPK,SPK(LOTS);
BUYPK,BPK(LOTS);
//出场
// 出场
// Leave
BUYP,BP(SKVOL);
SELLP,SP(BKVOL);
//止损
// 止损
// Stop loss
C>=SKPRICE*(1+SLOSS*0.01),BP(SKVOL);
C<=BKPRICE*(1-SLOSS*0.01),SP(BKVOL);
AUTOFILTER;
@@ -75,4 +96,4 @@ https://www.fmz.com/strategy/128125
> 更新时间
2018-12-05 10:57:07
2018-12-15 15:42:32
@@ -1,7 +1,7 @@
> 策略名称
高胜率ORB交易策略
高胜率ORB交易策略|High Winning Rate - ORB Trading Strategy
> 策略作者
@@ -9,6 +9,7 @@ littleDreamXX
> 策略描述
[trans]
- 策略名称:高胜率ORB交易策略
- 数据周期:日K
- 支持:商品期货
@@ -27,13 +28,34 @@ littleDreamXX
- 副图:
无
||
- Policy Name: High Winning Rate - ORB Trading Strategy
- Data Cycle: Daily
- Support: Commodity Futures
![IMG](https://www.fmz.com/upload/asset/5af37a668117bf82ffd3270e6792752f.png)
![IMG](https://www.fmz.com/upload/asset/bdafbb088fd859227800705a1c16edca.png)
- Main chart:
MA, formula: MAC ^^ MA (CLOSE, LENGTH);
MA of highest price, formula: MA_HH^^ MA (HHHV (HIGH, LENGTH), LENGTH;
MA of lowest price, formula: MA_LL^^ MA (LLV (LOW, LENGTH), LENGTH;
Upper track, formula: UPBAND ^^ O_TODAY + BAND;
Lower track, formula: DOWNBAND ^^ O_TODAY-BAND;
- Secondary chart:
none
[/trans]
> 策略参数
|参数|默认值|描述|
|----|----|----|
|N_DAY|10|N日周期|
|N_DAY|10|N日周期|N day cycle|
> 源码 (麦语言)
@@ -86,4 +108,4 @@ https://www.fmz.com/strategy/129084
> 更新时间
2018-12-06 17:33:27
2018-12-18 10:46:04