tw7613781 / daxiang_trade

A auto trading system for Bitmex
14 stars 7 forks source link

Adding new strat #4

Closed thorjeus closed 5 years ago

thorjeus commented 5 years ago

Hi dev,

Congrats, finally it's on the run. Found that current strategy is not yet effective (personally to me) since the result is negative for testing in few hours.

And since i am not a coder, could you please give a hint how to integrated this rsi strat into the module i use? Tried that manually but there is error in importing related to portfolio.py (error in importing MACD)

This could be another strat to use:

def relative_strength_index(df, n): """Calculate Relative Strength Index(RSI) for given data.

:param df: pandas.DataFrame
:param n: 
:return: pandas.DataFrame
"""
i = 0
UpI = [0]
DoI = [0]
while i + 1 <= df.index[-1]:
    UpMove = df.loc[i + 1, 'High'] - df.loc[i, 'High']
    DoMove = df.loc[i, 'Low'] - df.loc[i + 1, 'Low']
    if UpMove > DoMove and UpMove > 0:
        UpD = UpMove
    else:
        UpD = 0
    UpI.append(UpD)
    if DoMove > UpMove and DoMove > 0:
        DoD = DoMove
    else:
        DoD = 0
    DoI.append(DoD)
    i = i + 1
UpI = pd.Series(UpI)
DoI = pd.Series(DoI)
PosDI = pd.Series(UpI.ewm(span=n, min_periods=n).mean())
NegDI = pd.Series(DoI.ewm(span=n, min_periods=n).mean())
RSI = pd.Series(PosDI / (PosDI + NegDI), name='RSI_' + str(n))
df = df.join(RSI)
return df

Appreciate for your kindly help. Thanks & regards.

tw7613781 commented 5 years ago

Thank you, thorjeus.

You are right, the current strategy is just for demo purpose, it's not profitable.

Adding the rsi into strategy.py is easy, the important thing is how to define your strategy with rsi. for example, rsi value > 80, sell. value < 20, buy. if you check MACD() function in strategy, it will return a signal (bull, sell, nothing). Then the portfolio class is able to process the ordering based on the signal.

Please give me a suggestion on how to use rsi. it might be even used together with macd. I will add it to system later based on your opinion.

Regards

Max

thorjeus commented 5 years ago

Hi Dev,

I'm not quite sure in how to get it into it, my logical is simple for using rsi as strat, eventhough rsi is not the accurate one for strat.

    if self.last_operation != "BUY":
        if self.rsi < 30 and self.sma_fast > self.sma_slow:
            self.long()

    if self.last_operation != "SELL":
        if self.rsi > 70:
            self.short()

Just maybe, imho this api quite useful to use https://api.cryptowat.ch/markets/bitmex/btcusd-perpetual-futures/ohlc

I hope i can help you out, but currently i will be a tester :( Have to learn in coding lol

Keep up the great work dev. This programs deserve to be maintained.

Thanks & Regards.

tw7613781 commented 5 years ago

I added your strategy, and if you add more please refer to the WIKI https://github.com/tw7613781/daxiang_trade/wiki/system-modularity

thorjeus commented 5 years ago

Hi Dev, I just came up with another idea in implementing rsi strat where the bot is buying at per level we set, so the idea will be like this:

Strategy:

  1. RSI Short: it will accumulate the buy at rsi 70< as the first buy then make another buy at 80< and 90<
  2. RSI Long: it will accumulate the buy at rsi 50> as the first buy then make another buy at 40> and 30>

In a table, it could be seen like this with an example of 10 contract amount

RSI Short 70< first buy, amount = 10 x 1 -> 10 contracts 80< second buy, amount = 10 x 2 -> 20 contracts 90< third buy, amount = 10 x 3 -> 30 contracts

RSI Long 50> first buy, amount = 10 x 11 -> 10 contracts 40> second buy, amount = 10 x 2 -> 20 contracts 30> third buy, amount = 10 x 3 -> 30 contracts

Closing options:

  1. RSI from 70< will be closed at 30< and vice versa, RSI from 30> will be closed at 70>
  2. RSI from 80< will be closed at 40< and vice versa, RSI from 40> will be closed at 80>
  3. RSI from 90< will be closed at 50< and vice versa, RSI from 50> will be closed at 90>

Stop loss: RSI Short: 110< RSI Long: 10>

Sorry, this is just an idea, if it become a scalping method it still profitable after all, i guess. Thank you.