Surprising Differences in Bollinger Bands: Python Backtesting & Strategy Analysis

Поділитися
Вставка
  • Опубліковано 5 лис 2024

КОМЕНТАРІ • 63

  • @andreaardemagni6401
    @andreaardemagni6401 5 місяців тому +10

    I would also suggest to show the performance on a down trending stock - in other words but what happens with this strategy if your stock becomes unliked by the market?
    Overall, very good video. Thank you

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

      Thank you for your support, yes I assume we can apply symmetrical conditions for short positions as well, not sure about the results though.

  • @Ed-ix2vk
    @Ed-ix2vk 4 місяці тому +1

    What do you think of adding bid-ask spread and slippage?

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

      On lower timeframes that would cancel most of the returns, on 4H and daily it's good, actually the commission I added 0.002 is relatively large and covers for spread and slippage)

  • @cyclingchantal
    @cyclingchantal 5 місяців тому +2

    I have seen a strategy with the BB on the 4 hr timeframe. When price breaks upper BB, strategy would go short until MA is reached. Or long when breaks bottom BB.

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

      Yes I have a video on this one it works well this way, check this ua-cam.com/video/f6Nh4guZPRs/v-deo.html

  • @go_3691
    @go_3691 5 місяців тому +1

    Hi just wanted to say I love the work you did on Rayner teos strategy amongst all the work you put in. Is it ok to ask whether you could backtest a simple strategy with a set of simple rules? It’s a price action strategy. I’ve been confused. (I’m a swing trader who’s doing well in demo/forward testing but I’m struggling with becoming profitable for various reasons one is over holding positions etc, and I’ve heard all types of ways to backtest but just not getting it. apologies for being long winded and I hope my ask isn’t too much. Thanks in advance.

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

      Hi, thank you for your support, send me the conditions of the strategy, I will make a video if it's interesting. If you prefer to send an email it's codingntrading at gmail com

    • @go_3691
      @go_3691 4 місяці тому

      Hi, no pressure. Just wanted to let you know that I’ve emailed you and was wondering if you’ve seen it by any chance. Thanks again

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

      Hi I've seen it among others, not managing well to be honest 😂

    • @go_3691
      @go_3691 4 місяці тому

      Wow I can imagine. I can tell it’s been overwhelming. Do you have any solution to that?

  • @eitan71
    @eitan71 5 місяців тому +2

    what if you use crypto with "heavy" coins like BTC or ETH and even "crazy" coins like meme coins, AND Long and Short?
    how would that go?

    • @CodeTradingCafe
      @CodeTradingCafe  5 місяців тому +2

      I wasn't trying much with crypto but you are right, actually the advantage with crypto is that the volume data is centralized so we can use the volume information also for trading... more videos :)

    • @eitan71
      @eitan71 5 місяців тому +1

      @@CodeTradingCafe That would be great to see.
      Thank you!

  • @YusufOmanov-gf7ft
    @YusufOmanov-gf7ft 5 місяців тому +6

    Hi testing please this strategy next time from (serious backtester, Consistently Profitable Trading Strategy! 200,000+ Trade Backtest! Best Results Yet!)

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

      It rings a bell, I probably have the code somewhere because I remember the video. I will check it out and make something if the results are interesting to show.

    • @YusufOmanov-gf7ft
      @YusufOmanov-gf7ft 5 місяців тому

      He said this strategy is the best he has seen.

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

      yes I recap, there is only one way to find out :) let's add it to the list

  • @konstantindevelops131
    @konstantindevelops131 5 місяців тому

    So if I have a Binance trading bot that fetches data from the Binance API, then calculate the bollinger_bands with that data, I will have different amounts than TradingView for example?
    Meaning -> working with Binance API data will make my plot different than the one in TradingView after adding a BBand per say?

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

      The data might be slightly different but actually it's the BB computation that might be very different depending on which formula the platform is using, but if you are getting just price data from the platforms (Binance and TV) and you compute the BB in python let's say using the same approach then there is no reason to see large differences.

  • @tmyersf4
    @tmyersf4 5 місяців тому +1

    I saw an interesting video a few weeks ago from Nick Shawn - how i make money trading, even when i’m wrong. Might be good to try and automate this in python and see how it works out in a live trading scenario. An algo shoud easily be able to work out the optimum position size

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

      Hi, thank you for the tip, yes I think he focuses more on the trade management side which we/I should start considering for the videos here.

    • @OneCreator87
      @OneCreator87 4 місяці тому

      That's a manual strat, you can't code human discretion.

  • @randomdude7386
    @randomdude7386 5 місяців тому

    I find your results to match the potential flaw in your implied thesis on this test. You assume this will detect opportunities in already bullish markets. But the screen shot is trading sideways, like a commenter already pointed out. This in turn means the band should be relatively stable as volatility is relatively uniform. Now a rally starts the band shoots up, now you only look for confirmation for this bullish inclination and there you go. At the same time if you want a warning signal against a market shift this looks like it would warn you of a turn in the market's behavior which would typically end in a price correction that causes draw down in a long only strategy. I think this is more of change of pace detector then anything. This in turn means looking for bullish signs in a bull market will not yield an edge on outright holding. Imagine you have a strategy that uses IV changes to deduce good entry points, well a short squeeze like GME will screw you royally because you are not looking for it but you dont filter it out. I hope this helps to illustrate my point

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

      Thank you for your detailed comment. I agree that the current test conditions in a sideways market might not highlight the full potential of the strategy, it's true that the indicators are showing more the start of a potential rally. Your example of IV changes and the impact of events like short squeezes is also very relevant. This means that we keep the indicator but we will use it for completely different purposes now... looks simple but it gets complicated very quickly :)

  • @jroche1832
    @jroche1832 5 місяців тому +1

    For a strategy to be 'successful' it needs to a) outperform buy and hold b) have a lower max drawdown than buy and hold. Many so called 'strategies' are profitable but they are not good enough to out perform 'buy and do nothing'. You can buy the close and sell the open on SPY and be profitable... but massively underperform B & H

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

      Hi, I agree, in principle yes, but no realistic strategy will beat a buy and hold on strong and always long stocks, like Amazon, apple, MS, SP500... historically on a monthly/daily timeframe these were always trending up with some retracements, it's very exceptional if a a strategy can beat B&H on these stocks. But in principle yes I agree with you on the 2 rules especially drawdown often disregarded in backtesting. That being said, the strategy in this video is a very bad one 😂

  • @dilanjayaweera1634
    @dilanjayaweera1634 5 місяців тому +1

    I need a help any one please
    in Backtesting py how to use " limit " in self.buy()

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

      When you pass a buy or sell you can use the limit parameter and provide where at which price the limit is placed: self.buy(sl=sl1, tp=tp1, size=self.mysize, limit=limitvalue)

    • @dilanjayaweera1634
      @dilanjayaweera1634 5 місяців тому

      @@CodeTradingCafe is limitvalue just a number?

    • @dilanjayaweera1634
      @dilanjayaweera1634 5 місяців тому +1

      if I add current candle high as limit and next candle go above that price what is the entry price?
      entry price = limit price or second candle's open price?

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

      It's the entry price that you entered that will be taken into account as entry.

  • @yuvl32
    @yuvl32 5 місяців тому +8

    It doesn't look like this strategy is good for trending stocks, on the screenshot it doesn't look trending up, it looks like it was sideways for quite a long time before breaking up. In general trending stocks would have a hard time breaking the channel, because the channel will be very large. I would rather expect breaking channel from stocks that don't change a lot, so the channel is small, but for some reason they get attention and price rockets up high.

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

      You have a point, it also depends on which BB channel we use, all in all I don't think it's a stable strategy, signals are not really clear to me.

  • @aaronsarinana1654
    @aaronsarinana1654 5 місяців тому +1

    Good video! Thanks.

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

      Glad you liked it! Thank you for your support.

  • @abhishekjain3045
    @abhishekjain3045 5 місяців тому

    hi, you will never get singnal for this strategy in highly liquid stock. only low flot stock show this kind of movement.

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

      I agree, I noticed it highly depends on the channel width, but since the original video used 4X standard deviation I had to try it, but it's way too wide for a break out to happen. So yes no signals most of the times and for a lot of stocks.

  • @NikolaDragutinovic-xw8ct
    @NikolaDragutinovic-xw8ct 5 місяців тому

    Yes but can you please implement the leverage in the next video because the backtesting changes dramatically with just 30 leverage

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

      I could, if you are running the code actually it's very simple to modify the margin ratio so the leverage, otherwise I will keep it in mind for future videos, But I personally don't like high leverage it's not sustainable.

  • @BoHorror
    @BoHorror 5 місяців тому +4

    Why don’t you ever look at research papers instead of UA-camrs for results, as often research papers often have proper back tested results compared to UA-cam just being mainly a entertainment platform

    • @RafaelHaak
      @RafaelHaak 5 місяців тому

      Please! Provide some examples for us rookies. 😉

    • @CodeTradingCafe
      @CodeTradingCafe  5 місяців тому +7

      I hope my answer will not sound harsh, I have published numerical/modelling papers (over 65 academic papers, mostly in physics) and I am really familiar with the scientific/academic world. In this field (trading and backtesting) I found more interesting approaches than academic papers here on YoouTube (I repeat... in the field of trading only), more pragmatic and straight to the point. That being said, I still read financial research papers (average 2/week) to follow what's happening, now everyone is tweaking Machine Learning but nothing interesting so far. What I found interesting are books (some are useless though, but other can bring some inspiring ideas).

    • @animuhur1823
      @animuhur1823 5 місяців тому

      ​@@CodeTradingCafecould you suggest which books ?

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

      Robert Carver's are a good start

    • @esostoic
      @esostoic 5 місяців тому +1

      I've tested a lot of strategies from papers and most are garbage tbh. Luckily de prado brought more light to the problems within the academic realm of financial research.

  • @vassiliscapsis5828
    @vassiliscapsis5828 5 місяців тому

    Hi Ziad. I do not think it is a good strategy. For a strategy to be considered as viable it should perform at least 2x better than the buy and hold approach.

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

      Hi, it's hard to beat the buy and hold for stocks who had a long term uptrend (daily timeframe) because a buy position keeps earning profit. But I agree with you that the strategy is really bad, at first the indicator showed 0 signals I had to tweak it to get a signal out, so it's all unclear.

    • @vassiliscapsis5828
      @vassiliscapsis5828 5 місяців тому

      @@CodeTradingCafe yes I see your point. We should think about something like a trailing stop in order to stay in the trade longer. The ATR is good approach and we could use it as our trailing stop. I do not know how I could program it in python though (yet hehe). The idea for a long trade is that once the ATR is set to not go lower, only higher as price moves higher and remain 2 ATRs below the highest price. So practically trading without take profit. Only a moving stop loss.

    • @CodeTradingCafe
      @CodeTradingCafe  5 місяців тому +2

      I can see that you didn't watch the full video :) hmm check the code the trailing stop is there, I used both a percentage trail and an ATR trail in the code (download file I mean, the video only shows percentage trail stop).

    • @vassiliscapsis9932
      @vassiliscapsis9932 5 місяців тому

      @@CodeTradingCafe haha you caught me, I skipped to the results and did not watch the rest of it.

  • @نشامي
    @نشامي 5 місяців тому

    My opinion on these type of startegies is that they are super stupid and A waste of time

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

      You might be surprised to see a very simple (super stupid) strategy working well on a real account. I tried very complex strategies including Machine learning, neural networks ... simple works best (not the strategy in this video though), and it's much easier on higher timeframes.