Automated Price Trend Lines in Python | Algorithmic Trading Indicator

Поделиться
HTML-код
  • Опубликовано: 26 фев 2023
  • Presenting a unique algorithm implemented in python for finding trend lines on price data. The python code shown builds a powerful trading indicator the slope of the current trend lines. I've used this indicator in the past as an input to predictive models. The algorithm could also be used as a component for recognizing chart patterns such as wedges, triangles, pennants and so on.
    The automated support and resistance trend lines are found using a gradient descent approach. It creates a price channel on any length of data. It has only one adjustable parameter, the number of candles in which the trend lines are fit.
    Full Code: github.com/neurotrader888/Tre...
    Patreon: / neurotrader
    The content covered on this channel is NOT to be considered as any financial or investment advice. Past results are not necessarily indicative of future results. This content is purely for education/entertainment.

Комментарии • 31

  • @zhendongtian6715
    @zhendongtian6715 Месяц назад +2

    Additional things to try:
    1. Define a quality score: calculated as how closely the trendline matches the highs and lows (this rules out sudden price change and pave way for dynamic trend lines)
    2. Dynamic trend line: set a range of periods (7-30), calculate trend line for each period but only select one with best quality score (We can call it true trend line).

  • @rverm1000
    @rverm1000 9 месяцев назад +4

    Nice just shows I got along way to go to get better at programming

  • @LongTu167
    @LongTu167 3 месяца назад +1

    Amazing, thank you very much!!!

  • @probablyonthemoon
    @probablyonthemoon 5 месяцев назад

    Howdy Brother, love your work! Was wondering, do you log-transform price data before testing? Crypto prices can be very YEEHAW exponential

  • @SataMoore
    @SataMoore 2 месяца назад

    I am wondering how to ensure k bars within the tread channel as shown in the presentation, since with MSE the fitted data (the low values in the support mode for instance) must scatter along the trendline.

  • @brendanlydon5272
    @brendanlydon5272 Год назад +1

    Would you consider the normal equation instead of GD if n < 10^4? Unreal content btw. Would love to see a video on a long/short strategy with a neural net and playing with many feature variables predicting X candles ahead. Distance to vwap, 2nd stddev bollinger bands, maybe distance to top/bottom trend lines in current trend?

    • @neurotrader888
      @neurotrader888  Год назад +1

      Since we have the constraint of the trend lines being above and below all points we can't use the normal equation. As far as I know..
      I'll do some neural net content eventually it has been requested a few times. Its a complex topic so its difficult for me to make a one-off video for it.

  • @gustavnilsson9589
    @gustavnilsson9589 10 месяцев назад +1

    can you do a alogorithm that see an uptrend using the trend follow strategy?

  • @GaryBernstein
    @GaryBernstein 7 месяцев назад +2

    can you share the C/C++ code?

  • @ancientindian
    @ancientindian Год назад

    very nice. thanks. Have you also worked on automating the horizontal breakout levels (up, down), say for past 50 periods? So, instead of slant trendlines, you have horizontal breakout levels touched by maximum opens and closes of all candles in a given range.

    • @neurotrader888
      @neurotrader888  Год назад +4

      Yes I have. I have experimented with a few methods for horizontal levels or support/resistance levels. I'll make a video(s) about one or more of them eventually. Essentially they all search for prices that the market has repeatedly formed a local top/bottom. ( Local top/bottom finding algorithms will actually be my next video, in progress)
      One good approach I've used is presented in this paper:
      Zapranis, A. and Tsinaslanidis, P. 2012. Identifying and evaluating horizontal support and resistance levels: an empirical study on US stock markets. Applied Financial Economics. 22 (19), pp. 1571-1585.
      Another method I've tried finds local tops/bottoms and estimates the distribution of their prices using the parzen window method. Then the horizontal levels can be found by finding peaks in that distribution.
      Thanks for watching

    • @ancientindian
      @ancientindian Год назад

      @@neurotrader888 will check out your paper, look fwd to your next vid. thanks

  • @DeAdBiGeYeFiSh
    @DeAdBiGeYeFiSh 10 месяцев назад +2

    I think that a simpler way (in terms of steps of calculations) performs better in terms of computational complexity.
    For the bottom line: Start with a line joining the pivot point (or starting point) with the next point of close/low. Then go on checking the next points one by one. If the next is above the line, just pass. Otherwise, switch the line with the line joining the starting pivot point with this new point. By the end you have the desired trend line.
    I find your steps more conceptually appealing though, the people who would probably disagree would be CS heads that tend to prefer faster iterative/recursive algorithms.

    • @ranitbose9609
      @ranitbose9609 5 месяцев назад

      This isn't equivalent to what he's doing. This is because the line that minimises the MSE while having all points above the line doesn't necessarily pass through two points.
      However, I actually like your approach better and I think it aligns more with how trendlines should be drawn

    • @DeAdBiGeYeFiSh
      @DeAdBiGeYeFiSh 5 месяцев назад

      @@ranitbose9609 It is equivalent.
      Assume it doesn't. Then every point past the pivot point is strictly above the line. Therefore you can increase the angular coefficient of the line, obtaining one that is still not above any point but that is closer to every point past the pivot - therefore having a smaller MSE, contradicting the assumption that it minimizes it.

    • @poisonza
      @poisonza 3 месяца назад

      Similar enough IMO. Difference neglegible

  • @ponkieponkz
    @ponkieponkz 8 месяцев назад

    I dont understand how the pivot is calculated or stored in the dataframe...
    ***Never mind... Newbie here. I started learning python in april this year.
    I am retrofitting your codde to a Freqtrade dataframe. You are working with numpy arrays.
    Learned some new stuff thanks to this challeng.. Thanks for the content.

  • @nattyzaddy6555
    @nattyzaddy6555 5 месяцев назад +3

    I ran your code but it created a static matplotlib graph instead of the real-time updated graph that you show in the video

    • @iloos7457
      @iloos7457 5 месяцев назад

      use plotly
      or search interactive on google

  • @lennard4454
    @lennard4454 6 месяцев назад

    Something I don't like about this algorithm is, that it seems only to combine highs with highs and lows with lows. However rather often, previous Support becomes Resistance and reverse...

  • @poyolplays2825
    @poyolplays2825 Год назад

    Hello Sir. I've been searching for an algorithm to detect trendlines for days until I found this. Fatnastic work! I've implemented your algorithm in nodejs and it works perfectly, However my original intention was to detect those trendlines like the beginning and end of the video. How can i use the result of this TrendLineAutomation
    to calculate those two lines?

  • @MelarDev
    @MelarDev Месяц назад

    like someone said, c++ code would be great if you could share plz

  • @jassbinks3301
    @jassbinks3301 27 дней назад

    Can we have acces to C++ algorithme ?

  • @mhalan2198
    @mhalan2198 3 месяца назад

    why didn't you connect the two furthest pivots and that's it?

  • @KereellOlorin
    @KereellOlorin Месяц назад

    I'm a newby to trading. Please tell where I should scrape the data into csv files from? Or it is posible to get this files from tradingview (or similar resourses) ?

    • @nuweariho6884
      @nuweariho6884 20 дней назад

      Get from mt5 by just right clicking the chart and click save. It will offer you option to save as CSV. But if u want to automate then use mt5 python documentation. It will help u to access data into your python code from mt5.

  • @poisonza
    @poisonza 3 месяца назад

    computationally too expensive, the gradient descent part could go away.
    Given data window compute zigzag to find pivot points
    Enumerate all possible trend line using pivoot points.
    choose trend line with minimum error(distance between data and trendline).
    So essentially you compute way less but get similar result. cheers

  • @hasa4628
    @hasa4628 Год назад

    hey where i can learn more about algorithms for trading?

    • @neurotrader888
      @neurotrader888  Год назад

      I have a video of books I like. Many of the books have code.

  • @salexkorsan8790
    @salexkorsan8790 Год назад

    Mr dude send me the code i wanna make a bot, i will send you too