Giter Club home page Giter Club logo

Comments (3)

xmatthias avatar xmatthias commented on May 28, 2024 2

buy_ap: CategoricalParameter([14, 15, 16], default=14, space = "buy", optimize=True, load=True) (and all similar occurances) are type assignments only (buy_ap will still be None after this line).

you'll need to use buy_ap = CategoricalParameter([14, 15, 16], default=14, space = "buy", optimize=True, load=True) in each instance.

from freqtrade-strategies.

yazbuz avatar yazbuz commented on May 28, 2024

oh ok :) sorry for that. thanks a lot. after that i will use =) instead of :)

from freqtrade-strategies.

batuhanhazarguler avatar batuhanhazarguler commented on May 28, 2024

`
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

    alphatrend = self.generateAlphaTrend(dataframe)

    dataframe['k1'] = alphatrend['k1']
    dataframe['k2'] = alphatrend['k2']
    dataframe['signal'] = alphatrend['signal']

    # for elis leverage
    if self.can_use_elis_leverage == True:         
        dataframe['elis'] = alphatrend['elis']

    return dataframe

def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

    dataframe.loc[
        (   
            # (qtpylib.crossed_above(dataframe['k1'] , dataframe['k2']))
            (dataframe['k1'] > dataframe['k2']) &
            (dataframe['signal'].shift(1) == 'sell')
        ),
        'enter_long',
    ] = 1

    dataframe.loc[
        (
            # (qtpylib.crossed_below(dataframe['k1'] , dataframe['k2']))
            (dataframe['k1'] < dataframe['k2']) &
            (dataframe['signal'].shift(1) == 'buy')
        ),
        "enter_short",
    ] = 1

    return dataframe

def generateAlphaTrend(self, dataframe: DataFrame):
df = dataframe.copy()
# ap = 14
ap = self.at_period
# coeff = 1.4
coeff = self.at_coeff

    atr = ta.ATR(df['high'], df['low'], df['close'], timeperiod=ap)

    at = 'k1'
    at2 = 'k2'

    noVolumeData = False
    upt = []
    downT = []
    AlphaTrend = [0.0]
    rsi = ta.RSI(df['close'], timeperiod=ap)
    
    k1 = []
    k2 = []
    
    mfi = ta.MFI(df['high'], df['low'], df['close'], df['volume'], timeperiod=ap)


    # print(at)
    for i in range(len(df['low'])):
        if pd.isna(atr[i]):
            upt.append(0)
        else:
            upt.append(df['low'][i] - (atr[i] * coeff))

    for i in range(len(df['high'])):
        if pd.isna(atr[i]):
           downT.append(0)
        else:
          downT.append(df['high'][i] + (atr[i] * coeff))

    for i in range(1, len(df['close'])):
        if noVolumeData is True and rsi[i] >= 50:
            if upt[i] < AlphaTrend[i - 1]:
                AlphaTrend.append(AlphaTrend[i - 1])
            else:
               AlphaTrend.append(upt[i])

        elif noVolumeData is False and mfi[i] >= 50:
            if upt[i] < AlphaTrend[i - 1]:
               AlphaTrend.append(AlphaTrend[i - 1])
            else:
               AlphaTrend.append(upt[i])
        else:
            if downT[i] > AlphaTrend[i - 1]:
                AlphaTrend.append(AlphaTrend[i - 1])
            else:
                AlphaTrend.append(downT[i])

    for i in range(len(AlphaTrend)):
        if i < 2:
            k2.append(0)
            k1.append(AlphaTrend[i])
        else:
            k2.append(AlphaTrend[i - 2])
            k1.append(AlphaTrend[i])



    df[at] = pd.DataFrame(data=k1, columns=['k1'])
    df[at2] = pd.DataFrame(data=k2, columns=['k2'])

    conditions  = [ df[at] > df[at2], (df[at] == df[at2]), df[at] < df[at2] ]
    choices     = [ "buy", 'same', 'sell' ]
    df["basic_signal"] = np.select(conditions, choices, default=np.nan)


    previous = "same"
    for i in range(len(df)):
      if df.loc[i,"k1"] == df.loc[i,"k2"]:
        comment = previous
      else:
        comment = "buy" if df.loc[i,"k1"] > df.loc[i,"k2"] else "sell"
      df.loc[i,"signal"] = comment
      previous = comment

    if self.can_use_elis_leverage == True:
        elisGenerate = self.elis(dataframe)
        df['elis'] = elisGenerate['elis']
    
    df.fillna(0, inplace=True)
    # df.to_csv('df_at.csv', index = False, header=True)


    
    return df
####### calculate AlphaTrend #######


`

I hope it works. I've been using it for about a year. the profit is pretty low in the strategy I made. I hope you have a better strategy. 👍 :))

from freqtrade-strategies.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.