RSI Divergence Automated In Python | Algorithmic Trading

Поділитися
Вставка
  • Опубліковано 15 чер 2024
  • The RSI Divergence Detection is programmed in python as an automated indicator for algorithmic trading, the Jupyter notebook file is available from the link:
    drive.google.com/file/d/1u2ug...
    🍓 If you want to follow structured courses with more details and practice exercises check my "About" page for Discount Coupons on my Udemy courses covering: Python basics, Object Oriented Programming and Data Analysis with NumPy and Pandas, ... more courses are on the way drop me a message if you have a particular interesting topic! Good luck!
    the data file is available from the following link:
    drive.google.com/file/d/16BZc...
    #tradingbots #pythoncoding #algorithmictrading
    00:00 RSI Divergence In Algorithmic Trading
    07:40 Python Code For RSI Divergence Detection
    11:10 RSI Signal Visualization In Python
    25:05 RSI Divergence Signal In Python
    33:07 RSI Divergence Analysis Visualization

КОМЕНТАРІ • 110

  • @matthewschnitzler3153
    @matthewschnitzler3153 2 роки тому +32

    I have watched your videos a lot. Many of them I have seen over a hundred times each!!!.... I sincerely respect what your doing and appreciate you sharing your knowledge with me. I am still learning but compared to dozens of different youtubers, you have the most mind-blowing strategies along with insanely complex code that you make so easy to understand and beautifully written. You explain it better than anyone else can and I find great success combining your trade strategies with live trading bots. Keep doing what your doing man and one day in the future, I will owe you one. Thanks!

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +13

      I think I will have to print your comment and hang it on my work desk just for the days where I am tired and my code is not working properly 🙂 thank you for your appreciation

  • @russnagel1
    @russnagel1 2 роки тому

    I just found your channel this morning. EXCELLENT EXCELLENT EXCELLENT content. Great job. Keep up the good work. Liked and subscribed. Thank you.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thank you for your appreciation and support, I am happy you liked the content. Good luck!

  • @alpsgrin4501
    @alpsgrin4501 2 роки тому +4

    I can confidently congratulate this is the best deal found for all the time in your videos, here more than 3 buy signals converged)) and, as you can see, it is winning if we entered the deal, take profit can be immediately placed on the flag shape, its double size up)) )) stop-loss resistance line, it was also broken by a gap and there was a round figure with strong players with large volumes !!!

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Yes this deal was appealing also the size of the trade should be dynamic putting a lot of weight on strong signal positions...

  • @diearranz
    @diearranz Рік тому +3

    Hi! and many thanks for your videos, appreciate a lot that you also provide the code! It seems today I found a great channel for algo trading with Python

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Thank you for your support 😊 it's really nice to know that these videos are useful.

  • @flydr2
    @flydr2 2 роки тому +1

    Very well explained... Many thanks

  • @sathr1319
    @sathr1319 Рік тому +1

    Primarily, thank you for putting it all together.
    This was my first time watching any of your videos and now I'm certain I have found the perfect spot in my programming learning journey after watching how detail oriented your video was with a much higher level of clarity than any other training material I have come across.
    In my educational journey with Python Programming for trading I've come across:
    "np.where" - SYNTAX: numpy.where(condition, [x, y, ]/)
    "np.select" - SYNTAX: numpy.select(condlist, choicelist, default=0)
    To name a few, mainly in the interest of reducing computational time in place of using "if", "elif", "else", "for" Loops
    Collectively called Vectorizing with Pandas and NumPy.
    I haven't watch your other videos as yet (which I will for sure), if you may have used these Vectorizing options. But in this video you had mentioned drastic time factoring for logical computing. I'm definietly going to try out your raw code first and then morph it with Vectorizing to enable expanding the window beyond the 500 candles you had considered.
    Please overlook my suggestion if you have already played with Vectorizing. But if you have played with them I would be much obliged if you could point me towards your training material to shorten my learning curve.
    Great respect for your work!!!

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Thank you so much for your supportive comment. You are right vectorization can shorten computing time and it's of crucial importance for good python coding. In my videos I haven't always written code in the best possible way, mainly because my focus was on the trading strategy rather than the code itself. However feel free to take any code and apply your improvements as you see fit, comprehensions can be included as well and vectorization ad you already mentioned. Good luck and happy coding!

  • @PouyaMofidi
    @PouyaMofidi 11 місяців тому +1

    I watched this video two times and I found it excellent. Thank you for sharing us. I prefer to use divergence with MaCD

    • @CodeTradingCafe
      @CodeTradingCafe  10 місяців тому +1

      Thank you for your supportive comment, it's always nice to know that these videos are useful! I will keep note for the MACD maybe in a future video I will include it with the divergence. Good luck!

  • @leducanh2225
    @leducanh2225 2 роки тому +1

    Thank you for your awesome video.

  • @alpsgrin4501
    @alpsgrin4501 2 роки тому +3

    For forex, small timeframes are up to 1 minute, for stocks, a larger timeframe is 15 minutes to 1 hour to enter and watch the smoothness and trailing stop, of course, before entering, you need to look at the larger timeframe what is happening globally with the stock, and if the movement is the same on both timeframes, then this is very good, for example, a reversal from the upper border of the Bollinger Channel, at 4 hour, 1 hour and 15 minutes, then this confident movement down for a long time can be spent in a trade for hours

    • @Zakneteur
      @Zakneteur Місяць тому

      how do you identify clearly a reversal from a Bollinger border ? do you have a reference/book or youtube channel you advice to learn to clearly identify it ?

  • @chandrimad5776
    @chandrimad5776 2 роки тому +1

    Excellent work, thanks for sharing. Will try with long range observation (10 prior to date, 10 after date)

  • @jackroark6928
    @jackroark6928 7 місяців тому +1

    ⭐❤great video. I can apply this to a project I'm working on.

  • @baselsm
    @baselsm Рік тому +1

    thanks for the amazing content, do you advise to to run RSI divergence on heikin ashi candle instead normal one to eleminate noise specially on low time frame

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Thank you for your comment, you reminded me that I have to include heiken ashi candles in here... I usually don't recommend low timeframes for algotrading it's too hard to work it out. But you can always try on HA candles it might solve the noise problem.

  • @musicxplore7926
    @musicxplore7926 Рік тому +1

    Thanks again for your video! May I ask if there is a way to extract macroeconomics data such as inflation, interest, unemployment rates etc. conveniently from python please?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Hi, I haven't tried this yet, but we definitely can scrap news and forums websites in python and use language processing for analysis.

  • @leinadssab
    @leinadssab 10 місяців тому +1

    Great video, thanks! Will try this out..One question though, when using this to generate in realtime I.e. current candle = df[close].iloc[-1]... will it generate a signal on an unconfirmed pivot? I guess it would be nice to know if it's unconfirmed as at least one can wait and see and anticipate the div...

    • @CodeTradingCafe
      @CodeTradingCafe  10 місяців тому

      Hi, thank you for your comment, to solve the pivot issue you can delay the backcandles by let's say a 5 candles window this way after all is confirmed you can detect the divergence. It needs some work and testing though, Good luck!

  • @Jack-uc5ly
    @Jack-uc5ly 2 роки тому +2

    Interesting video! I wonder if somehow you coud use linear regression on the pivot points/highest high/lows and get the steepest angle, so the lines don't intersect, so then you could use when the RSI in general is quite high/low and uptrending/downtrending.
    I'm quite skeptical with these ideas but always fun to test! Thanks, great video

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +2

      Hi, I don't remember if it was this video or a different one, but I modified the intercept of the slopes so they go through the highest high and lowest low, (maybe in the channels detection video) something very similar to what you are proposing, this way price and slopes don't intersect until there is a break from the trend channel.
      I agree it's a lot fun trying around these kind of an addiction at some point.

    • @Jack-uc5ly
      @Jack-uc5ly 2 роки тому +1

      @@CodeTradingCafe ah sweet, will check it out
      Yeah I just seem to be going through books and backtesting their ideas. I'd love to do a book or channel on it because it's just ridiculous what people are selling.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +2

      @@Jack-uc5ly I understand what you're saying ... So many insane winning strategies out there yet no one is that rich yet 🙂. A YT channel is fun to do, a book less rewarding (don't mean money wise, just personal satisfaction) unless advertised properly and reaches a high number of readers. Good luck

  • @kelabux5956
    @kelabux5956 2 роки тому +1

    really good video. completely underestimated. will look through all your other videos soon.
    maybe you try your strategies in freqtrade? Since you could backtest Crytpos...but multiple at once. Will try to pack your strategy in a strategy file and then look what happens :)

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Thanks a lot for your support 😊, I am glad you liked it. Good luck with your strategy.

  • @ventiladorbueno1846
    @ventiladorbueno1846 2 роки тому +1

    Thank you

  • @moussadawood9192
    @moussadawood9192 Рік тому +1

    good work

  • @alpsgrin4501
    @alpsgrin4501 2 роки тому +1

    I understand that this is a load on your computer, but can a colab be used? the tensor processor is there, it is still possible to speed up if you refer to the database in sql, so as not to download the dataframe every time, is it possible to use Cython and the add-on in C languages here

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      I have to think about it and run some tests, I think when a strategy is set this wouldn't be a problem.

  • @ZAREIGH61
    @ZAREIGH61 2 роки тому +1

    Thank you for this great video. Just one question: what is your coding environment for Python? I mean the app name.
    Thank you.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Hi, thank you for your support, I usually use jupyter notebook from the anaconda platform, just download and install anaconda and all is contained within

  • @alpsgrin4501
    @alpsgrin4501 2 роки тому +1

    IF YOU WANT TO COMBINE, the Bollinger channel, for example, will help to find resistance and support lines, the second confirmation of your rightness in finding the extremum is the morning star and Doji and hammer candlestick patterns.
    in both directions, I mean the inverted hammer too, well, the overbought and oversold zones of the stochastic and RSI signal with a trail stop. as they say it's the cherry on the cake )))

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      I agree combining for confirmation is good but then you have very little signals to collect, very frustrating but I have to try it anyway

    • @alpsgrin4501
      @alpsgrin4501 2 роки тому +1

      @@CodeTradingCafe I assure you))) there will be work for us! only for NYSE, AMEX and NASDAQ there are 8389 tickers, and there is also Europe and Singapore and Tokyo stock exchange , we will not be able to keep up with the strategy this is how many opportunities the market offers

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      and which is your favorite timeframe?

    • @alpsgrin4501
      @alpsgrin4501 2 роки тому +1

      @@CodeTradingCafe I only work intraday depends on the broker's commission, of course the timeframe depends on the strategy, which is why I wrote a lot about backtesting and optimization, and if you find a good strategy but it doesn't work) you need to check it on all timeframes and optimize the parameters

  • @lisst2211
    @lisst2211 2 роки тому +2

    how about if i want to do it for group of stocks in dataframe?I failed if making like df['pivot'] = df.groupby('code').apply(lambda x: pivotid(df,x,5,5)),error is
    TypeError: unsupported operand type(s) for -: 'str' and 'int'

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      It's hard to debug online, but the error is coming from data type, I also think this method will not work as intended.

  • @fredc1980
    @fredc1980 2 роки тому +1

    Excellent video. I will test it on BTC and ETH. Just one technical comment regarding the slope line, it shouldn’t cross any of the intermediate prices when connecting swing lows or swing highs or it will be invalidated as a divergence. Any chance to code that?? Thanks

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Hello, thank you, yes it can be corrected by changing the intercept I remember I did this in the channel detection video, there are definitely different ways of coding this.

    • @ariangrainca7915
      @ariangrainca7915 Рік тому +1

      @@CodeTradingCafe Hi can you please link me the video you were referring to talking about changing the intercept to exclude the intermediate crossing points? thanks appreciate your content a lot

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi try this one it might be of help ua-cam.com/video/phy57DZOIwc/v-deo.html

  • @hugomenchaca7216
    @hugomenchaca7216 2 роки тому +1

    Firstly, thanks a lot for sharing, it's a fantastic and great project. I specialist in technical analysis and have been start to develop system with python and backtest them.
    I prefer develop the strategies using a vector matrix due to is faster than the bucles, I like to test over SP500 list stocks, It would be interesting for next proyects that you could test the strategies over a large stocks list.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Hi, thank you for your comment, I wanted to start using stocks but I think I was a bit lazy to move from forex to a different market, I will try SP500 sometime soon and extend from there to other stocks

  • @hawkscoinhood2703
    @hawkscoinhood2703 Рік тому

    Has anyone experimented with adding Hidden Divergence to this code? I am making an attempt. BTW... Code Trading... Your videos are the BEST python trading examples I have found on the internet.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Thanks a lot for your support, always nice to know these codes are of help!

  • @lucksimi3320
    @lucksimi3320 2 роки тому +1

    Great Videos! Can add a BUY &SELL Signal

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      I will and backtest it see what it gives... soon :)

  • @alpsgrin4501
    @alpsgrin4501 2 роки тому +1

    For example, the longest timeframe in the strategy that I know, it is called the Delta phenomenon this strategy has been working for many years, of course you know that a human being is 80 percent water, and the human brain is 90 percent, so every 28 days when the ocean tides, it depends on the Moon, the lunar calendar, each the trader is under pressure from the gravity of the moon, funny but like that= scientific fact

  • @Deb_Learner
    @Deb_Learner Рік тому +1

    I sincerely thank you for sharing the knowledge and code. I am curious make RSI hidden divergence strategy with 7 period. Long conditions: 1) price is > 200 EMA, 2) 20 EMA>200 EMA and 3) RSI makes hidden divergence. BUY signal on the candle that moves high of the previous 2 candles and SL will be below the swing low or low of the reversal candle. Short conditions: 1) price is < 200 EMA, 2) 20 EMA

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi Dipak, you can find most of these indicators and how to use them in python here on my channel download the codes and apply custom modifications your strategy doesn't seem challenging for a a Python implementation. Good luck!

  • @futurestadawul
    @futurestadawul Рік тому +1

    Hi bro...excellent channel for algorithmic trading with Python..Thank you very much for this.
    I am wondering how we can use this with backtrader? If you have any idea..a link or any other kind of help please share it with us. Thank you in advance.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Thank you for your support, I am not really familiar with backtrader, but I am sure there should be an API somewhere... get ready for some python though

  • @PouyaMofidi
    @PouyaMofidi 11 місяців тому +1

    It will works very much better if you filtter pivots of price by one HH after one LL.

    • @CodeTradingCafe
      @CodeTradingCafe  10 місяців тому +1

      you are right the order of the pivots is important, I included the pivots order in a strategy for a video this week... I hope it will be of help. Thanks again for your support!

  • @hasa4628
    @hasa4628 Рік тому +1

    nice did u backtested it?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      I did something recently but I haven't included the trade management part.

  • @sweealamak628
    @sweealamak628 2 роки тому +1

    I've done up my RSI Divergence algo too, different from yours, I followed the simplistic way found on wikipedia. Very satisfying to see it come to life on plotly 😊 Hope you'll be kind enough to give some advice like the last time... my code is getting long (1000+) due to other functions created for overlay, do you think it's necessary for me to create my own package to be imported like TA-lib to "tidy or optimise" my code? Thanks Pro!

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Hi, thanks a lot for your comment it supports the educational spirit of this channel, in my opinion 1000 lines are ok, but if you have functions that you will be using in other codes then go for it create your own home lab package, however if these function are only for this particular code then it's not worth your effort. Good luck!

    • @sweealamak628
      @sweealamak628 2 роки тому +1

      @@CodeTradingCafe Thanks so much for your reply. Yes, the functions are solely used for this piece of code for overlaying trend lines and stuff. Glad to know I'm in normal territory 😅

  • @alpsgrin4501
    @alpsgrin4501 2 роки тому +2

    Congratulations, this is the smartest and best approach to trading. and you are also very attentive to details. noticed a double bounce from the resistance line.
    there is also a breakout with a gap and after a few candles there is a flag figure I think about 7 signals indicate an uptrend.
    it's a pity YOU DIDN'T TEST what would happen if you bought in the found places.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thanks, I was expecting your comments :) I will test a strategy with this indicator, I prefer to do it on a different video because this one was already too long... I was thinking of combining this RSI signal with a trail stop and see where it goes from there

    • @johanhumblet6090
      @johanhumblet6090 Рік тому +1

      @@CodeTradingCafe you could basically backtest it over multiple years with multiple stocks, and then you could calculate your win rate

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      You are right I should test it on more currencies/stocks for robustness

  • @seify4000
    @seify4000 2 роки тому

    you can use the SMA or EMA of price to ignore the sharp peaks of shadows which ruins the algorithm of local max and min defections, becouse it smothen the chart movement.

    • @seify4000
      @seify4000 2 роки тому

      *detection I mean, not defections *

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Yes thank you, are you thinking like a fast SMA? I mean then we have this parameter that would affect the sensitivity of the MA movement

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Nice profile pic by the way

    • @seify4000
      @seify4000 2 роки тому

      @@CodeTradingCafe thank you 🙂

    • @seify4000
      @seify4000 2 роки тому

      @@CodeTradingCafe yes I mean really fast SMA maybe like aveareage of 2 or 3 candles. this SMA doesn't meanful but I think filters the sharpness of local sudden peaks. or zigzag++ indicator which determine the actual peaks and valleys very well.

  • @kikepech
    @kikepech Рік тому

    Nice Video. QQ. is there any update for the code? the line6 (df['pivot'] and df['RSIpivot']); when i try to reply the code i colab, give the next issue: "AttributeError: 'int' object has no attribute 'timestamp'", i dont know what that means.
    Note: all the code was copy and paste in colab.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      it might be related to the type of the time column maybe python is taking it as int you can try to convert to time and see if it works

  • @valueray
    @valueray Рік тому +1

    checking a pivot to the right side will allways be a hindsight problem, no?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, yes absolutely, you can avoid this by leaving a gap with the current candle.

  • @johnlymanliza5713
    @johnlymanliza5713 6 місяців тому +1

    IMO, It will be easier to understand with proper naming of your variables and arguments.

    • @CodeTradingCafe
      @CodeTradingCafe  6 місяців тому +1

      I am genuinely sorry about this, I have always neglected this part of coding which turns out to be important even for my colleagues at work... I improved this a bit recently but the old codes remain the same.

  • @bentz242
    @bentz242 6 місяців тому

    how can we do backtest for this algo-trading?

    • @CodeTradingCafe
      @CodeTradingCafe  6 місяців тому

      Hi, a bit of a work, but the shortest is to put the detection of the pattern in a function (the function should take the current candle index among other params) and then for each candle you call the function to generate a signal then it's easy because you already have the signals to you can use backtesting.py package.

  • @richardbokele830
    @richardbokele830 3 місяці тому +1

    "Thank you very much! But what do you think about using neural networks to detect RSI divergences? ...I'm up for this idea, but I'm not sure if it can work."

    • @CodeTradingCafe
      @CodeTradingCafe  3 місяці тому

      Not a bad idea, but I think using classic analytics like in this video is easier and sometimes even better.

  • @weiSane
    @weiSane Рік тому +2

    Wondering how I can implement this for MQL5. I wish this was in mql5. Way more powerful and convenient for trading than python. But I'm gonna try to do it in mql5 anyway. Wish me luck .

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Hey it's possible to make it in mql5, I used to code mql but moved to python for the machine learning part which is more convenient when needed.

    • @weiSane
      @weiSane Рік тому +2

      @@CodeTradingCafe machine learning in trading? I need to check out more of your videos then

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      @@weiSane it's not that promising so far but I needed to try it and see

    • @weiSane
      @weiSane Рік тому +2

      @@CodeTradingCafe I have been following some dudes articles on MQL5 articles section where he uses mql5 to create machine learning models and so on in mql5 . I think you should check it out too. Interesting how powerful mql5 can be . Never thought it's possible for such stuff honestly

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      ML with mql5! I have to see it

  • @hdfhhddff683
    @hdfhhddff683 2 роки тому +1

    I think the best is trading after rsi breakout.

  • @Aram-SEMO
    @Aram-SEMO 2 роки тому +1

    :)