Profitable Strategy Using Bollinger Bands and RSI Automated in Python

In this video, we present a profitable trading strategy using Bollinger Bands and RSI indicators, automated in Python. The strategy combines Bollinger Bands, RSI, and specific candle patterns to detect reversal points and identify optimal entry positions. We backtest the strategy using Python, accounting for commissions and spread costs, and achieve positive returns. The video covers the strategy rules, demonstrates the Python code used for backtesting, and provides a downloadable link for the code. By integrating Bollinger Bands, RSI, and Python automation, this approach aims to enhance your trading performance. Join us to learn how to implement this effective strategy and test trading results with automated Python scripts.
]]] Drop a comment if you feel like sharing and supporting with some ideas!
Subscribe for more Python trading tutorials and backtesting strategies.
°°° Discount Vouchers for my Algorithmic Trading and Python courses:
💲 Algorithmic Trading: bit.ly/CouponAlgorithmicTrading
💲 Data Analysis with Numpy and Pandas: bit.ly/CouponDataAnalysis
💲 Machine Learning Methods In Algorithmic Trading: bit.ly/CouponMachineLearningT...
Download the Python Code (notebook):
drive.google.com/file/d/1zG8s...
And the data file I used in the video:
drive.google.com/file/d/1k2kG...
#bollingerbands #tradingstrategy #technicalanalysis #stockmarket #finance #investing #automatedtrading #algorithmictrading

Пікірлер: 120

  • @AxelFoster322
    @AxelFoster32211 күн бұрын

    Oh, I love you guys, the best market analysis! Seriously, why not mention Unimantic?

  • @CodeTradingCafe

    @CodeTradingCafe

    11 күн бұрын

    Thank you for your support, we're not aware of UM

  • @FarmerJesse

    @FarmerJesse

    6 күн бұрын

    What's up with spammers trying to promote this unheard of unimantic? Leave us alone, no one wants to buy your crappy unimantic

  • @robertbendkowski3385
    @robertbendkowski338513 күн бұрын

    This is the strategy (well, slightly modified) I’ve been using for the past 2 years on the H1 timeframe across various currency pairs. It’s not fully autonomous - in the end, it is me who decides whether to open a trade or not. My current win rate hovers around 80%, and the return percentage over these 2 years is over 100%.

  • @TheEcherriman

    @TheEcherriman

    13 күн бұрын

    Being nosey, what language have you used - is it Python ? and what feed do you use please ?

  • @robertbendkowski3385

    @robertbendkowski3385

    12 күн бұрын

    @@TheEcherriman Yes, the code is written in Python. I get the data from the broker XTB via API.

  • @omerfaruk1351

    @omerfaruk1351

    12 күн бұрын

    what kind of adjustmens you did if its not private? and also, have you tried it in crypto?

  • @robertbendkowski3385

    @robertbendkowski3385

    12 күн бұрын

    @@omerfaruk1351 Nothing major, to be honest: • Bollinger Bands (BB) calculated over 20 periods. • The candle being engulfed can’t be a Doji or any other variation of a small/no body and long wicks type of candle. • I don’t trade when a signal occurs directly on a Bollinger Band after a nearly vertical move up or down, as this means the trend is strong and I would be trading against the short-term momentum. Price often tends to slow down after a while and move a bit closer to the middle of the BB channel. You can find many divergences there on the RSI, which, when paired with an engulfing bar, usually indicate a great opportunity. That’s mostly what I do. There’s also a bit of gut feeling now and then, but I can’t describe it. I believe it comes with experience. And no, I don't trade cryptos at all. Edit. I would like to clearly state that I am not some internet scammer, nor am I trying to portray myself as a genius trader. I am still not rich, I still do not live off trading, and I still make plenty of mistakes. I am continuously learning, and my trades are sometimes tragically off the mark.

  • @YusufOmanov-gf7ft

    @YusufOmanov-gf7ft

    12 күн бұрын

    does this work on crypto too?

  • @omerfaruk1351
    @omerfaruk135112 күн бұрын

    When the trade count is low, the problem is that we can't fully understand the real winning percentage of a strategy. For example, in probability, when you toss a coin, it's 50% heads and 50% tails, but if you toss it 10 times, you might get 8 heads and 2 tails. However, if you try it infinitely many times, it will converge to 50% heads and 50% tails. To fully understand and test a strategy, especially if we are optimizing the parameters and picking the best one according to historical values, we should be careful about the sample size. In my opinion, 18 is not enough. We can find 500 pairs and find the best parameters for historical data, but as long as the trade count for a pair is small, the winning rate does not prove whether it is a reliable value.

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Absolutely right, the uncertainty is high for low trades count, I should compute the uncertainty actually along with the return value considering the central limit theorem... nice idea thanks again

  • @h345s

    @h345s

    12 күн бұрын

    ​@@CodeTradingCafeSame thoughts here. Nice video. But low number of trades makes it's not so good. As for me backtest should have at least 1000 trades. In other way it's cherry picking. Because of that I like small timeframes. It's give you much better information.

  • @byob801

    @byob801

    12 күн бұрын

    That's a great point. I ran it with SPY and XLK daily data on a shorter period 2018 - 2024 both traded 11 times but the results did not duplicate the BMW data. Both ETFs did poorly and think it's because both ETFs had trending markets over the sample time period, this is best for mean reversion markets. Thanks enjoyed the video.

  • @BoHorror
    @BoHorror13 күн бұрын

    You found the holy grail, congratulations

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Lol thank you, it's a good start but need more tests on robustness.

  • @abdsh422
    @abdsh42211 күн бұрын

    Amazing contribution. You made it easy to start for many people. Thanks for keep contributing!

  • @CodeTradingCafe

    @CodeTradingCafe

    11 күн бұрын

    My pleasure! Thank you for your constant support, you always bring something nice into the comments :) enjoy coding and Good luck.

  • @hu5116
    @hu511612 күн бұрын

    Thanks! Great video with very interesting strategy! You gave me a number of ideas to try ;-)

  • @CodeTradingCafe

    @CodeTradingCafe

    11 күн бұрын

    Great to hear! Coding is always good bringing new ideas I find it stimulating.

  • @TheEcherriman
    @TheEcherriman13 күн бұрын

    Thanks again !

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Thank you too for your support, much appreciated.

  • @harrisonwalker96
    @harrisonwalker962 күн бұрын

    Great video! I will dig into the code in the coming days. Thanks for sharing.

  • @CodeTradingCafe

    @CodeTradingCafe

    Күн бұрын

    Awesome, thank you for your support!

  • @apogounte8239
    @apogounte823912 күн бұрын

    Hi. Nice effort. Had seen the guy that tried this on all russell index stocks. He uses it in 5m , 15m 30m and 1h timeframes.

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Thank you! yes I am not a fan of minutes timeframes but I could test it on 30M or lower for example, if anything interesting I will get back with a video.

  • @Salvasauss
    @Salvasauss13 күн бұрын

    Amazing video, very insightful. I was actually looking into a modified version of this strategy the other day, it's by the youtuber Serious Backtester and he did a great video explaining the strategy and changes he made to it including some amazing backtest results. I was especially interested in the 30 minute time frame 0.15 bbw variant. Maybe you could do a video on it giving some more insight? it's called ''serious RSI - Bollinger Bandwidth strategy''

  • @user-fe1ot6cl1v

    @user-fe1ot6cl1v

    12 күн бұрын

    I coded this strategy for cryto. It doesn't work in my hands. It would be useful to compare with smb else

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Thank you for sharing. I don't remember if I already did the 30 min timeframe, but I could try it again it's not difficult to modify the code for it, should be a quick video (I will dig in the files I might have it already but need time for the video).

  • @CodeTradingCafe

    @CodeTradingCafe

    9 күн бұрын

    The one and only CodeTradingCafe 💪 😂

  • @JohnQuezadaHuayamave
    @JohnQuezadaHuayamave12 күн бұрын

    excelente video.

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Thank you so much!

  • @lorensaunders6034
    @lorensaunders603412 күн бұрын

    I think the key is mostly the two conditions of price action... one candle closing outside of the BB and the other surpassing it in the other direction and to the other side of the BB. I bet it works on multiple timeframes but is best on the H1. Just a hunch.

  • @CodeTradingCafe

    @CodeTradingCafe

    11 күн бұрын

    Hi thank you, I was actually willing to try 1H I don't remember I have made any video here using 1H timeframe...

  • @Monduras
    @Monduras13 күн бұрын

    I’ve also been testing the same strategy with test account and did not consider bb width as an idea… this strategy really depends on the ccy and what std deviations you use.

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Yes I am not sure it's robust enough, but we can test it in different conditions to see.

  • @Monduras

    @Monduras

    12 күн бұрын

    @@CodeTradingCafe what I found interesting is if you extend to two std deviations and allow more than one trade so if it goes up and down around the band a couple of times you can implement a couple of trades in the same direction

  • @CodeTradingCafe

    @CodeTradingCafe

    11 күн бұрын

    Yes I agree, but the risk is higher also

  • @mikecervantes9394
    @mikecervantes93944 күн бұрын

    Awesome job Francis thanks a lot! im here from udemy ;). Have u try this strategy with stochastic i/o rsi? and maybe adding a trailing stop...

  • @CodeTradingCafe

    @CodeTradingCafe

    4 күн бұрын

    Hi, thank you for sharing. I didn't spend all the time I wanted on this strategy yet, I think it is tunable still...

  • @priyansh02chawda
    @priyansh02chawda11 күн бұрын

    This works best in only sideways market

  • @CodeTradingCafe

    @CodeTradingCafe

    11 күн бұрын

    I agree it doesn't seem robust enough to me, can be revisited with mods later on maybe.

  • @jroche1832
    @jroche183212 күн бұрын

    What would be helpful is a calculation of the buy and hold max drawdown so we can see how a strategy compares on a drawdown basis ie an 8% out performance vs B&H is great IF max drawdown is lower by 20%

  • @jroche1832

    @jroche1832

    12 күн бұрын

    Following code could be used: def calculate_max_drawdown(data): # Calculate daily returns data['Daily Return'] = data['Adj Close'].pct_change() # Calculate cumulative returns data['Cumulative Return'] = (1 + data['Daily Return']).cumprod() # Calculate the running maximum data['Running Max'] = data['Cumulative Return'].cummax() # Calculate drawdown data['Drawdown'] = data['Cumulative Return'] / data['Running Max'] - 1 # Calculate the maximum drawdown max_drawdown = data['Drawdown'].min() return round(max_drawdown * 100, 2)

  • @CodeTradingCafe

    @CodeTradingCafe

    11 күн бұрын

    That's a good point, sometimes B&H seems better in returns but might be risky in DD, we can easily run a backtest just buying at the beginning of the dataframe and holding till the end of the test. Thank you for the code as well!

  • @DalazG
    @DalazG12 күн бұрын

    Curious how big of a forex account would this require to be successful? And can it be configured with mt4?

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    it can be configured, but I wouldn't trade it, it need to be tested also for robustness, different assets and different conditions.

  • @orderflowdojo
    @orderflowdojo5 күн бұрын

    😎📈

  • @CodeTradingCafe

    @CodeTradingCafe

    4 күн бұрын

    Thank you!

  • @emeraandhanshe5954
    @emeraandhanshe59547 күн бұрын

    Any chance this can be coded in PINEScript to create a indicator in TV

  • @CodeTradingCafe

    @CodeTradingCafe

    6 күн бұрын

    Hi, it can be translated but I don't do pinescript myself (try with chat GPT it might help)

  • @standup9729
    @standup97299 күн бұрын

    which market can use for this strategy? Can it use for forex, please?

  • @CodeTradingCafe

    @CodeTradingCafe

    9 күн бұрын

    Any market might work and might not, we need to try it, but yes I think forex is a good start.

  • @davidsalzgeber4792
    @davidsalzgeber479210 күн бұрын

    Your videos inspired my to build my own trading bot. I created a oanda demo account and wrote some code and deployed it. The problem i currently have, is that i have to pay a lot of swap. (I did some research, as far as I understand its just overnight fees.) The swap is in my case really high, nearly 0.1% of my invested capital per day. When investing in stocks over a few months, the swap would eat all my profits. Especially on the daily timeframe. What can i do about that? (I am new to that subject, so it is possible that i missed something very obvious)

  • @CodeTradingCafe

    @CodeTradingCafe

    9 күн бұрын

    Hi, yes I suffered from swap at some point with Oanda, and sometimes swap can be positive meaning you earn on the opened trades! yes it's a small interest for some forex pairs and in one direction for example on USDCHF if you buy/long you get interest but if you short you pay interest... anyway to get rid of this check in your region if Oanda has other types of accounts that don't make you pay swap or overnight fees, if not check other brokers as well, my friend uses CFI in the MiddleEast region he can leave Forex trades opened for 3 month with no additional fees!

  • @davidsalzgeber4792

    @davidsalzgeber4792

    5 күн бұрын

    @@CodeTradingCafe Thank you for the explanation! It makes a lot of sense. I am currently working an a BTCUSD Trading Bot and it got great results in the backtests over the last 4 years. The strange thing is, that i have to pay swap for going long and short. I will probably have to switch the broker, but that should not be that big of a deal.

  • @bipmix
    @bipmix11 күн бұрын

    Just joined and the code link won’t load into Phythpn or Anaconda to test, any suggestion is appreciated

  • @CodeTradingCafe

    @CodeTradingCafe

    9 күн бұрын

    Open Jupyter notebook and try to load/open the file from there.

  • @fusionsamayal6384
    @fusionsamayal63848 күн бұрын

    Hi this is wonderful high probability setups. Thanks for sharing. Whrere can I find the python code?

  • @CodeTradingCafe

    @CodeTradingCafe

    7 күн бұрын

    Hi, thank you, the code is in the link in the description

  • @fusionsamayal6384

    @fusionsamayal6384

    7 күн бұрын

    @@CodeTradingCafe Thanks for the reply. Tried the code shows error

  • @saumikhan2655
    @saumikhan2655Күн бұрын

    hi sir, how can i put this python code in mql4 file ? if i put it there and execute it would it be turned into mql4 ea file?

  • @CodeTradingCafe

    @CodeTradingCafe

    17 сағат бұрын

    Hi, you need to translate from python to mql language.

  • @dilanjayaweera1634
    @dilanjayaweera16346 күн бұрын

    Are you currently running any bot with real money? can you share the status of that bots like you previously did?

  • @CodeTradingCafe

    @CodeTradingCafe

    5 күн бұрын

    Hi, actually around +8% to +14% yearly return (so I can't buy an airplane yet). I run it on low risk setup but I can push it up to 20% yearly I just don't like risk. It runs on the daily and 4H timeframe so it's slow, around 2 signals per month.

  • @dilanjayaweera1634

    @dilanjayaweera1634

    5 күн бұрын

    @@CodeTradingCafe Thank you for replying

  • @vishalkanodia4830
    @vishalkanodia48306 күн бұрын

    hello please help me in using this in trading view for INDIAN share market

  • @CodeTradingCafe

    @CodeTradingCafe

    6 күн бұрын

    Hi, unfortunately I don't trade specific markets but you can adapt any of my codes on this channel. Good luck!

  • @yashpatel2458
    @yashpatel245811 күн бұрын

  • @CodeTradingCafe

    @CodeTradingCafe

    9 күн бұрын

    Thank you !

  • @maheshmohan3885
    @maheshmohan388512 күн бұрын

    Bro I want to backtest it on Btc usdt 4HR time frame I will do backtest and put the result as comments here....

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Good luck! and thank you for sharing!

  • @rajutandale6663
    @rajutandale66638 күн бұрын

    sir pl. code for india stock market

  • @CodeTradingCafe

    @CodeTradingCafe

    8 күн бұрын

    Hi, really sorry I am not familiar with the indian market, but if you like a strategy here you can adapt easily to any asset you are trading.

  • @sachin6757
    @sachin675710 күн бұрын

    @CodeTradingCafe I have a strategy. Could you please check and let me know 1. RSI above RSI MA 2. close should be above 20 ema to take entry

  • @CodeTradingCafe

    @CodeTradingCafe

    9 күн бұрын

    Hi, this is not a strategy, it's 2 indicators combined, there is a lot to consider when you need to backtest including the trade management part. You need to provide more details like the length of the RSI, the length of the MA of the RSI, when RSI above MA are we talking exactly about when the RSI crosses above the MA?... If you decide to code strategies, the advantage you will gain is thinking in details :) I strongly encourage you to try, your whole trading experience will change. Edit: sorry I just noticed how long my message is.

  • @sachin6757

    @sachin6757

    9 күн бұрын

    @@CodeTradingCafe thanks for your reply. Yes, I am working on strategy based on these 2 indicators to take entry.

  • @davidsaurel4012
    @davidsaurel401210 күн бұрын

    Discarding short trades and you get 100% WR

  • @CodeTradingCafe

    @CodeTradingCafe

    9 күн бұрын

    Thank you for pointing this out. But I am afraid the total number of trades is low so this is not very accurate we would have to test it on different assets as well.

  • @ChandanSah-un2xg
    @ChandanSah-un2xg7 күн бұрын

    60% return from 2011 to 2024?

  • @CodeTradingCafe

    @CodeTradingCafe

    7 күн бұрын

    Yes but these strategies can be deployed on multiple assets at the same time so you can trade for instance 30 assets in parallel.

  • 9 күн бұрын

    Only 18 trades and 66% return over such immense timeframe (13 years) is actually pretty bad. Notice that the dataframe has an open value of 59.2 in the first row and a close value of 101.386 in the last row. Buying the asset in the first day and selling in the last yields a return of 71.26% by doing absolutely nothing. The strategy is actually underperforming the simplest strategy, which is buying and holding.

  • @CodeTradingCafe

    @CodeTradingCafe

    8 күн бұрын

    Hi, thank you for sharing, I understand your point I do agree partially though. The buy and hold strategy works only on increasing assets, imagine I tried the same strategy on a different stock or a forex that went down so basically the buy and hold will be in the negative, I avoid taking it as a reference. I do agree though that the number of trades is low however I have read many professional traders books and they do have this kind of "selective" strategies too, the solution is to run the strategy on multiple assets at the same time.

  • 14 сағат бұрын

    @@CodeTradingCafe it isn't about actually deploying a buy-and-hold strategy, but to establish a baseline for comparison. The strategy in the video spans through more than a decade and it is easy to lose perspective. Taking 18 trades and having 66% return, while keeping the capital committed to run it, is really ridiculous. The point is: the performance evaluation invalidates the strategy completely.

  • @user-lc4pl4vk5t
    @user-lc4pl4vk5t13 күн бұрын

    Hi, I have a bot Idea if you want to test

  • @CodeTradingCafe

    @CodeTradingCafe

    12 күн бұрын

    Hi, send me an email, I will check if it has potential... codingntrading at gmail com

  • @JonahScott-on7md
    @JonahScott-on7md13 күн бұрын

    Great transmission, as always. I appreciate the no-nonsense approach you take to the news and the markets. A lot has changed and that's about it ,but the truth is that I don't even care much about the bull or bear market anymore because Sarah Mackenzie covered me while I'm doing comfortable.20k 30k every week and I'm still counting thanks to her ❤💗💗

  • @FridayNaomi

    @FridayNaomi

    13 күн бұрын

    Sarah Mackenzie's crypto knowledge is like a secret recipe for success

  • @EvelynDiana773

    @EvelynDiana773

    13 күн бұрын

  • @Stevenuer0iq

    @Stevenuer0iq

    13 күн бұрын

    I remain eternally grateful to Sarah Mackenzie for her efforts that got me to this point , finally paid off my mortgage and all my debts, what more could I've asked for. She changed my life for good

  • @martinevans2547

    @martinevans2547

    13 күн бұрын

    Please educate me, I've come across this before. How can I get to her please?

  • @Doreenmolly

    @Doreenmolly

    13 күн бұрын

    Get her on

  • @TheEcherriman
    @TheEcherriman10 күн бұрын

    Hi, I've been trying to adapt your code for FX (EURUSD H1 in this case) In the Scatter chart part (e.g) the following line threw a type error line=dict(color='green', width=1), - which was corrected with line={'color': 'green', 'width': 1}, However, once I was in the backtest section, the following errors occurred ValueError: Long orders require: SL (1.080610316351981) ValueError: Short orders require: TP (1.1016589696057346) Any tips on how to debug this, please ?

  • @CodeTradingCafe

    @CodeTradingCafe

    9 күн бұрын

    Hi, yes the TP values are not aligned with the trades and the TP distances, recheck the conditions why and how are these values messed up, so it's basically the values of TP and sL you need to recheck the rules and make sure the values are computer correctly.