한 가지 다목적 전략은 BTC 현금 구매 전략이며, 원래는 1000USD의 현금이었다. 켈트너 통로를 돌파했는지 여부를 확인하고, 돌파했다면 더 많은 것을하십시오. 이 프로젝트의 전략은: 1, 6%의 손실이 발생하면 직접적인 손실을 중지합니다. 2, MA 평균선을 넘어선 경우 바로 판매합니다. 3, 10%의 이익이 발생하면 보호 요인으로 직접 더 많이하고, 지난 24 시간 동안 10%의 연속 하락이 발생하면 갑작스러운 사건이 발생하면 즉시 손실을 중지하십시오.
이 전략은 실제로 실행된 결과, 다시 테스트하는 것이 좋았습니다. 하지만 이 모든 것은 단지 한 가지의 문제일 뿐입니다.
''' start: 2020-01-01 00:00:00 end: 2020-04-24 00:00:00 period: 1h exchanges: [{"eid":"huobi","currency":"BTC_USDT","stocks":0,"meta":{"AccessKey":"7yngd7gh5g-a7ed9b1a-c05064c3-bab33","SecretKey":"553c2cd1-e229e1d2-25a536cb-db7d3"}}] ''' import talib as ta import pandas as pd from datetime import datetime from datetime import timedelta import math #coding:utf8 import sys eid = -1 last_price = -1 def main(): global eid global last_price global ma while True: records = exchange.GetRecords(1*60*60) e = exchange kline1 = pd.DataFrame(records) kline1['Time'] = kline1['Time'].map(lambda x: datetime.utcfromtimestamp(x/1000)+timedelta(hours=8)) kline1.columns = ['time','open','high','low','close','volume','oi'] r = kline1 #Log('最新k线时间',r.iloc[-1].time, ' 最新价格收盘价', r.iloc[-1].close) leadLine1 = ta.EMA(r.close, 30) leadLine2 = ta.SMA(r.close, 30) UT=leadLine2 < leadLine1 DT=leadLine2 > leadLine1 # keltner channel ma = ta.EMA(kline1.close, 80) # 真实的范围函数 range1 = ta.TRANGE(kline1.high, kline1.low, kline1.close) rangema = ta.EMA(range1, 80) upper = ma + 3*rangema lower = ma - 3*rangema # minus and plus of adx/dmi minus = ta.MINUS_DI(kline1.high,kline1.low, kline1.close,14) plus = ta.PLUS_DI(kline1.high, kline1.low, kline1.close ,14) volume0 = r.iloc[-1].volume volume1 = r.iloc[-2].volume rn = r.iloc[-1] entry_long = rn.close > upper.iloc[-1] and (r.iloc[-1].volume+ r.iloc[-2].volume) >1.5 *(r.iloc[-4].volume+ r.iloc[-5].volume) long = entry_long exit_long = (rn.close < ma.iloc[-1] ) account = exchange.GetAccount() amount = account.Stocks #Log('Balance is ', account['Balance'], ' Btc amount is ', amount) # 如果处于空仓状态 if (account['Balance'] >= 600 and amount < 0.001): if long==True and account['Balance'] < 400 and amount<0.01: Log('balance is ', account['Balance'], ' 余额不足400,退出!') return elif long== True and account['Balance'] >= 600: #第一次开多仓 Log('balance is ', account['Balance']) Log('多仓位时间: ', rn.time, ' open is ', rn.open , ' close is ', rn.close, ' upper is ', upper.iloc[-1], ' volume 0\1 is', volume0 , 'volume 1 is ', volume1 , ' plus is ',plus.iloc[-1], ' minus is ', minus.iloc[-1], '@') exchange.Buy(-1,600) last_price = rn.close + 10 Sleep(1000*60*15) # 如果处于持仓状态 if amount>0.001 : if amount > 0.0001 and rn.close <= last_price*0.94: Log('止损平仓事件: ','balance is ', account['Balance'], rn.time, ' rn.close is ', rn.close, ' @') id = exchange.Sell(-1, amount); account = exchange.GetAccount() amount = account.Stocks Log('Balance is ', account['Balance'], ' Btc amount is ', amount) eid = -1 #如果处于一直持仓又大跌状态,才卖出 elif amount > 0.0001 and rn.close >= last_price * 1.1 and rn.close <= r.iloc[-24].close*0.9: Log('持仓周期内的大跌止损平仓事件: ', rn.time, ' rn.close is ', rn.close, ' @') id = exchange.Sell(-1, amount); eid = -1 account = exchange.GetAccount() amount = account.Stocks Log('Balance is ', account['Balance'], ' Btc amount is ', amount) elif amount > 0.0001 and exit_long == True : if rn.close <= last_price: Log('位置下滑平仓位事件,亏损: amount is ',amount ,' time is ', rn.time, ' 价格是:',rn.close,' ma is ', ma.iloc[-1], ' 开仓价格',last_price,' 亏损幅度:',100*(last_price -rn.close)/last_price ,'% @') eid = exchange.Sell(-1, amount) # print(r.tail(10)) # print('ma is ' ,ma) account = exchange.GetAccount() amount = account.Stocks Log('Balance is ', account['Balance'], ' Btc amount is ', amount) elif rn.close > last_price*1.1 : Log('超出10%盈利继续持仓') account = exchange.GetAccount() amount = account.Stocks Log('Balance is ', account['Balance'], ' Btc amount is ', amount) return elif rn.close > last_price and rn.close <=last_price*1.1: eid = exchange.Sell(-1, amount); account = exchange.GetAccount() amount = account.Stocks Log('Balance is ', account['Balance'], ' Btc amount is ', amount) Log('位置下滑平仓位事件,赚钱啦: amount is ',amount, ' time is ', rn.time, ' 价格是: ',rn.close,' ma is ', ma.iloc[-1],' 开仓价格',last_price,' 盈利幅度:',100*(rn.close-last_price )/last_price ,'% @' ) else: id = exchange.Sell(-1, amount); Log('最终位置下滑平仓位事件,赚钱啦: amount is ',amount, ' time is ', rn.time, ' 价格是: ',rn.close,' ma is ', ma.iloc[-1],' 开仓价格',last_price,' 盈利幅度:',100*(rn.close-last_price )/last_price ,'% @' ) eid = -1 account = exchange.GetAccount() amount = account.Stocks Log('Balance is ', account['Balance'], ' Btc amount is ', amount) Sleep(1000*60*15)
차오장키를 전략에 쓰지 마세요.
증오자형의 연락처