Automated Price Action Trading Strategy In Python

Поделиться
HTML-код
  • Опубликовано: 17 май 2024
  • This video presents a simple trading strategy using candlestick patterns and support and resistance values. The strategy can be automated for price action detection. The strategy was automated and tested in Python on historical data of Euro versus US Dollar.
    Check my previous video on support and resistance levels for more details:
    • Automated Support and ...
    🍓 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 Python code is available for download from the link:
    drive.google.com/file/d/1Hd34...
    The data file:
    drive.google.com/file/d/1v2Bf...
    #python #forex #algorithmictrading
    00:00 Support And Resistance Trading Introduction
    03:40 Support Resistance Trading Strategy
    06:50 Algorithmic Trading Code In Python
    22:40 Trading Strategy Predictions Results

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

  • @doge2themoon373
    @doge2themoon373 Год назад +3

    happy to find your channel, I've been looking to start in python and find this very helpful

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

      Thank you for your comment, check my playlists there is one on learning python it might be helpful, and good luck, it will be fun you will see!

  • @drjenniferderm
    @drjenniferderm 2 года назад +5

    Very thorough explanation!! Great content!

  • @pauleasther
    @pauleasther 10 месяцев назад +3

    Congrats on not having a clickbait title like, “Make Millions Overnight” or suchlike as used by so many Tubers. Instead a professional honest approach.

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад +3

      Thank you for your appreciation, I am glad you enjoyed the content. In fact I am happy with the coding part most of the time so no need to oversell any indicator, they all have some pros and cons.

  • @arieltoledosoto9343
    @arieltoledosoto9343 7 месяцев назад

    Oooh geez! This channel is amazing!
    Thanks for your jog. It's very nice.

    • @CodeTradingCafe
      @CodeTradingCafe  7 месяцев назад

      Glad you enjoy it! thank you for your support.

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +4

    Good afternoon, you do not need to worry, such videos cannot be too long))) in everything related to money, there is always not enough information and thanks for the strong video

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад +2

      Lol well it reminds me years ago trying to learn trading all I was stumbling on was the moving average strategy in like 6 min vids...plenty of them, nothing that helpful... Times have changed and the field is evolving quickly, today's techniques are really powerful.
      Maybe I will try to automate this strategy in another video.

  • @prabhattiwari5089
    @prabhattiwari5089 Год назад +2

    @CodeTrading, you are a gem.💎
    Thank you so much for sharing these amazing videos.

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

    Thanks, amazing video, I learned a lot!

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

      Thank you for your support, glad the videos is helpful

  • @sawfhsawfh2024
    @sawfhsawfh2024 2 года назад +3

    Thank you so much for sharing 🙂

  • @bostjan.gajsler
    @bostjan.gajsler 4 месяца назад

    Great work! Excellent!

  • @kingsanket123
    @kingsanket123 11 месяцев назад +1

    Great content.. Thanks a lot !
    I have one query. Why are you not using TAlib to detect candlestick patterns?

    • @CodeTradingCafe
      @CodeTradingCafe  11 месяцев назад

      Hi by the time I started doing these codes candles were still freshly introduced in TAlib. Another reason is I like to control the ratios of the patterns like the wick versus candle body and size of the engulfing candle etc... but I don't mind using TAlib if you know what's happening under the hood.

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

    Thank you much for sharing videos from novice programmer from thailand :-)

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +2

    on 26.07 you are talking about the up trend is a very smart idea, but you can implement this condition not to trade against the market by setting in the code if the last 3-4 candles are bullish, then we trade, if bearish, then we do not, for example. It is necessary in the code to indicate the NUMBER of PREDING candles, this is the MOST IMPORTANT condition in addition

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад

      Hi, sorry for the delay, I had to check in detail, adding the filtering method is good but we will be decreasing the sensitivity of our model therefore yielding no more than ~3 trades per year, maybe this is good to implement for lower timeframes (H4 or H1)

  • @flydr2
    @flydr2 2 года назад +2

    Thanks Again!

  • @paultenzer1361
    @paultenzer1361 Год назад +3

    Really great video, thanks for putting this out and giving us the source code too. Thanks bro you saved me a ton of pain

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

      Thank you for your support, finally some of my work is being discovered 🙂 happy these codes are of use

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

    Como siempre son excelentes videos los que tienes.

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад

      Gracias amigo :) thank you for your support!

  • @maverick456-33
    @maverick456-33 Год назад +1

    Very Good Tutorial !

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +3

    How would we optimize the automatic finding of the exact stop loss in pips, so that backtesting itself on historical data checks how much optimal in pips the stop would be on the found candles to enter a trade, of course, count the indent from the resistance line

  • @alabaalaba2810
    @alabaalaba2810 2 года назад +3

    Great!

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад

      Thank you, I will try to show a bot using this

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +2

    how to carry out the process of automatic optimization of the stop loss and take profit parameters, as solved in the metatrader in backtesting, and how would you decide to INDENT in the code from the resistance and support lines in order to sell at the distance from the resistance line found in the backtest, for example ?

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад

      I think I understand what you mean, we will have to include most of the code in this video in a big for loop that checks different SL values or distances to price, then you keep the SL distance yielding highest income, in machine learning this is close to overfiting in the sense that it would work fine on previous data where you did your adjustments but it doesn't necessarily work well on future data.
      Anyway to optimise any parameter the code can be included in a for loop changing the parameter and checking the outcome.

    • @alpsgrin4501
      @alpsgrin4501 2 года назад +2

      @@CodeTradingCafe I think this is a very good idea for a new video, automatic optimization and finding exactly in pips the price of the stop loss and take profit, as well as the trailing stop and the step of following the price, display the clarified parameters in the table. This will improve profits and help reduce losses. The first rule of the trader))) cut losses

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

    I saw your prev SR level video pls mention it in the description of video, I think prev video should be seen prior this video

  • @shivamdubey4783
    @shivamdubey4783 8 месяцев назад +1

    Sir what is prerequisite for starting your course I know python besides that what else you need to know

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

      Hi, python then more python and again python. Later you need to get familiar with trading strategies and some algorithmic trading books. Good luck!

  • @MrHamish1998
    @MrHamish1998 2 года назад +3

    This is a great video and strategy! I think there is look forward bias in the signal calculation though. When iterating through subrow to calculate the support and resistances the subrow finishes on 'row' which is the present day. This is fed in to the support and resistance functions which look n1 candles behind the row input and n2 candles in front so you would have to know what n2 candles are in to the future. Just food for thought. Correct me if I'm wrong because I've been staring at this code all day!

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад +1

      Hi, thank you for your comment, the right boundary in Python is excluded meaning if I write [row-5:row] in fact it goes from row-5 up to row-1
      I hope it makes sense

    • @MrHamish1998
      @MrHamish1998 2 года назад +1

      @@CodeTradingCafe
      I see, but the current row is included in the iteration:
      For subrow in range(row-backcandles+n1, row+1):
      if support (df, subrow, n1, n2):
      SS.append(df.low[subrow])
      So if the code is looking forward n2 candles when subrow = row ?

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад +4

      @@MrHamish1998 actually you're correct, the subrow should stop at row+1-n2 I think it wouldn't affect our results much because it's an error only triggered when the current candle is support or resistance along with previous 45 candles (we simply got lucky with this) this reminded me of the same type of mistake I was commenting on an article years ago.
      Thank you for pointing this out

    • @MrHamish1998
      @MrHamish1998 2 года назад +2

      @@CodeTradingCafe I backtested it with the look forward bias using backtesting module on 15min and 5min timeframes on 5 cryptos using ATR as TP. Results were incredible (+1000% APY). After fixing the look forward bias returns went to +10-20%. So still profitable. I reckon using volume and large time frame SRs as well as your wedge breaks and head and shoulders in your other videos this could be a serious trading bot! Either way you’ve helped my coding a lot with these videos and inspired some ideas!

    • @MrHamish1998
      @MrHamish1998 2 года назад +2

      @@CodeTradingCafe also because we’re iterating through each row then every candle backwards within BackCandles every support/resistance found will become the current row at some point. Easily fixed though. Bit of tweaking and this strategy is a weapon

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

    Hi, may I ask if I will test this strategy for example to data of BTC/USD. The column "amount" will represent pips, but how many lots/units am I trading actually?

    • @CodeTradingCafe
      @CodeTradingCafe  Месяц назад +1

      Hi, good question, actually this is not included in the code nor the video, so we are assuming one full bitcoin in trade, now if you want to make things easier as a full backtest, in my most recent videos I am using backtesting.py for backtests and you can include the trade size in it. Check this one for example ruclips.net/video/C3bh6Y4LpGs/видео.html

  • @Damiensgarage
    @Damiensgarage 2 года назад +4

    Hey man great content learning alot from your coding skills could u do a video on connecting to mt5 api with python to implement some of these strategies in the back testing terminal on mt5 binace connection would be cool aswell

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад +2

      Hi, thank you for your comment, I understand what you mean, I have already thought about it but dropped the idea since we can backtest in python. However, note that these particular strategies can be written in mql language relatively easily because there is no Machine Learning involved (main reason I chose Python was being able to include ML models).

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

    Thank you for your work. I'm probably being an idiot, but I can't get the algo to find the data file. Do I need to save it at a particular location so it can be found by the algo please?

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

      Thank you for your support! The easiest is to keep the data file in the same folder just next to the jupyter notebook python file. Let me know if it worked.

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

      @@CodeTradingCafe Thanks, works now!

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

    where do u get the data csv

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

      Yfinance, my broker and Dukascopy. Good luck!

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +2

    at 28.40 there will be no false positive triggering))) if you indicate what I just wrote about, do not enter the deal in short, if the previous candles are 3-4, SPECIFY IN CODE !!! There were Bulls

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад

      Yes but at the same time we are looking for engulfing signals around resistance/supports so we expect a reversal, I am not sure if I add one more condition we would still have any signals at all. We can investigate this anyway, the code is ready so I can add the condition and see what it does...

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

    hello, what is the barsupfront variable its gives an error thats its not defined

    • @CodeTradingCafe
      @CodeTradingCafe  2 месяца назад +1

      These are the bars to look for in the future, shouldn't run at the end of the dataframe.

    • @cybergrimreaper6669
      @cybergrimreaper6669 2 месяца назад +1

      @@CodeTradingCafe does it have to be defined before the loop?

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

      I assume so because it's used inside the loop.

  • @username42
    @username42 Год назад +2

    how can we put this into tradingview pinescript as strategy indicator?

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

      Hi honestly I am not familiar with tradingview coding language but it shouldn't be very different from any. I mainly prefer python because it has machine learning and neural networks libraries.

  • @user-tc5ml3lg2q
    @user-tc5ml3lg2q 4 месяца назад

    how can i get quotex otc candlestick data such as open, hight,low... in python ?

    • @CodeTradingCafe
      @CodeTradingCafe  4 месяца назад

      Hi, you might try dukascopy they might have data published.

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +2

    I know the main mistake of the trailing stop. IT DOESN'T WORK UNTIL THE PRICE TOUCHES IT IN THE BACKWARD DIRECTION, which is very inconvenient! What is your opinion? does the trailing start from the moment you place an order in your code? and it immediately follows the price at a certain distance of 10-15 pips?

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад +2

      In my opinion the trailing distance shouldn't be a constant like 10 or 15 or something else pips, mainly because the market is different every day, if I have to test trailing stop I would use the distance of the stop loss as described in the video as a start but also have to think about modifying the trail distance (making it smaller) as you get closer from a "fictive" take profit value, make like a function where the trailing distance shrinks linearly until a certain point which is the "TP" then the distance remains constant for the rest of the time. (I know it's complex/annoying but we can't use linear or constant thinking on nonlinear market, and you have to give enough room for your trade to move especially at the beginning).
      Another way to fix the distance of a trailing stop is using ATR values takes into account the market volatility.

  • @yeardol
    @yeardol Месяц назад +1

    Symmetrical exit maybe 😊 according to the strategy

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

    What platform can we use this code on? Tradingview, mt4, mt5 ? Thanks

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

      Hi this code is in Python language so you need python installed to run it, it doesn't work on mt nor tradingview. However the algorithm can be translated to mt or tradingview

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

      @@CodeTradingCafe OK thanks

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

    is it possible to implement python code in MT4 station ?

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

      Hi, yes using mql4 language you can translate any Python code to run in mt4.

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

    Could you please help me how to implement the strategy in indian market on index options

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

      You need to backtest first to make sure it's profitable

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +2

    at 26.45, you found a 585 candle well suited to our conditions, but why did the scanner miss the next candle right behind it? she perfectly suited all conditions! Is this an ERROR IN THE CODE? SCAN SKIP MAYBE MORE THAN ONCE, I DIDN'T NOTICE BUT IT'S WORTH CHECKING I THINK! AND YOU?

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад

      Well spotted ! in fact it might not be an error but I suspect that it wasn't taken as a signal because in the function isstar() we have a minimum candle body difference to consider (the variable is called bodydiffmin check video 8:28) so maybe the candle is "too small" to make a signal, ... there is one way to find out decrease the value of the bodydiffmin or simply check the body length of this particular candle.

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

    thank you so much! But can you add English subtitle pls ?

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

    May I privately share an idea for consideration?

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

      Hi, sure you can send me an email, the address is in the about section of this channel.

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

      @@CodeTradingCafe Sent.

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

    any idea why its now getting multiple errors ?

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад

      Hi, it shouldn't get errors I think the code is still the same. Can you mention the type of errors you are getting?

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

      @@CodeTradingCafe high it was my fault, its all good....awesome code. I didnt put the csv in the correct file location...school boy error....

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад

      It's good it's working! good luck for your experiments.

    • @paulmc7309
      @paulmc7309 10 месяцев назад

      @@CodeTradingCafe hi its all good, great channel... I was wondering if you coded something a bit different like HTF say 2H indicators using data from 30mins? For S&R try Gann SQ of 9... a strategy I am looking at is 30min data Stochast(5,3,3) & BB(20) & Gann SQ of 9 S & R, (use this for close to S & R) isStar or isDoji, then HTF indicators: 72 EMA 144 EMA , ADX 56. For BUY 72EMA>144EMA, ADX D+>D-, isStar or isDoji, below BB low, Stoch70. Its just something a bit different from using single TF with single TF indicators and using Gann for S & R.

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +2

    Why don't you go from static, in real time, it is much more informative to see which candle on the chart is false positive, if you mark all the found candles with arrows showing the direction of entering a deal, a green arrow up long, or a red short down, then you will not need to manually drive in the numbers of the found candles

    • @CodeTradingCafe
      @CodeTradingCafe  2 года назад

      It's a good idea but there's still a problem where you can fit only a certain number of candles into a visible frame, but yeah I see what you mean I will look into it

    • @alpsgrin4501
      @alpsgrin4501 2 года назад +1

      @@CodeTradingCafe no problem, you can implement horizontal scrolling scrolling from the first candle in our dataset, for example 10 years and 3000 candles, the graph is drawn in Cartesian coordinates, a new candle will be drawn along the X-axis every time, and the previous ones will disappear behind the visible field to the left, how in any real-time platform charts with new candles are drawn, let's leave, for example, beautiful large, convenient size 30 visible candles, the rest behind the canvas, just scrolling to view

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

    This strategy is good compare to other strategy that use indicator like rsi, macd and so on, because it is lagging and i think i can throw rsi , macd into rubbish.🤣🤣🤣🤣

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

      actually you can still use RSI or other indicators for exit strategies but not for the entry. And you are right support resistance and price action are better for entry signals. Good luck (check also my videos on VWAP and Bollinger Bands they provide good hints as well)

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

      @@CodeTradingCafe because i have my friend that are programmer (data scientist) , he does not use rsi, macd and standard indicator on tradingview for strategies, he use mean reversion, multi time frame analysis and price movement or volatility analysis in his trading strategy.

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

      Multi timeframe is powerful reversals are less noisy on higher timeframes and entry points are clearer on lower timeframes.