Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ichimoku_score #97

Open
wupeng1211 opened this issue Sep 11, 2020 · 5 comments
Open

ichimoku_score #97

wupeng1211 opened this issue Sep 11, 2020 · 5 comments
Labels
Strategy Request Requests asking for an implementation of a specific strategy

Comments

@wupeng1211
Copy link

Hello , can someone implements this strategy? Thanks You !

Source

What come from this strategy? Cite your source:

@xmatthias xmatthias added the Strategy Request Requests asking for an implementation of a specific strategy label Sep 11, 2020
@wupeng1211
Copy link
Author

wupeng1211 commented Nov 11, 2020

   ########################################
    #
    #  ======= Ichimoku Signals Score =======
    #
    def Ichimoku_Score(self, dataframe, conversion_line_period = 9, base_line_periods = 26, laggin_span = 52, displacement = 26):
        
        df = dataframe.copy()        
        
        # Heikin Ashi Strategy
        heikinashi = qtpylib.heikinashi(df)
        df['ha_open'] = heikinashi['open']
        df['ha_close'] = heikinashi['close']
        df['ha_high'] = heikinashi['high']
        df['ha_low'] = heikinashi['low']
        
        df['tenkan'] = (df['ha_high'].rolling(window = conversion_line_period).max() + df['ha_low'].rolling(window = conversion_line_period).min()) / 2
        df['kijun'] = (df['ha_high'].rolling(window = base_line_periods).max() + df['ha_low'].rolling(window = base_line_periods).min()) / 2
        df['senkou_leading_a'] = (df['tenkan'] + df['kijun']) / 2
        df['senkou_leading_b'] = (df['ha_high'].rolling(window = laggin_span).max() + df['ha_low'].rolling(window = laggin_span).min()) / 2
        df['senkou_span_a'] = df['senkou_leading_a'].shift(displacement)
        df['senkou_span_b'] = df['senkou_leading_b'].shift(displacement)
        df['chikou_span'] = df['ha_close'].shift(displacement)
        
        df['tenkan1'] = df['tenkan'].shift(+1)
        df['kijun1'] = df['kijun'].shift(+1)
        df['senkou_leading_a1'] = df['senkou_leading_a'].shift(+1)
        df['senkou_leading_b1'] = df['senkou_leading_b'].shift(+1)
        df['senkou_span_a1'] = df['senkou_span_a'].shift(+1)
        df['senkou_span_b1'] = df['senkou_span_b'].shift(+1)
        df['chikou_span1'] = df['chikou_span'].shift(+1)
        
        df['ha_close1'] = df['ha_close'].shift(+1)

        
        # // == Price and Kijun Sen (standard line) Cross ==
        def calcTkCross(x):
            if (x['tenkan'] > x['kijun']) and (x['tenkan1'] <= x['kijun1']):
                intersect = (x['tenkan1'] * (x['kijun'] - x['kijun1']) - x['kijun1'] * (x['tenkan'] - x['tenkan1'])) / ((x['kijun'] - x['kijun1']) - (x['tenkan'] - x['tenkan1']))
                if (intersect > x['senkou_span_a']) and(intersect > x['senkou_span_b']):
                    return 2
                elif(intersect < x['senkou_span_a'])and(intersect < x['senkou_span_b']):
                    return 0.5 
                else :
                    return 1
            elif (x['tenkan'] < x['kijun'])  and (x['tenkan1'] >= x['kijun1']):
                intersect = (x['tenkan1'] * (x['kijun'] - x['kijun1']) - x['kijun1'] * (x['tenkan'] - x['tenkan1'])) / ((x['kijun'] - x['kijun1']) - (x['tenkan'] - x['tenkan1']))
                if (intersect > x['senkou_span_a']) and(intersect > x['senkou_span_b']):
                    return -0.5
                elif(intersect < x['senkou_span_a'])and(intersect < x['senkou_span_b']):
                    return -2 
                else :
                    return -1
            else :
                return 0
        
        df['tkCrossScore'] = df.apply(calcTkCross, axis = 1)
        
        # // == Price and Kijun Sen (standard line) Cross ==
        def calcPkCross(x):
            if (x['ha_close'] > x['kijun']) and (x['ha_close1'] <= x['kijun1']):
                intersect = (x['ha_close1'] * (x['kijun'] - x['kijun1']) - x['kijun1'] * (x['ha_close'] - x['ha_close1'])) / ((x['kijun'] - x['kijun1']) - (x['ha_close'] - x['ha_close1']))
                if (intersect > x['senkou_span_a']) and(intersect > x['senkou_span_b']):
                    return 2
                elif(intersect < x['senkou_span_a'])and(intersect < x['senkou_span_b']):
                    return 0.5 
                else :
                    return 1
            elif (x['ha_close'] < x['kijun'])  and (x['ha_close1'] >= x['kijun1']):
                intersect = (x['ha_close1'] * (x['kijun'] - x['kijun1']) - x['kijun1'] * (x['ha_close'] - x['ha_close1'])) / ((x['kijun'] - x['kijun1']) - (x['ha_close'] - x['ha_close1']))
                if (intersect > x['senkou_span_a']) and(intersect > x['senkou_span_b']):
                    return -0.5
                elif(intersect < x['senkou_span_a'])and(intersect < x['senkou_span_b']):
                    return -2 
                else :
                    return -1
            else :
                return 0
        
        df['pkCrossScore'] = df.apply(calcPkCross, axis = 1)
        
        # // == Kumo Breakouts ==
        def calcKumoBreakout(x):
            if (((x['ha_close'] > x['senkou_span_a'])and(x['ha_close1'] <= x['senkou_span_a1'])and(x['senkou_span_a'] > x['senkou_span_b']))or((x['ha_close'] > x['senkou_span_b'])and(x['ha_close1'] <= x['senkou_span_b1'])and(x['senkou_span_a'] < x['senkou_span_b']))) :
                return 2
            elif(((x['ha_close'] < x['senkou_span_a'])and(x['ha_close1'] >= x['senkou_span_a1'])and(x['senkou_span_a'] < x['senkou_span_b']))or((x['ha_close'] < x['senkou_span_b'])and(x['ha_close1'] >= x['senkou_span_b1'])and(x['senkou_span_a'] > x['senkou_span_b']))) :
                return -2 
            else :
                return 0
        
        df['kumoBreakoutScore'] = df.apply(calcKumoBreakout, axis = 1)
        
        # // == Senkou Span Cross ==
        def calcSenkouCross(x):
            if (x['senkou_leading_a'] > x['senkou_leading_b']) and(x['senkou_leading_a1'] <= x['senkou_leading_b1']):
                if (x['ha_close'] > x['senkou_span_a']) and(x['ha_close'] > x['senkou_span_b']):
                    return 2
                elif(x['ha_close'] < x['senkou_span_a'])and(x['ha_close'] < x['senkou_span_b']):
                    return 0.5 
                else :
                    return 1
            elif (x['senkou_leading_a'] < x['senkou_leading_b']) and(x['senkou_leading_a1'] >= x['senkou_leading_b1']):
                if (x['ha_close'] > x['senkou_span_a']) and(x['ha_close'] > x['senkou_span_b']):
                    return -0.5
                elif(x['ha_close'] < x['senkou_span_a'])and(x['ha_close'] < x['senkou_span_b']):
                    return -2 
                else :
                    return -1
            else :
                return 0
                
        df['senkouCrossScore'] = df.apply(calcSenkouCross, axis = 1)
        
        # // == Chikou Span Cross ==
        def calcChikouCross(x):
            if (x['ha_close'] > x['chikou_span']) and(x['ha_close1'] <= x['chikou_span1']):
                intersect = (x['ha_close1'] * (x['chikou_span'] - x['chikou_span1']) - x['chikou_span1'] * (x['ha_close'] - x['ha_close1'])) / ((x['chikou_span'] - x['chikou_span1']) - (x['ha_close'] - x['ha_close1']))
                if (intersect > x['senkou_span_a']) and(intersect > x['senkou_span_b']):
                    return 2
                elif(intersect < x['senkou_span_a'])and(intersect < x['senkou_span_b']):
                    return 0.5 
                else :
                    return 1
            elif (x['ha_close'] < x['chikou_span'])  and (x['ha_close1'] >= x['chikou_span1']):
                intersect = (x['ha_close1'] * (x['chikou_span'] - x['chikou_span1']) - x['chikou_span1'] * (x['ha_close'] - x['ha_close1'])) / ((x['chikou_span'] - x['chikou_span1']) - (x['ha_close'] - x['ha_close1']))
                if (intersect > x['senkou_span_a']) and(intersect > x['senkou_span_b']):
                    return -0.5
                elif(intersect < x['senkou_span_a'])and(intersect < x['senkou_span_b']):
                    return -2 
                else :
                    return -1
            else :
                return 0
        
        df['chikouCrossScore'] = df.apply(calcChikouCross, axis = 1)
        
        # // == price relative to cloud ==
        def calcPricePlacement(x):
            if (x['ha_close'] > x['senkou_span_a']) and(x['ha_close'] > x['senkou_span_b']):
                return 2
            elif(x['ha_close'] < x['senkou_span_a'])and(x['ha_close'] < x['senkou_span_b']):
                return -2
            else :
                return 0
        
        df['pricePlacementScore'] = df.apply(calcPricePlacement, axis = 1)
        
        # // == lag line releative to cloud ==
        def calcChikouPlacement(x):
            if (x['ha_close'] > x['senkou_leading_a']) and(x['ha_close'] > x['senkou_leading_b']):
                return 2
            elif(x['ha_close'] < x['senkou_leading_a'])and(x['ha_close'] < x['senkou_leading_b']):
                return -2
            else :
                return 0
        
        df['chikouPlacementScore'] = df.apply(calcChikouPlacement, axis = 1)
            
        # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # //
        df['Ichimoku_Score'] = (df['tkCrossScore'] + df['pkCrossScore'] + df['kumoBreakoutScore'] + df['senkouCrossScore'] + df['chikouCrossScore'] ).cumsum()
        
        return df['Ichimoku_Score']

@kunwar-vikrant
Copy link

thanks!!

@rusagent
Copy link

Is this instantly useable with freqtrade?

@berlinguyinca
Copy link
Member

berlinguyinca commented Feb 17, 2021 via email

@XL-Reaper
Copy link
Contributor

This indicator will only got up with the ".cumsum()", right? This cannot be the 1:1 implementation of the zenbot strategy as far as I can see.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Strategy Request Requests asking for an implementation of a specific strategy
Projects
None yet
Development

No branches or pull requests

6 participants