Name
马丁策略-V001
Author
superMan
Strategy Arguments
Argument | Default | Description |
---|---|---|
DF | 0,1,2,3,4,5,6,7 | 每次跌幅的比例,由字符串转数组。 |
JYD | $$$enc$$$BTC | 自己买入的交易对 |
startNum | true | 最开始买入的数量 单位USTD |
minWin | 1.3 | 止盈百分比 |
Source (javascript)
var DFlist = DF.split(',').map(item => 0 - item) // 跌幅的数组,由于不可以设置成数组,最开始由字符串代替;
var JYDlist = JYD.split(',') // 选择的交易对。
var account = 0; // 账户余额
var index = 0; // 补仓次数
var accountNum = 0 // 总持仓量
var countPrice = false; // 总持仓钱
var YKBL = 0 // 盈亏比例
var copyStartNum = startNum;
var FrozenBalance = 0; // 当前平台冻结余额
// 函数方法区域
// 初始化函数
function initFn(isFirst){
account = _C(exchange.GetAccount)
if(isFirst){
Log('robot starts to run')
} else {
Log('robot 重复运行中')
}
}
// 循环函数
function onTick() {
}
// 循环确定 订单已经买入
function onSureBuy(FrozenBalance){
}
// 买入函数
function onBuy(){
let account = _C(exchange.GetAccount)
if ((account.Balance / currentPrice > copyStartNum && accountNum == 0) || DFlist[index] > YKBL){
exchange.Buy(currentPrice, copyStartNum);
Log(`订单买入,价格为${currentPrice},数量为${copyStartNum}`,'#ff0000')
FrozenBalance = currentPrice * copyStartNum
let i = 0
while(FrozenBalance){
FrozenBalance = _C(exchange.GetAccount).FrozenBalance;
if(i >= 5 ){
let order = _C(exchange.GetOrders)
order = JSON.stringify(order)
for(let i = 0; i < order.legnth; i++){
exchange.CancelOrder(order[i].Id);
}
Log('撤销买入,平台冻结余额为:',FrozenBalance, '#00ff00')
break
} else if(FrozenBalance) {
i++
} else {
break
}
Sleep(200)
}
if(i >= 5 && FrozenBalance){
FrozenBalance = 0
return false
} else {
// 走到这里说明 订单买入成功
Log(`订单买入成功,价格为${currentPrice},数量为${copyStartNum}`,'#00ff00')
accountNum += copyStartNum
countPrice += currentPrice * copyStartNum
copyStartNum = copyStartNum*2
index++
}
}
if(account.Balance / currentPrice < copyStartNum){
// Log("账户 余额不足")
}
}
// 入口函数
function main() {
initFn(true)
var num = 1;
while(1){
account = _C(exchange.GetAccount)
currentPrice = _C(exchange.GetTicker).Low;
//Log(`循环第${num}次`,'account',account,'currentPrice',currentPrice,'countPrice',countPrice,'YKBL',YKBL,'copyStartNum',copyStartNum)
num++
// 获取当前 涨跌幅
if(!countPrice){
countPrice = currentPrice * copyStartNum
} else {
// 计算当前盈亏比例
YKBL = (countPrice * copyStartNum - currentPrice * copyStartNum) / countPrice * copyStartNum *100
}
Log(`当前循环第${num}次盈亏比例为`,YKBL)
if(YKBL > 1000 ){
Log('当前总价',YKBL,'当前总持有币数量',copyStartNum,'当前卖价',currentPrice,'#ff0000')
}
// 当达到止盈百分比的时候抛仓
if(YKBL > minWin){
// var diffStock = _N(countPrice / accountNum);
var diffStock = _N(account.Stocks, 4);
exchange.Sell(currentPrice, diffStock)
countPrice = 0
accountNum = 0
copyStartNum = startNum
Log("卖出价格为:",currentPrice,diffStock,account,'#00ff00')
index = 0
}
// 买入
onBuy()
Sleep(1000*60)
}
}
Detail
https://www.fmz.com/strategy/288966
Last Modified
2021-06-10 13:30:52