This commit is contained in:
Zero
2016-05-12 16:08:58 +08:00
parent 10503d8958
commit 41e89c0154
8 changed files with 138 additions and 58 deletions
+25
View File
@@ -0,0 +1,25 @@
/*
策略出处: https://www.botvs.com/strategy/14436
策略名称: 10行人品策略
策略作者: 春哥
策略描述:
赚不赚钱看人品
参数 默认值 描述
-------- ----- -------
Interval 300 轮询周期(秒)
*/
function main() {
while (true) {
Sleep(Interval * 1000);
if (Math.random() > 0.5) $.Buy(1000000); else {
$.Sell(1000000);
var a = $.GetAccount();
if (a) LogProfit( a.Balance , 'CNY:', a.Balance, 'BTC:', a.Stocks);
}
}
}
+8 -15
View File
@@ -35,10 +35,10 @@ function MACD_Cross(){
var dea = macd[1];
var column = macd[2];
var len = records.length;
if( (dif[len-1] > 0 && dea[len-1] > 0) && dif[len-1] > dea[len-1] && dif[len-2] < dea[len-2] && column[len-1] > 0.2 ){
if( (dif[len-1] > 0 && dea[len-1] > 0) && dif[len-1] > dea[len-1] && dif[len-2] < dea[len-2] && column[len-1] > 0.08 ){
return 1;
}
if( (dif[len-1] < 0 && dea[len-1] < 0) && dif[len-1] < dea[len-1] && dif[len-2] > dea[len-2] && column[len-1] < -0.2 ){
if( (dif[len-1] < 0 && dea[len-1] < 0) && dif[len-1] < dea[len-1] && dif[len-2] > dea[len-2] ){
return 2;
}
return 0;
@@ -125,14 +125,7 @@ var holdOrder = {
this.level = 1;
}
};
function getTimeByNormal(time){
var timeByNormal = new Date();
timeByNormal.setTime(time);
var strTime = timeByNormal.toString();
var showTimeArr = strTime.split(" ");
var showTime = showTimeArr[3]+"-"+showTimeArr[1]+"-"+showTimeArr[2]+"-"+showTimeArr[4];
return showTime;
}
function scan(){
var sellInfo = null;
var buyInfo = null;
@@ -152,7 +145,7 @@ function scan(){
holdOrder.orderState = ORDER_VALID;
holdOrder.price = buyInfo.price;
holdOrder.amount = buyInfo.amount;
holdOrder.time = getTimeByNormal((new Date()).getTime());
holdOrder.time = $.getTimeByNormal((new Date()).getTime());
state = singal === 1 ? STATE_BUY : STATE_SELL;
var account = $.GetAccount(exchange);
@@ -171,7 +164,7 @@ function scan(){
holdOrder.orderState = ORDER_INVALID;
holdOrder.price = sellInfo.price;
holdOrder.amount = sellInfo.amount;
holdOrder.time = getTimeByNormal((new Date()).getTime());
holdOrder.time = $.getTimeByNormal((new Date()).getTime());
profit = holdOrder.updateCurrentProfit(lastPrice,sellInfo.amount);
state = STATE_FREE;
@@ -184,7 +177,7 @@ function scan(){
holdOrder.orderState = ORDER_INVALID;
holdOrder.price = sellInfo.price;
holdOrder.amount = sellInfo.amount;
holdOrder.time = getTimeByNormal((new Date()).getTime());
holdOrder.time = $.getTimeByNormal((new Date()).getTime());
profit = holdOrder.updateCurrentProfit(lastPrice,sellInfo.amount);
state = STATE_FREE;
@@ -197,7 +190,7 @@ function scan(){
holdOrder.orderState = ORDER_INVALID;
holdOrder.price = sellInfo.price;
holdOrder.amount = sellInfo.amount;
holdOrder.time = getTimeByNormal((new Date()).getTime());
holdOrder.time = $.getTimeByNormal((new Date()).getTime());
profit = holdOrder.updateCurrentProfit(lastPrice,sellInfo.amount);
state = STATE_FREE;
@@ -210,7 +203,7 @@ function scan(){
holdOrder.orderState = ORDER_INVALID;
holdOrder.price = sellInfo.price;
holdOrder.amount = sellInfo.amount;
holdOrder.time = getTimeByNormal((new Date()).getTime());
holdOrder.time = $.getTimeByNormal((new Date()).getTime());
profit = holdOrder.updateCurrentProfit(lastPrice,sellInfo.amount);
state = STATE_FREE;
+5 -4
View File
@@ -4,12 +4,15 @@
> 开源策略列表
- [单独计算收益(代码来自zero)](https://www.botvs.com/strategy/1084)
- [差价监控](https://www.botvs.com/strategy/1340)
- [MACD 双向 滑动止损](https://www.botvs.com/strategy/12822)
- [时间转换模板](https://www.botvs.com/strategy/14517)
- [10行人品策略](https://www.botvs.com/strategy/14436)
- [商品期货主力合约过滤](https://www.botvs.com/strategy/9837)
- [从第三方网站获取K线 (0427更新)](https://www.botvs.com/strategy/12977)
- [平台价格指标监控1.1](https://www.botvs.com/strategy/12442)
- [20行打造均线交叉策略](https://www.botvs.com/strategy/14051)
- [均线策略 30 行打造一个正向收益系统](https://www.botvs.com/strategy/12348)
- [MACD 双向 滑动止损](https://www.botvs.com/strategy/12822)
- [各大平台API可用率统计](https://www.botvs.com/strategy/4404)
- [数字货币现货交易类库](https://www.botvs.com/strategy/10989)
- [商品期货交易类库](https://www.botvs.com/strategy/12961)
@@ -20,7 +23,6 @@
- [高精度回测](https://www.botvs.com/strategy/11575)
- [函数自动容错模板](https://www.botvs.com/strategy/11609)
- [Dual Thrust OKCoin 期货](https://www.botvs.com/strategy/12101)
- [差价监控](https://www.botvs.com/strategy/1340)
- [RSI_now_sb_ok](https://www.botvs.com/strategy/11604)
- [自定义K线周期转换](https://www.botvs.com/strategy/11216)
- [模板库使用例子](https://www.botvs.com/strategy/10991)
@@ -49,7 +51,6 @@
- [单点狙击高频加仓自动反手解套算法 V1.2](https://www.botvs.com/strategy/2406)
- [796期货反手加倍算法](https://www.botvs.com/strategy/3648)
- [冰山委托 - 支持价格触发 BitVC期货专用](https://www.botvs.com/strategy/951)
- [单独计算收益(代码来自zero)](https://www.botvs.com/strategy/1084)
- [多线程获取多个交易的深度信息](https://www.botvs.com/strategy/3651)
- [账户余额变动邮箱提醒, 支持添加多个交易所](https://www.botvs.com/strategy/2006)
- [多线程获取多个交易的账户信息](https://www.botvs.com/strategy/3297)
+1 -1
View File
@@ -1,7 +1,7 @@
/*
策略出处: https://www.botvs.com/strategy/11604
策略名称: RSI_now_sb_ok
策略作者: luoluchang
策略作者: tfboys
策略描述:
RSI简单买卖测试, 默认 70-100卖出,0-30买入
+36 -36
View File
@@ -8,40 +8,40 @@
*/
function adjustFloat(v) {
return Math.floor(v*1000)/1000;
}
function GetAccount() {
var account;
while (!(account = exchange.GetAccount())) {
Sleep(1000);
}
return account;
}
function GetTicker() {
var ticker;
while (!(ticker = exchange.GetTicker())) {
Sleep(1000);
}
return ticker;
}
function updateProfit(accountInit, accountNow, ticker) {
var netNow = accountNow.Balance + accountNow.FrozenBalance + ((accountNow.Stocks + accountNow.FrozenStocks) * ticker.Buy);
var netInit = accountInit.Balance + accountInit.FrozenBalance + ((accountInit.Stocks + accountInit.FrozenStocks) * ticker.Buy);
LogProfit(adjustFloat(netNow - netInit), accountNow);
}
function main() {
InitAccount = GetAccount();
while (true) {
updateProfit(InitAccount, GetAccount(), GetTicker());
Sleep(20000);
}
function adjustFloat(v) {
return Math.floor(v*1000)/1000;
}
function GetAccount() {
var account;
while (!(account = exchange.GetAccount())) {
Sleep(1000);
}
return account;
}
function GetTicker() {
var ticker;
while (!(ticker = exchange.GetTicker())) {
Sleep(1000);
}
return ticker;
}
function updateProfit(accountInit, accountNow, ticker) {
var netNow = accountNow.Balance + accountNow.FrozenBalance + ((accountNow.Stocks + accountNow.FrozenStocks) * ticker.Buy);
var netInit = accountInit.Balance + accountInit.FrozenBalance + ((accountInit.Stocks + accountInit.FrozenStocks) * ticker.Buy);
LogProfit(adjustFloat(netNow - netInit), accountNow);
}
function main() {
InitAccount = GetAccount();
while (true) {
updateProfit(InitAccount, GetAccount(), GetTicker());
Sleep(5000);
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
/*
策略出处: https://www.botvs.com/strategy/12442
策略名称: 平台价格指标监控1.1
策略作者: luoluchang
策略作者: tfboys
策略描述:
1.5---可以监控ATR,RSI,BOLL,PRICE
+1 -1
View File
@@ -1,7 +1,7 @@
/*
策略出处: https://www.botvs.com/strategy/8266
策略名称: 平台价格比较1.0
策略作者: luoluchang
策略作者: tfboys
策略描述:
1.4---增加告警周期设置
+61
View File
@@ -0,0 +1,61 @@
/*
策略出处: https://www.botvs.com/strategy/14517
策略名称: 时间转换模板
策略作者: 小小梦
策略描述:
###把毫秒级的时间转换成 直观的 时间显示,比如 把 Record.Time 时间戳 (毫秒数) 和 Trade.Time 转换为 正常时间。也可以用于获取当前时间,如 传入参数为: new Date() 就显示当前时间。
参数 默认值 描述
------ ----- ---------------
isShow false 是否在转换时输出转换后的时间。
*/
/*
-- 策略引用该模板以后直接用 $.Test() 调用此方法
-- main 函数在策略中不会触发, 只做为模板调试的入口
*/
$.getTimeByNormal = function(time) {
if(typeof( time ) == "object" ){
time = time.getTime();
return getTimeByNormal(time);
}else if(typeof( time ) == "number" ){
return getTimeByNormal(time);
}
throw "时间转换模板导出函数传入参数类型错误!,请传入Date 类型 或 毫秒数";
};
function getTimeByNormal(time){
var timeByNormal = new Date();
timeByNormal.setTime(time);
var strTime = timeByNormal.toString();
if(isShow === true){
Log("getTimeByNormal转换为:",strTime);
}
return strTime;
}
//测试
function main() {
var time1 = $.getTimeByNormal( new Date() );
Log("当前时间time1:",time1);
Sleep(1000 * 60);
var time3 = (new Date()).getTime();
Log("毫秒级时间:",time3,"转换");
var time2 = $.getTimeByNormal( time3 );
Log("转换后的时间:",time2);
Log("new Date:",typeof(new Date()));
Log("number :",typeof(12355554875425));
//var str = "ssadfgg";
//var returnStr = $.getTimeByNormal(str); //传入一个 错误类型 字符串 实验下。。
//Log("参数传入字符串:",returnStr);
var records = exchange.GetRecords();
while(!records || records.length < 10){
records = exchange.GetRecords();
Sleep(1000);
}
for(var i = 0; i < records.length; i++){
Log(records[i],"时间转换:i:",i,"---",getTimeByNormal(records[i].Time));
}
}