예제 #1
0
    def add_default_exit_cond(self, task):
        #
        target_loss_cond = LowerLimitCondition(
            StgEvent.Gain, 1,
            random.randint(MyDefaultValue.LossStd - 20,
                           MyDefaultValue.LossStd + 50))
        task.addLossExitCond(target_loss_cond)

        checksum_cond = RangeCondition(Indicator.SCheckSum, 2, -3, 3)
        task.addLossExitCond(checksum_cond)

        greater_cond = UpperLimitCondition(Indicator.GreaterContinuousCount, 3,
                                           10)
        task.addLossExitCond(greater_cond)
        #===========================================#
        expired_cond = UpperLimitCondition(StgEvent.HoldExpire, 1,
                                           MyDefaultValue.ExpiredStd)
        task.add_expired_exit_cond(expired_cond)

        checksum_cond = RangeCondition(Indicator.SCheckSum, 2, -3, 3)
        task.add_expired_exit_cond(checksum_cond)

        greater_cond = UpperLimitCondition(Indicator.GreaterContinuousCount, 3,
                                           10)
        task.add_expired_exit_cond(greater_cond)
예제 #2
0
    def default_params(self):
        '''
        up_h_cond = UpperLimitCondition("UpH", 1, 15)
        up_wide_cond = RangeCondition("UpW", 2, 1, 10)

        flat_h_cond = UpperLimitCondition("UpH", 1, 8)
        flat_wide_cond = RangeCondition("UpW", 2, 1, 10)

        down_h_cond = LowerLimitCondition("DownH", 1, -15)
        down_wide_cond = RangeCondition("DownW", 2, 1, 10)
        '''
        up_h_cond = UpperLimitCondition(Indicator.LastSwingHeightShort, 1, 15)
        up_w_cond = RangeCondition(Indicator.LastSwingWidthShort, 2, 1, 10)
        setp1 = CondtionSet("up")
        setp1.index = 1
        setp1.add_cond(up_h_cond)
        setp1.add_cond(up_w_cond)
        self.add_sets(setp1)

        flat_h_cond = UpperLimitCondition("UpH", 1, 8)
        flat_w_cond = RangeCondition("UpW", 2, 1, 10)
        setp2 = CondtionSet("flat")
        setp2.index = 2
        setp2.add_cond(flat_h_cond)
        setp2.add_cond(flat_w_cond)
        self.add_sets(setp2)

        down_h_cond = LowerLimitCondition("DownH", 1, -15)
        down_wide_cond = RangeCondition("DownW", 2, 1, 10)
        setp3 = CondtionSet("down")
        setp3.index = 3
        setp3.add_cond(down_h_cond)
        setp3.add_cond(down_wide_cond)
        self.add_sets(setp3)
예제 #3
0
 def add_default_buy_expired_exit_cond(self, task):
     #时间
     expired_cond = UpperLimitCondition(StgEvent.HoldExpire, 1, MyDefaultValue.ExpiredStd)
     checksum_cond = RangeCondition(Indicator.SCheckSum, 2, -3, 3)
     greater_cond = UpperLimitCondition(Indicator.GreaterContinuousCount, 3, 10)
     task.add_expired_exit_cond(greater_cond)
     task.add_expired_exit_cond(expired_cond)
     task.add_expired_exit_cond(checksum_cond)
예제 #4
0
    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) 
예제 #5
0
 def add_default_sell_exit_cond(self, task):
     #价格
     target_loss_cond = LowerLimitCondition(Indicator.HoldProfit, 1, random.randint(MyDefaultValue.LossStd-20, MyDefaultValue.LossStd+50))
     checksum_cond = RangeCondition(Indicator.SCheckSum, 2, -3, 3)
     lesser_cond = UpperLimitCondition(Indicator.LessContinuousCount, 3, 10)
     task.addLossExitCond(target_loss_cond)
     task.addLossExitCond(checksum_cond)
     task.addLossExitCond(lesser_cond)
     #时间
     expired_cond = UpperLimitCondition(StgEvent.HoldExpire, 1, MyDefaultValue.ExpiredStd)
     checksum_cond = RangeCondition(Indicator.SCheckSum, 2, -3, 3)
     lesser_cond = UpperLimitCondition(Indicator.LessContinuousCount, 3, 10)
     task.add_expired_exit_cond(checksum_cond)
     task.add_expired_exit_cond(expired_cond)
     task.add_expired_exit_cond(lesser_cond)
예제 #6
0
    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
예제 #7
0
    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)
예제 #8
0
    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) 
예제 #9
0
    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) 
예제 #10
0
 def add_default_buy_loss_exit_cond(self, task):
     #价格
     target_loss_cond = LowerLimitCondition(Indicator.HoldProfit, 1, random.randint(MyDefaultValue.LossStd-20, MyDefaultValue.LossStd+50))
     checksum_cond = RangeCondition(Indicator.SCheckSum, 2, -3, 3)
     greater_cond = UpperLimitCondition(Indicator.GreaterContinuousCount, 3, 10)
     task.addLossExitCond(target_loss_cond)
     task.addLossExitCond(checksum_cond)
     task.addLossExitCond(greater_cond)
예제 #11
0
    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) 
예제 #12
0
 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
예제 #13
0
    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)
예제 #14
0
    def add_default_sell_entry_cond(self, task, ups, end_bar):
        #task = TradeTask("SellTest", MyString.Sell, 0, entry_timeout, hold_time)
       
        #price_cond = UpperLimitCondition(Indicator.CurPrice, 1, open_price)
        cksum_cond = RangeCondition(Indicator.SCheckSum, 1, 0, 4)
        height8_cond = LowerLimitCondition(Indicator.RangeHeight15, 2, 10)
        height15_cond = LowerLimitCondition(Indicator.RangeHeight15, 3, 16)
        #二选一
        downs_cond = RangeCondition(Indicator.Downs, 4, ups, ups+20)
        #or
        expired_cond = UpperLimitCondition(Indicator.CurBar, 4, end_bar)

        task.addEntryCond(cksum_cond)
        task.addEntryCond(height8_cond)
        task.addEntryCond(height15_cond)
        task.addEntryCond(downs_cond)
        task.addEntryCond(expired_cond)
예제 #15
0
    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)
예제 #16
0
 def add_target_gain_exit_cond(self, task,target_profit):
     target_cond = UpperLimitCondition(Indicator.HoldProfit, 1, target_profit)
     checksum_cond = RangeCondition(Indicator.SCheckSum, 2, -3, 3)
     task.addGainExitCond(target_cond)
     task.addGainExitCond(checksum_cond)
예제 #17
0
 def create_default_gain_exit_cond(self):
     #gain exit
     target_profit = self.stg.get_indor_value(Indicator.PreBuyProfit)
     target_cond = UpperLimitCondition(Indicator.HoldProfit, 1, target_profit)
     return target_cond