Custom Indicators In Backtesting.py - Python Deep Dive

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

КОМЕНТАРІ • 55

  • @magellan124
    @magellan124 2 роки тому +9

    finally a tutorial that doesn't just run through the minimalist talib function getting started guide on the docs page! Youre awesome

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

    You're a good teacher, really important to zoom out to give the overview before zooming in. Thank You

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

    Best lesson on Backtesting topic I ever had. Such a consise and clear content, just amazing. Thank you so much!

  • @Alexrmacleod
    @Alexrmacleod 11 місяців тому +2

    but can you run bt.optimise on your params in your custom indicator function?

    • @GlitchMatrix-bs7ib
      @GlitchMatrix-bs7ib 8 місяців тому

      Yeah i believe but then your indicator function has to be in your backtesting class

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

    Thanks mate, you teach excellent!! cheers from Argentina.

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

    Another example is a Doji candle whatever on top or bottom on a day chart has to be confirmed by the following candle. It can be determined the direction by Squeeze or Bollinger band break out method at lower time frame, for instance 5 minute's data(one minute even better), lower the time frame, higher the profit and lower the risk. I wish you could produce such video. That will defeat most indicators even if you may have to use MACD or TSI to help narrow down the approach.

  • @29Bhaskar1984
    @29Bhaskar1984 3 місяці тому

    Great educational stuff. Thanks. But 1 question - why isnt your wall clock working? :)

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

    Very instructive stuff I've been looking for. Thanks

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

    Hi chad very informative. Let's say I was using two sma,s how do I optimize them

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

    May you please do a video on how you clean data, like choosing reliable sources.

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

    Clearly explained the relationship among the three functions. Is there a way to feed an extra(lower) time frame, say 60 minutes to backtesting day data frame, to assistant decision making by checking the top and bottom? For instance, a daily candle''s High greater than close may be the end of uptrend finish, but the top signal has to be confirmed by next daily down candle. if a 60 minute's down candle (for instance, an engulfing pattern) can indicates the top, so a sell signal can be generated on last 60 minute's candle and next 60 minute's open of candle can be used to sell. Furthermore, same principle, 15m time frame can decide the turning point for 60m candle, lower the time frame, the more concise of the turning point of top and bottom, especially 5th wave is counted

    • @dwijgurram5490
      @dwijgurram5490 11 місяців тому

      You can exhaustively lay out all conditions of ant decision tree using nested if else statement

  • @PhatNguyen-mq2ns
    @PhatNguyen-mq2ns 7 місяців тому

    Hi teacher, it's not related to article but you need change battery for your clock.

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

    This is really useful information! thank you so much Chad!

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

    Very Very good presentation!. Unfortunately when i try to use as data a dataframe with signals and prices i have created i get the error: " ValueError: `data` must be a pandas.DataFrame with columns 'Open', 'High', 'Low', 'Close', and (optionally) 'Volume'". Anyway I can get around that? (Meaning that for example I want a strategy where the price ratio of 2 stocks is monitored and when too far away from mean (daily closings) you execute with +/-2std criterion etc. no open high low etc columns in this case...)

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

    Many thanks Chad, is it posible to use another series into indicator function? for example use pct_change of AMZN, to create signals con GOOG?. Best

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

    Thanks a lot for this great information, it's very clear and understandable!!

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

    Great video. Thanks. Just wonder if there is a direct way to embed the interactive chart from the backtestng.py result in a flask framework!

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

      The chart gets exported as a html to the folder you're running it from, so you can likely embed that.
      Might also be an easier way to directly get the html

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

    thank for good video. I wonder if I want something like adx di+ di- in the same indicator how to do it

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

    thanks for your time
    I would love to implement a strategy based on Donchain bands but I can't. can you help me ? A thousand thanks

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

    Nice one guvnor

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

    For plotting, I get an error from bokeh module . Problem may be with the exact module versions I am using. Is it possible for you to share the environmrnt you are using ?

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

      Check the repo, there's a fix for it in the issues tab

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

    Lets say i have an good working system now with good indicators. How can i use this framework for real trading? For example on interactive brokers? What do i have to change? Where do i put my buy/sell signals etc?

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

      Backtesting.py isn't really built for live trading. I'm sure you could adapt the framework to do it for you but you may as well write it from scratch. If you like backtesting.py for backtesting then I'd recommend just building a function/class that handles live trading that takes in a Strategy object and directly pulls the buy/sell logic from there

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

    Hi, does this package only work with GOOG, if not could you please explain how I can use different stocks?

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

      Yeah you'll just need to download some other data, load it in as a pandas dataframe and you're good

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

    Why do I keep getting this error ImportError: cannot import name 'Backtest' from partially initialized module 'backtesting' (most likely due to a circular import)? I have tried renaming the folders but that doesn't work either

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

      I think you have a file called backtest or backtesting or similar

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

    Really appreciate this video! Much like your "Signal Indicator" section, I have already added my indicator values in a column to my DataFrame - I see I can call it in def next(self) via "self.data.". However, is there any way I can plot it as a line on the candle bar chart please, like the examples (in other vids) using SMAs? Would be really great to see my indicator values plotted on the chart

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

      In init(self), you could define an indicator that just uses the values from your dataframe. Then it would get plotted on the chart

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

      @@ChadThackray thanks a lot, I have managed to plot the indicator successfully

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

    Hey Chad, as always good work and many thanks for your effort!
    I implement an custom ma crossover and wondering how to skip candles? E.g. when using crossover function btpy immediately enter a position after closing a previous one. But I want to open a new position e.g. two candles after the previous closed one. I tried it with barssince but without success. How would you approach? Any suggestions?
    Have a nice day!

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

      You can loop over the completed trades, find out when the most recent one was and when it closed, and then open your position that way.
      Alternatively just keep a class variable with the amount of consecutive days that you've not held a position, and write your logic based on that.
      Hope this helps!

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

    how can real apply strategy

  • @avinash-manoli
    @avinash-manoli 2 роки тому

    Hello Chad, thank you very much for your AMAZING!! videos. At 28:35 in your video you mention that Self.data.close can be accessed with any index such as -1, -2, -3 and so on. But when I'm trying to just print "print(self.data.Close[-3])" in the "Next" function, I get the following error "index -3 is out of bounds for axis 0 with size 2". It appears that the index works only until "-2" and beyond that it errors out. Is this the right understanding ?

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

      You should be able to check for the length and / or handle the exception.
      It'll just depend on how many bars of warm up data backtesting.py originally starts with

    • @avinash-manoli
      @avinash-manoli 2 роки тому +1

      @@ChadThackray Thanks for your reply. Yes I was able to handle the exception. Thank you again for your videos on backtesting.py. You are probably the only guy on the internet making such detailed videos on backtesting.py. Please make more videos on this !! :)

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

    my ml model give us 0 and 1. 1 buy and 0 is sell. thats it. Is backtrader ok with ml/dl models ?

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

      You can definitely test the signals. Main problem with ML is avoiding bias in backtesting

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

    legend

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

    Hello Chad, Thanks for your video!
    In 2nd example of "Bollinger Bands using external libraries", my understanding that the self.I() function returns numpy array, hence the Indicatior functrion "return bbands.to_numpy.T[:3]" which is numpy array matched the requirement of self.I() return.
    In last example of Momentom Strat, the indicator function return "data.Close.s.pct_change(periods=7) * 100" which is pandas.series instead of numpy array but it worked fine too. That is the part Im not very understanding, is it must return numpy arrary result to calling self.I()function? Back to 2nd example, Can we just return "return bbands" which is pandas.dataframe to self.I() instead?
    Sorry for my beginner questions as I am not python expert!

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

      Python isn't very strict about type checking like other languages.
      You can return a numpy array, a pandas series, or a pandas dataframe, and backtesting.py will try and handle things appropriately.
      Using any of them is fine, but generally I prefer to use numpy arrays as they are the most predictible

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

      Got it, thanks for your reply😀

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

    hey Chad! first of thank you for the video.
    I was working on a Stochastic indicator and was wondering should I have the calculation for the %K line and %D line within def init or should i have the calculation done before starting the "Class Stochastic(strategy): " or before the def init(self): ?
    my workflow :
    I imported data from the broker.
    Turned it into pandas data frames.
    created function stoch_k() and stoch_d() to calculate the %K and %D .
    I created a function since in init it requires a function after self.I(func,data.close, etc) so my code look something like this
    self.Stochastic = self.I(stoch_k(),self.data.close,12)
    but i got an error said series object is not callable
    ....
    should i have def Indicator first, calculate Stochastic within it and return the value? how should i go about it since i would need 2 values, %K and %D which is a moving average of %K.
    Thank you

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

      I figured it out! but now i got an error said Data Index is not datetime. Assuming simple priods, but 'pd.DateTimeIndex' is advised.
      I assum it has something to do with how i format the data ? i got the data from metatrader 5 and the date time is in seconds, i converted it into date time already so not sure why. from what i read i may need to clarify the column for Backtest to read it.

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

      @@silverhathacker yeah backtesting.py is a bit picky with how it consumes data. Try and take some data from yfinance to compare. Yous should look exactly the same as that.
      Is your date an index or a column? I believe that makes a difference.

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

      @@ChadThackray hey Chad, I figured it out. the Date time needed to be index. then i need to specify the column to use as indicator, so i printed out the Stochastick %K and was able to use it for backtesting. thank you so much !

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

    dude you are awesome

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

    Great 👍

  • @bryan-9742
    @bryan-9742 2 роки тому

    how would this work with regards to crypto currency trading 24/7?
    GREAT VIDEO

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

    pivot point strategy by using backtesting ..video upload..