Maximizing Profits with Python Backtesting: Price Breakout Strategy & Dynamic Trade Management

  Рет қаралды 17,854

CodeTrading

CodeTrading

Күн бұрын

A comprehensive guide on backtesting a price breakout strategy using Python and maximizing profits through dynamic trade management. We'll explore different approaches that can boost your profits from 10% to almost 100%.
We'll be applying our strategy to both manual and algorithmic trading. Even if you're not into algorithmic trading, you can still utilize the insights from our backtest for your manual trading strategies.
In this video, we'll revisit an indicator presented in a previous video, looking for key support or resistance levels where the price has bounced three times before breaking through. We'll use the moving average to determine the trend direction.
We'll also discuss various trade management rules, including stop loss (SL) and target profit (TP) conditions. We'll explore a dynamic approach using the Relative Strength Index (RSI) and a method that uses a stop loss value as a percentage of the price value.
💲 Discount Coupon for My Udemy course on Algorithmic Trading:
bit.ly/CouponA...
🔥Download the Python notebook used in this video from the link below.
drive.google.c...
The Data file in case needed:
drive.google.c...
Remember, the goal here is to highlight the power of trade management while backtesting our breakout indicator. You can apply these results to your manual or algorithmic trading.
#python #backtesting #technicalanalysis BreakoutStrategy #trademanagement #algorithmictrading #breakouttrading #rsi

Пікірлер: 83
@precioslouzado8651
@precioslouzado8651 10 ай бұрын
Awesome. I love the education you are providing for every segment of the code. Thanks and much appreciated.
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Glad it's of help! Thank you for your comment.
@enotbert
@enotbert 10 ай бұрын
That's a great approach. I haven't gotten around to experimenting with the code yet, but the first place to dig is to increase the frequency of trades. 13 trades in a 5000+ day period is very rare. If you increase that number, it's likely that the all important temporal metrics will also change for the better. I will start by selecting the values responsible for the signals. If I manage to find interesting combinations of variables, I'll update you.
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Hi, thank you. Just in case the frequency is not easy to increase we might as well run the same algo on different currencies... one way of increasing the trades number. Good luck!
@enotbert
@enotbert 10 ай бұрын
@@CodeTradingCafe Thanks. Can you please advise the logic on how to define zone_width. Maybe there are some statistical methods or is it a purely empirical approach?
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
For now purely empirical, if you want to kind of automate I would say use something related to ATR.
@칠월이십삼일
@칠월이십삼일 7 ай бұрын
Then how about using 1h or 4h?
@trocchiettoski
@trocchiettoski 4 ай бұрын
@@CodeTradingCafe yeah i have been using zone_width and is really not good because applying to stocks growing with price will have a difference between high-mean always bigger than 0,001, and the same with another constant
@LolkeDijkstra
@LolkeDijkstra 2 ай бұрын
I tried to replicate the exact same results and found that you were using a gap window of 6 equal to the pivot window. That would do the trick. But of course you should have increased the gap.
@CodeTradingCafe
@CodeTradingCafe 2 ай бұрын
Hi, glad it works. Regarding the gap not necessarily check the edge conditions, in python the right edge of a slice is automatically excluded.
@coati3019
@coati3019 10 ай бұрын
Hello Dr. In the sell orders you have to use two different tp values instead of tp1 (for now you have two identical sell orders). Maybe this will increase win ratio of this strategy.
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Hi, you're absolutely right, I missed this! might be worth you trying it see if it improves our results. Thank you for pointing this out!
@ericchen161
@ericchen161 10 ай бұрын
Really good strategy, clear coding logics and well organized walking through!! Appreciate it!
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Glad you enjoyed it! Thank you for your support.
@nandoribas
@nandoribas 10 ай бұрын
Best code/trading channel on KZbin, amazing content, explanations and examples. Congratz!
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Thank you for your support! Glad these videos are helpful.
@lennard4454
@lennard4454 9 ай бұрын
Hi, I've wanted to make a suggestion. I've followed you for quite some time and a coded a bunch of stuff my self. Lately I've gotten really interest in using code to improve manual trading by detecting common chart patterns. I've noticed that doing it with classic code, for me just doesn't work very well, especially with the live market where it doesn't have as many candles to look into the future. I think a way better approach would be using ai. This what today's ai is good at, not predict tomorrows price. Maybe you could use ai in the future again... Thx for reading.
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
Hi, thank you, which AI algos you have in mind?
@lennard4454
@lennard4454 9 ай бұрын
​@@CodeTradingCafe I've done some work on this problem. It is a very complicated topic and I didn't find good solution on the internet. So I've developed my own for a simplified version of this problem for now. I've defined the problem as following: Given a time series where each value depends on the values before, one needs to find a pattern that varies in length at may occur at any index (n times). For simplification, I've stacked sinus waves with different wave length and choose the subsequence from each low to each high as my pattern. I've send you en email to the notebook because KZbin won't allows links here.
@bentz242
@bentz242 10 ай бұрын
when apply this tests on stocks e.g. AAPL the test dataframe always empty, any idea how to resolve it ?
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Yes all the parameters variables values can be changed to fit the new asset price, these were set in the example for EUR USD.
@dcchase8225
@dcchase8225 9 ай бұрын
How can i apply in Indian capital Markets?
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
you need to get the data for any market you need and adjust the parameters for this market, check the results.
@hamidsavalanpour4277
@hamidsavalanpour4277 8 ай бұрын
This code doesnt work with live data using stocks. Tried it with spy and it got only 1 trade for the last 5 years. Can you make your future videos with live data?
@CodeTradingCafe
@CodeTradingCafe 8 ай бұрын
Hi, I don't understand you used it on live data for the last 5 years? you need to tune the parameters depending on the asset you are trading. It doesn't matter if data is live or historical.
@Ezio-uh4uy
@Ezio-uh4uy 9 ай бұрын
This strategy is good for forex.
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
Hopefully it wan't disappoint, some strategies suddenly mess up!
@_romulus4336
@_romulus4336 9 ай бұрын
where is the backtesting folder
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
Hi, check the google drive link in the description.
@Qstgggg
@Qstgggg 10 ай бұрын
Do the same backtest only for a minute timeframe
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
I can do it but 1 minute timeframe is too noisy for algos like this one, but again we can try it, nothing to loose.
@rafaelsarmentero
@rafaelsarmentero 7 ай бұрын
This is not profitable.
@CodeTradingCafe
@CodeTradingCafe 7 ай бұрын
On its own no, but it can be a part of a full trading system.
@neuvedeno1
@neuvedeno1 Ай бұрын
Has anyone made it work with crypto?
@CodeTradingCafe
@CodeTradingCafe Ай бұрын
Not me, not yet at least :)
@veerjain4537
@veerjain4537 10 ай бұрын
Gotta say your channel is truly amazing was wandering in some event based backtesters, then got this video in my feed, saw your whole channel every single of your video is gold for me. I have started from the last video day before yesterday now I'm at 5th from the down, in a month or two will watch this video. Truly genuine and amazing content, hats off to you sir. Thankyou for this valuable content. P.S. I saw some comment about your udemy course can you drop the link of that? Thanks :D
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Thanks a lot for your appreciation, I am glad these videos are of help. (the course link is here www.udemy.com/course/algorithmic-trading-strategies-in-python/?couponCode=BA93A8F7375DB35B1252) Just in case the voucher expires let me know I can generate a new one to avoid you paying a full price.
@saabsaab3774
@saabsaab3774 10 ай бұрын
very genuine channel salute
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Thank you for your support!
@RichardPain3
@RichardPain3 10 ай бұрын
Hello Dr. Just stumbled accross the channel. Exactly what I am looking for. Just got your Udemy course and subbed. Thx for putting this info out there.
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Awesome, thank you for your support!
@amberneeltalksonfacts
@amberneeltalksonfacts 8 ай бұрын
Hello Sir, can apply this Breakout Strategy for Finvasia Shoonya Broker Api Indian Broker, for Live Trading
@CodeTradingCafe
@CodeTradingCafe 8 ай бұрын
Hi, I honestly don't have experience with Indian brokers but you can always try to open a demo/free account and see if there is a way to automate your strategies, worst case it simply wouldn't work.
@amberneeltalksonfacts
@amberneeltalksonfacts 8 ай бұрын
@@CodeTradingCafe ohh great thanks for your reply sir,
@amberneeltalksonfacts
@amberneeltalksonfacts 8 ай бұрын
@@CodeTradingCafe actually people don't reply idk why but you did so thanks 🙏
@amberneeltalksonfacts
@amberneeltalksonfacts 8 ай бұрын
@@CodeTradingCafe btw sir can you give any resistance breakout python code so that I can try to run with my broker, if any plz 🙏
@CodeTradingCafe
@CodeTradingCafe 8 ай бұрын
The code is available from the link in the description of the video you can download it
@Ccccccc109
@Ccccccc109 10 ай бұрын
Thanks you for Your work! Where do you find the csv files please?
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Thank you for your support, the data files are in the description
@Exzal123
@Exzal123 7 ай бұрын
It's weird... I've got my dataframe with my signal showing 1 or 0. I use your backtesting code, and in order to see if it was working for the conditions I've put some print that gave the right outputs : if self.signal!=0 and len(self.trades)==0 and self.data.Signal_Achat==1: sl = self.data.Stoploss[-1] print("SL", sl) sldiff = abs(sl-self.data.Close[-1]) tp = self.data.Close[-1]+sldiff*TPSLRatio print("ENTRY", self.data.Close[-1]) print("TP", tp) print("") self.buy(sl=sl, tp=tp, size=100000) But when I print(stats) I get only NaN and 0 values... I don't know if this is common? Thanks !
@CodeTradingCafe
@CodeTradingCafe 7 ай бұрын
Hi, there might be something preventing your bot from passing trades, so the print is happening but no trade is opened, example reasons: trade size is too high there is not enough money in the account, sl and tp values are too close to the price or not in the good order, ... just verify your numbers.
@davidsaurel4012
@davidsaurel4012 10 ай бұрын
Cooo
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Thank you :)
@Thiarara_superWP
@Thiarara_superWP 9 ай бұрын
hello, some of us are new to this, take us step to step on how to run this and make it work.
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
Hi, this channel is also for new to coding, my main purpose is education. To refresh your python skills, I would start by this playlist kzbin.info/aero/PLwEOixRFAUxZVV0XNWlapem1yoRA4rt_O Then carry on with these videos on strategies. Good luck!
@mohammedmansour8181
@mohammedmansour8181 9 ай бұрын
This video is nice to refresh python and learn trading in the same time 😊
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
Glad you liked it Thank you for your support.
@Alexrmacleod
@Alexrmacleod 10 ай бұрын
Legend walks among us
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Lol ! thank you for your support :)
@The_Foolish_Fool
@The_Foolish_Fool 9 ай бұрын
Been looking at this and it's exactly what I was needing. now only if I could find a way to incorporate S&R levels.
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
I am glad it's helpful, check this one for S & R kzbin.info/www/bejne/rpzcZI2feNh4etU
@The_Foolish_Fool
@The_Foolish_Fool 9 ай бұрын
@@CodeTradingCafe I've tried adapting your code to work with a SPY dataset I've gotten from Kaggle (it's the most up to date one I could find and it also has the most data points going back to the 1970's) and I can't seem to get the backtesting to work. it doesn't output any trades.
@AchuVlogs
@AchuVlogs 9 ай бұрын
Please create video on implementing central pivot range (CPR) indicator.
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
Thank you for the idea, I never used it before, might research how to beforehand.
@AchuVlogs
@AchuVlogs 9 ай бұрын
@@CodeTradingCafe Its a leading indicator used for day trade, calculated based on previous day's data. Sure, looking forward :)
@secretsmile9219
@secretsmile9219 8 ай бұрын
hey you can try camarilla pivot points daily R3 R4 + S3 + S4 these levels are most important S/R @@CodeTradingCafe
@dmitriys4279
@dmitriys4279 5 ай бұрын
13 trades???
@CodeTradingCafe
@CodeTradingCafe 5 ай бұрын
well it depends on the parameters and how selective you want the model to be, also the timeframe... but the algorithm is working.
@usikalal7279
@usikalal7279 10 ай бұрын
File Donot downloading
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
All the files are OK I checked these you need to click the download button after the google drive page is opened.
@newbienoob1
@newbienoob1 10 ай бұрын
sir do you have github repository ?
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
I didn't push these codes on github unfortunately, must do it at some point.
@newbienoob1
@newbienoob1 10 ай бұрын
@@CodeTradingCafe thank you sir for free content it really helped me god bless you 🙏🙏🙏🤲🤲
@kingsleyonyenanu9272
@kingsleyonyenanu9272 10 ай бұрын
Hello Mr. Code Trading.. how can I connect with you outside here… maybe Facebook,Twitter or telegram???
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Hi, thank you for our interest, the best is either on KZbin or by email.
@kingsleyonyenanu9272
@kingsleyonyenanu9272 10 ай бұрын
@@CodeTradingCafe okay, I would like to have your email.
@CodeTradingCafe
@CodeTradingCafe 9 ай бұрын
It's in the about section of this channel, sorry can't share it here I think YT will automatically remove the message
Automated Price Break Out Detection: Algorithmic Trading In Python
16:34
Trading with Python: Simple Scalping Strategy
13:47
CodeTrading
Рет қаралды 94 М.
The day of the sea 😂 #shorts by Leisi Crazy
00:22
Leisi Crazy
Рет қаралды 1,8 МЛН
Running With Bigger And Bigger Lunchlys
00:18
MrBeast
Рет қаралды 107 МЛН
Using docker in unusual ways
12:58
Dreams of Code
Рет қаралды 449 М.
How I Would Learn Python FAST in 2024 (if I could start over)
12:19
Thu Vu data analytics
Рет қаралды 351 М.
How Financial Firms Actually Make Money
22:40
QuantPy
Рет қаралды 352 М.
How to Code a AI Trading bot (so you can make $$$)
35:09
Nicholas Renotte
Рет қаралды 637 М.
The day of the sea 😂 #shorts by Leisi Crazy
00:22
Leisi Crazy
Рет қаралды 1,8 МЛН