def create_over_avgline_in_range_bottom_task(self, prior): # over avg and in range bottom gain_cond = self.create_default_gain_exit_cond() up_task1 = TradeTask("OverAvgInRgeBot", MyString.Buy, self.clock.cur_bar, 300, 300) avg_cond = EventRelativeBarCondition(StgEvent.OverAvgLineAtOpen, 1, 0,60) btm_cond = EventRelativeBarCondition(StgEvent.InRangeBottom, 2, 0, 100) up_task1.addEntryCond(avg_cond) up_task1.addEntryCond(btm_cond) up_task1.addGainExitCond(gain_cond) self.add_default_exit_cond(up_task1) up_task1.set_priority(prior) return up_task1
def if_bigbangup(self, kstatus): #create_tradecondition() chsum_cond = RangeCondition(Indicator.SCheckSum, 1, -2, 2) task = TradeTask("WaitForBack", MyString.Buy, kstatus.cur_bar_id, 30, 200) #回调 task.addEntryCond(chsum_cond) lowrange_cond = RangeCondition(Indicator.RangeHeight15, 1, 10, 20) task.addGainExitCond(lowrange_cond) loss_cond = UpperLimitCondition(Indicator.HoldProfit, 1, -200) task.addLossExitCond(loss_cond) #task.add_gain_exit_event(StgEvent.Loss200) self.addTradeTask(task)
def create_buy_task_by_price(self, entry_price): task = TradeTask("DefaultBuyPirce", MyString.Buy, self.clock.cur_bar, 300, 300) #cur_price = self.stg.get_indor_value(Indicator.CurPrice) price_cond = UpperLimitCondition(Indicator.CurPrice, 1, entry_price) task.addEntryCond(price_cond) back_rest_event = EventSampleRlBarCondition(StgEvent.StdBackRestOfDown, 2, 0, 10) task.addEntryCond(back_rest_event) #gain exit target_profit = self.stg.get_indor_value(Indicator.PreBuyProfit) target_cond = UpperLimitCondition(Indicator.HoldProfit, 1, target_profit) task.addGainExitCond(target_cond) #loss exit self.add_default_exit_cond(task) self.addTradeTask(task)
def default_strategy(self): entry_timeout = 300 hold_time = 300 task = TradeTask("SellTest", MyString.Sell, 0, entry_timeout, hold_time) #entry open_price = 3730 #price_cond = LowerLimitCondition(Indicator.CurPrice, 1, open_price) price_cond = UpperLimitCondition(Indicator.CurPrice, 1, open_price) task.addEntryCond(price_cond) #gain exit #price_cond = UpperLimitCondition(Indicator.CurPrice, 1, open_price-2) price_cond = LowerLimitCondition(Indicator.CurPrice, 1, open_price - 2) task.addGainExitCond(price_cond) #loss exit TradeFactory.add_default_exit_cond(task) task.set_callbacker(self) self.addTradeTask(task)
def create_range_sell_task(self): task = TradeTask("TradeRangeSell", MyString.Sell, self.clock.cur_bar, 300, 300) #entry range_h = self.stg.get_indor_value(Indicator.RangeHInDay) if (range_h < 100): return range_l = self.stg.get_indor_value(Indicator.RangeLInDay) cur_price = self.stg.get_indor_value(Indicator.CurPrice) if (range_l > cur_price): range_l = cur_price + random.randint(MyDefaultValue.GainStd-20, MyDefaultValue.GainStd+50) price_cond = UpperLimitCondition(Indicator.CurPrice, 1, range_h) task.addGainExitCond(price_cond) #gain exit price_cond = LowerLimitCondition(Indicator.CurPrice, 1, range_l) task.addGainExitCond(price_cond) target_gain_cond = UpperLimitCondition(Indicator.HoldProfit, 1, random.randint(MyDefaultValue.GainStd-20, MyDefaultValue.GainStd+50)) task.addGainExitCond(target_gain_cond) #loss exit self.add_default_exit_cond(task) self.addTradeTask(task)
def create_buy_task_by_back(self, downs): task = TradeTask("DefaultBuy", MyString.Buy, self.clock.cur_bar, 300, 300) #cur_price = self.stg.get_indor_value(Indicator.CurPrice) price_cond = UpperLimitCondition(Indicator.Downs, 1, downs) task.addEntryCond(price_cond) #gain exit target_profit = self.stg.get_indor_value(Indicator.PreBuyProfit) target_cond = UpperLimitCondition(Indicator.HoldProfit, 1, target_profit) task.addGainExitCond(target_cond) #loss exit self.add_default_exit_cond(task) self.addTradeTask(task)
def create_classic_buy_task(self, unders): task = TradeTask("ClassicBuy", MyString.Buy, self.clock.cur_bar, 300, 300) #cur_price = self.stg.get_indor_value(Indicator.CurPrice) downs_cond = UpperLimitCondition(Indicator.Downs, 1, unders) task.addEntryCond(downs_cond) #gain exit target_profit = self.stg.get_indor_value(Indicator.PreBuyProfit) if (target_profit > 10): target_profit = 10 target_cond = UpperLimitCondition(Indicator.HoldProfit, 1, target_profit) task.addGainExitCond(target_cond) #loss exit self.add_default_exit_cond(task) return task
def create_range_buy_task(self): task = TradeTask("TradeRangeBuy", MyString.Buy, self.clock.cur_bar, 300, 300) range_h = self.stg.get_indor_value(Indicator.RangeHInDay) cur_price = self.stg.get_indor_value(Indicator.CurPrice) if (range_h < cur_price): range_h = cur_price + random.randint(MyDefaultValue.GainStd-20, MyDefaultValue.GainStd+50) #gain exit random.randint(MyDefaultValue.GainStd-2, MyDefaultValue.GainStd+5) price_cond = UpperLimitCondition(Indicator.CurPrice, 1, range_h) task.addGainExitCond(price_cond) target_gain_cond = UpperLimitCondition(Indicator.HoldProfit, 1, random.randint(MyDefaultValue.GainStd-20, MyDefaultValue.GainStd+50)) task.addGainExitCond(target_gain_cond) #loss exit self.add_default_exit_cond(task) self.addTradeTask(task)
def create_target_sell_task(self, name, target_profit): buy_task = TradeTask(name, MyString.Sell, 0, 300, 300) self.add_default_sell_entry_cond(buy_task, 10, 100) self.add_target_gain_exit_cond(buy_task, target_profit) self.add_default_sell_loss_exit_cond(buy_task) return buy_task
def create_in_range_bottom_buy_task(self, prior): gain_cond = self.create_default_gain_exit_cond() up_task3 = TradeTask("farFromLL", MyString.Buy, self.clock.cur_bar, 300, 300) away_cond = EventRelativeBarCondition(StgEvent.FarFromLL, 1, 0, 500) downs_cond = UpperLimitCondition(Indicator.Downs, 2, 20) ck = RangeCondition(Indicator.CheckSum15, 3, -6, 6) price_pos = LowerLimitCondition(Indicator.DistanceAvgLine, 3, -10) #均线以下 up_task3.addEntryCond(away_cond) up_task3.addEntryCond(downs_cond) up_task3.addEntryCond(ck) up_task3.addEntryCond(price_pos) up_task3.addGainExitCond(gain_cond) self.add_default_exit_cond(up_task3) return up_task3
def create_range_task(self): task = TradeTask("TradeRangeBuy", MyString.Buy, self.clock.cur_bar, 300, 300) #cksum = TradeCondition() #event = pass
def __init__(self): gain_cond = self.create_default_gain_exit_cond() # over avg and in range bottom up_task1 = TradeTask("OverAvgInRgeBot", MyString.Buy, self.clock.cur_bar, 300, 300) avg_cond = EventSampleCondition(StgEvent.OverAvgLineAtOpen, 1, 0, 60) btm_cond = EventSampleCondition(StgEvent.InRangeBottom, 2, 0, 100) up_task1.addEntryCond(avg_cond) up_task1.addEntryCond(btm_cond) up_task1.addGainExitCond(gain_cond) self.add_default_exit_cond(up_task1) #v and inrange bottom up_task2 = TradeTask("VInRgeBot", MyString.Buy, self.clock.cur_bar, 300, 300) avg_cond = EventSampleCondition(StgEvent.RushBottomAndBack, 1, 10, 360) btm_cond = EventSampleCondition(StgEvent.InRangeBottom, 2, 0, 100) up_task2.addEntryCond(avg_cond) up_task2.addEntryCond(btm_cond) up_task2.addGainExitCond(gain_cond) self.add_default_exit_cond(up_task2) # far from day_bottom and in range bottom up_task3 = TradeTask("farFromLL", MyString.Buy, self.clock.cur_bar, 300, 300) away_cond = EventSampleCondition(StgEvent.FarFromLL, 1, 0, 500) downs_cond = UpperLimitCondition(Indicator.Downs, 2, 20) ck = RangeCondition(Indicator.CheckSum15, 3, -6, 6) up_task3.addEntryCond(away_cond) up_task3.addEntryCond(downs_cond) up_task3.addEntryCond(ck) up_task3.addGainExitCond(gain_cond) self.add_default_exit_cond(up_task3)
def __init__(self): gain_cond = self.create_default_gain_exit_cond() # over avg and in range bottom up_task1 = TradeTask("OverAvgInRgeBot", MyString.Buy, self.clock.cur_bar, 300, 300) avg_cond = EventSampleCondition(StgEvent.OverAvgLineAtOpen, 1, 0, 60) btm_cond = EventSampleCondition(StgEvent.InRangeBottom, 2, 0, 100) up_task1.addEntryCond(avg_cond) up_task1.addEntryCond(btm_cond) up_task1.addGainExitCond(gain_cond) self.add_default_exit_cond(up_task1) #v and inrange bottom up_task2 = TradeTask("OverAvgInRgeBot", MyString.Buy, self.clock.cur_bar, 300, 300) avg_cond = EventSampleCondition(StgEvent.RushBottomAndBack, 1, 10, 360) btm_cond = EventSampleCondition(StgEvent.InRangeBottom, 2, 0, 100) up_task2.addEntryCond(avg_cond) up_task2.addEntryCond(btm_cond) up_task2.addGainExitCond(gain_cond) self.add_default_exit_cond(up_task2)