class DoubleMaStrategy(LooperApi): allow_max_price = 5000 # 设置价格上限 当价格达到这个就卖出 防止突然跌 止盈 allow_low_price = 2000 # 设置价格下限 当价格低出这里就卖 防止巨亏 止损 def __init__(self, name): super().__init__(name) self.count = 1 self.api = Indicator() self.api.open_json("../zn1912.SHFE.json") self.pos = 0 def on_bar(self, bar): # todo: 均线 """ """ am = self.api am.add_bar(bar) if not am.inited: return cci = am.cci() pass def on_trade(self, trade): if trade.direction == Direction.LONG: self.pos += trade.volume else: self.pos -= trade.volume def init_params(self, data): """"""
def __init__(self, name): super().__init__(name) self.count = 1 self.pos = 0 self.bar_3 = Indicator() # 3分钟bar线 self.bar_3.open_json('../zn1912.SHFE.json') # 读取本地数据 self.allow_max_price = 5000 # 设置价格上限 当价格达到这个就卖出 防止突然跌 self.allow_low_price = 2000 # 设置价格下限 当价格低出这里就卖 防止巨亏
class DoubleMaStrategy(LooperApi): allow_max_price = 5000 # 设置价格上限 当价格达到这个就卖出 防止突然跌 止盈 allow_low_price = 2000 # 设置价格下限 当价格低出这里就卖 防止巨亏 止损 def __init__(self, name): super().__init__(name) self.count = 1 self.api = Indicator() self.api.open_json("../zn1912.SHFE.json") self.pos = 0 def on_bar(self, bar): # todo: 均线 和 MACD 和 BOLL 结合使用 """ """ am = self.api am.add_bar(bar) # 收盘 close = am.close # 压力 平均 支撑 # top, middle, bottom = am.boll() # DIF DEA DIF-DEA macd, signal, histo = am.macd() if self.allow_max_price <= close[-1] and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) if self.allow_low_price >= close[-1] and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) # 金叉做多 和 均线>平均 if histo[-1] > 0: if self.pos == 0: self.action.buy(bar.close_price, 1, bar) elif self.pos < 0: self.action.cover(bar.close_price, 1, bar) self.action.buy(bar.close_price, 1, bar) # 死叉做空 elif histo[-1] < 0: if self.pos == 0: self.action.sell(bar.close_price, 1, bar) # 反向进行开仓 elif self.pos > 0: self.action.sell(bar.close_price, 1, bar) self.action.short(bar.close_price, 1, bar) def on_trade(self, trade): if trade.direction == Direction.LONG: self.pos += trade.volume else: self.pos -= trade.volume def init_params(self, data): """"""
class SmaStrategy(LooperApi): def __init__(self, name): super().__init__(name) self.count = 1 self.pos = 0 self.bar_3 = Indicator() # 3分钟bar线 # self.bar_3.open_json('../zn1912.SHFE.json') # 读取本地数据 self.allow_max_price = 5000 # 设置价格上限 当价格达到这个就卖出 防止突然跌 self.allow_low_price = 2000 # 设置价格下限 当价格低出这里就卖 防止巨亏 def on_bar(self, bar): # todo: 布林带 """ """ self.bar_3.add_bar(bar) if not self.bar_3.inited: return top, middle, bottom = self.bar_3.boll() if self.allow_max_price < bar.close_price and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) if self.allow_low_price > bar.close_price and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) # 均线大于中线 说明是涨 if bar.close_price > middle[-1]: # 没有就买 if self.pos == 0: self.action.buy(bar.close_price, 1, bar) elif self.pos < 0: self.action.cover(bar.close_price, 1, bar) self.action.buy(bar.close_price, 1, bar) # 跌 elif bar.close_price <= middle[-1]: if self.pos == 0: pass elif self.pos > 0: self.action.sell(bar.close_price, 1, bar) self.action.short(bar.close_price, 1, bar) def on_trade(self, trade): if trade.direction == Direction.LONG: self.pos += trade.volume else: self.pos -= trade.volume def init_params(self, data): """"""
class SmaStrategy(LooperApi): def __init__(self, name): super().__init__(name) self.count = 1 self.pos = 0 self.bar_3 = Indicator() # 3分钟bar线 self.bar_3.open_json('../zn1912.SHFE.json') # 读取本地数据 self.allow_max_price = 5000 # 设置价格上限 当价格达到这个就卖出 防止突然跌 self.allow_low_price = 2000 # 设置价格下限 当价格低出这里就卖 防止巨亏 def on_bar(self, bar): # todo: 抛物线指标 SAR """ """ self.bar_3.add_bar(bar) if not self.bar_3.inited: return sar = self.bar_3.sar() if self.allow_max_price < bar.close_price and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) if self.allow_low_price > bar.close_price and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) # 接连涨 if sar[-1]['sar'] > sar[-2]['sar']: # 没有就买 if self.pos == 0: self.action.buy(bar.close_price, 1, bar) elif self.pos < 0: self.action.cover(bar.close_price, 1, bar) self.action.buy(bar.close_price, 1, bar) else: if self.pos > 0: self.action.sell(bar.close_price, 1, bar) self.action.short(bar.close_price, 1, bar) def on_trade(self, trade): if trade.direction == Direction.LONG: self.pos += trade.volume else: self.pos -= trade.volume print(self.pos, '-----------') def init_params(self, data): """"""
class SmaStrategy(LooperApi): def __init__(self, name): super().__init__(name) self.count = 1 self.pos = 0 self.bar_3 = Indicator() # 3分钟bar线 self.bar_3.open_json('../zn1912.SHFE.json') # 读取本地数据 self.allow_max_price = 5000 # 设置价格上限 当价格达到这个就卖出 防止突然跌 self.allow_low_price = 2000 # 设置价格下限 当价格低出这里就卖 防止巨亏 def on_bar(self, bar): # todo: 三倍运动平均值指标 TEMA """ """ self.bar_3.add_bar(bar) if not self.bar_3.inited: return close = self.bar_3.close tema = self.bar_3.tema() if self.allow_max_price < bar.close_price and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) if self.allow_low_price > bar.close_price and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) # 三倍平均数小于收盘价 if tema[-1] < close[-1]: # 没有就买 if self.pos == 0: self.action.buy(bar.close_price, 1, bar) elif self.pos < 0: self.action.cover(bar.close_price, 1, bar) self.action.buy(bar.close_price, 1, bar) else: if self.pos > 0: self.action.sell(bar.close_price, 1, bar) self.action.short(bar.close_price, 1, bar) def on_trade(self, trade): if trade.direction == Direction.LONG: self.pos += trade.volume else: self.pos -= trade.volume def init_params(self, data): """"""
class SmaStrategy(LooperApi): def __init__(self, name): super().__init__(name) self.count = 1 self.pos = 0 self.bar_3 = Indicator() # 3分钟bar线 self.bar_3.open_json('../zn1912.SHFE.json') # 读取本地数据 self.allow_max_price = 5000 # 设置价格上限 当价格达到这个就卖出 防止突然跌 self.allow_low_price = 2000 # 设置价格下限 当价格低出这里就卖 防止巨亏 def on_bar(self, bar): # todo: 随机指标 """ """ self.bar_3.add_bar(bar) if not self.bar_3.inited: return close = self.bar_3.close k, d = self.bar_3.kd() if self.allow_max_price < close[-1] and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) if self.allow_low_price > close[-1] and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) # 金叉 if k[-2] > d[-2] and k[-1] == d[-1]: # 没有就买 if self.pos == 0: self.action.buy(bar.close_price, 1, bar) # 死叉 if k[-2] == d[-2] and k[-1] < d[-1]: if self.pos > 0: self.action.sell(bar.close_price, 1, bar) def on_trade(self, trade): if trade.direction == Direction.LONG: self.pos += trade.volume else: self.pos -= trade.volume def init_params(self, data): """"""
class SmaStrategy(LooperApi): def __init__(self, name): super().__init__(name) self.count = 1 self.pos = 0 self.bar_3 = Indicator() # 3分钟bar线 self.bar_3.open_json('../zn1912.SHFE.json') # 读取本地数据 self.allow_max_price = 5000 # 设置价格上限 当价格达到这个就卖出 防止突然跌 self.allow_low_price = 2000 # 设置价格下限 当价格低出这里就卖 防止巨亏 def on_bar(self, bar): # todo: RSI 相对强度指数 """ """ self.bar_3.add_bar(bar) if not self.bar_3.inited: return roc = self.bar_3.roc() if self.allow_max_price < bar.close_price and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) if self.allow_low_price > bar.close_price and self.pos > 0: self.action.sell(bar.close_price, self.pos, bar) ################## # 无具体资料 # ################## pass def on_trade(self, trade): if trade.direction == Direction.LONG: self.pos += trade.volume else: self.pos -= trade.volume def init_params(self, data): """"""
def __init__(self, name): super().__init__(name) self.count = 1 self.api = Indicator() self.api.open_json("../zn1912.SHFE.json") self.pos = 0