This is the strategy (well, slightly modified) I’ve been using for the past 2 years on the H1 timeframe across various currency pairs. It’s not fully autonomous - in the end, it is me who decides whether to open a trade or not. My current win rate hovers around 80%, and the return percentage over these 2 years is over 100%.
@TheEcherriman5 ай бұрын
Being nosey, what language have you used - is it Python ? and what feed do you use please ?
@robertbendkowski33855 ай бұрын
@@TheEcherriman Yes, the code is written in Python. I get the data from the broker XTB via API.
@omerfaruk13515 ай бұрын
what kind of adjustmens you did if its not private? and also, have you tried it in crypto?
@robertbendkowski33855 ай бұрын
@@omerfaruk1351 Nothing major, to be honest: • Bollinger Bands (BB) calculated over 20 periods. • The candle being engulfed can’t be a Doji or any other variation of a small/no body and long wicks type of candle. • I don’t trade when a signal occurs directly on a Bollinger Band after a nearly vertical move up or down, as this means the trend is strong and I would be trading against the short-term momentum. Price often tends to slow down after a while and move a bit closer to the middle of the BB channel. You can find many divergences there on the RSI, which, when paired with an engulfing bar, usually indicate a great opportunity. That’s mostly what I do. There’s also a bit of gut feeling now and then, but I can’t describe it. I believe it comes with experience. And no, I don't trade cryptos at all. Edit. I would like to clearly state that I am not some internet scammer, nor am I trying to portray myself as a genius trader. I am still not rich, I still do not live off trading, and I still make plenty of mistakes. I am continuously learning, and my trades are sometimes tragically off the mark.
@YusufOmanov-gf7ft5 ай бұрын
does this work on crypto too?
@omerfaruk13515 ай бұрын
When the trade count is low, the problem is that we can't fully understand the real winning percentage of a strategy. For example, in probability, when you toss a coin, it's 50% heads and 50% tails, but if you toss it 10 times, you might get 8 heads and 2 tails. However, if you try it infinitely many times, it will converge to 50% heads and 50% tails. To fully understand and test a strategy, especially if we are optimizing the parameters and picking the best one according to historical values, we should be careful about the sample size. In my opinion, 18 is not enough. We can find 500 pairs and find the best parameters for historical data, but as long as the trade count for a pair is small, the winning rate does not prove whether it is a reliable value.
@CodeTradingCafe5 ай бұрын
Absolutely right, the uncertainty is high for low trades count, I should compute the uncertainty actually along with the return value considering the central limit theorem... nice idea thanks again
@h345s5 ай бұрын
@@CodeTradingCafeSame thoughts here. Nice video. But low number of trades makes it's not so good. As for me backtest should have at least 1000 trades. In other way it's cherry picking. Because of that I like small timeframes. It's give you much better information.
@byob8015 ай бұрын
That's a great point. I ran it with SPY and XLK daily data on a shorter period 2018 - 2024 both traded 11 times but the results did not duplicate the BMW data. Both ETFs did poorly and think it's because both ETFs had trending markets over the sample time period, this is best for mean reversion markets. Thanks enjoyed the video.
@abdsh4225 ай бұрын
Amazing contribution. You made it easy to start for many people. Thanks for keep contributing!
@CodeTradingCafe5 ай бұрын
My pleasure! Thank you for your constant support, you always bring something nice into the comments :) enjoy coding and Good luck.
@Salvasauss5 ай бұрын
Amazing video, very insightful. I was actually looking into a modified version of this strategy the other day, it's by the youtuber Serious Backtester and he did a great video explaining the strategy and changes he made to it including some amazing backtest results. I was especially interested in the 30 minute time frame 0.15 bbw variant. Maybe you could do a video on it giving some more insight? it's called ''serious RSI - Bollinger Bandwidth strategy''
@АлександрДудоров-ъ2т5 ай бұрын
I coded this strategy for cryto. It doesn't work in my hands. It would be useful to compare with smb else
@CodeTradingCafe5 ай бұрын
Thank you for sharing. I don't remember if I already did the 30 min timeframe, but I could try it again it's not difficult to modify the code for it, should be a quick video (I will dig in the files I might have it already but need time for the video).
@CodeTradingCafe5 ай бұрын
The one and only CodeTradingCafe 💪 😂
@harrisonwalker965 ай бұрын
Great video! I will dig into the code in the coming days. Thanks for sharing.
@CodeTradingCafe5 ай бұрын
Awesome, thank you for your support!
@Monduras5 ай бұрын
I’ve also been testing the same strategy with test account and did not consider bb width as an idea… this strategy really depends on the ccy and what std deviations you use.
@CodeTradingCafe5 ай бұрын
Yes I am not sure it's robust enough, but we can test it in different conditions to see.
@Monduras5 ай бұрын
@@CodeTradingCafe what I found interesting is if you extend to two std deviations and allow more than one trade so if it goes up and down around the band a couple of times you can implement a couple of trades in the same direction
@CodeTradingCafe5 ай бұрын
Yes I agree, but the risk is higher also
@hu51165 ай бұрын
Thanks! Great video with very interesting strategy! You gave me a number of ideas to try ;-)
@CodeTradingCafe5 ай бұрын
Great to hear! Coding is always good bringing new ideas I find it stimulating.
@lennard44543 ай бұрын
this line is unexpected important: `df = df[df.High != df.Low]` removing decreases the performance significantly. but adding: `if (self.data.High[-1] == self.data.Low[-1]): return` didn't have the same effect as the first statement I think this should be kept in mind for live implementations.
@CodeTradingCafe3 ай бұрын
Hi, actually it makes sense because if we separate the candles leaving holidays and weekends empty data, we will loose some signals and some exits depending on the type of strategy. I agree with you the concern is how to take this into account when live trading.
@asarechrisford29284 күн бұрын
Which time frame is best and which pair it works best
@CodeTradingCafe4 күн бұрын
My preferred is daily timeframe.
@apogounte82395 ай бұрын
Hi. Nice effort. Had seen the guy that tried this on all russell index stocks. He uses it in 5m , 15m 30m and 1h timeframes.
@CodeTradingCafe5 ай бұрын
Thank you! yes I am not a fan of minutes timeframes but I could test it on 30M or lower for example, if anything interesting I will get back with a video.
@b.k.6149Ай бұрын
@@CodeTradingCafe How is it possible to connect those short time frames with an live account? And do you know where can i get half an hour timeframes for backtestings?
@lorensaunders60345 ай бұрын
I think the key is mostly the two conditions of price action... one candle closing outside of the BB and the other surpassing it in the other direction and to the other side of the BB. I bet it works on multiple timeframes but is best on the H1. Just a hunch.
@CodeTradingCafe5 ай бұрын
Hi thank you, I was actually willing to try 1H I don't remember I have made any video here using 1H timeframe...
@sc2020GR4 ай бұрын
does it matter if data point is minute or day?
@CodeTradingCafe4 ай бұрын
Yes of course, timeframe is crucial for different strategies.
@DalazG5 ай бұрын
Curious how big of a forex account would this require to be successful? And can it be configured with mt4?
@CodeTradingCafe5 ай бұрын
it can be configured, but I wouldn't trade it, it need to be tested also for robustness, different assets and different conditions.
@reilwaystation43723 ай бұрын
some of the functions of backtesting py is not working in higher python version you think it's totally abandoned?
@CodeTradingCafe3 ай бұрын
I am not aware but there must be an update for it, but I haven't faced a problem with Python 3.11.4 (currently what I am using)
@reilwaystation43723 ай бұрын
@@CodeTradingCafe python 12 I guess it's working just the yfinance part I guess
@LightHumor995 ай бұрын
Please try this on lower timeframes like 30 minutes 1 hr etc.
@CodeTradingCafe5 ай бұрын
I will add it to a long list, so it might be a while.
@mikecervantes93945 ай бұрын
Awesome job Francis thanks a lot! im here from udemy ;). Have u try this strategy with stochastic i/o rsi? and maybe adding a trailing stop...
@CodeTradingCafe5 ай бұрын
Hi, thank you for sharing. I didn't spend all the time I wanted on this strategy yet, I think it is tunable still...
@jroche18325 ай бұрын
What would be helpful is a calculation of the buy and hold max drawdown so we can see how a strategy compares on a drawdown basis ie an 8% out performance vs B&H is great IF max drawdown is lower by 20%
@jroche18325 ай бұрын
Following code could be used: def calculate_max_drawdown(data): # Calculate daily returns data['Daily Return'] = data['Adj Close'].pct_change() # Calculate cumulative returns data['Cumulative Return'] = (1 + data['Daily Return']).cumprod() # Calculate the running maximum data['Running Max'] = data['Cumulative Return'].cummax() # Calculate drawdown data['Drawdown'] = data['Cumulative Return'] / data['Running Max'] - 1 # Calculate the maximum drawdown max_drawdown = data['Drawdown'].min() return round(max_drawdown * 100, 2)
@CodeTradingCafe5 ай бұрын
That's a good point, sometimes B&H seems better in returns but might be risky in DD, we can easily run a backtest just buying at the beginning of the dataframe and holding till the end of the test. Thank you for the code as well!
@emeraandhanshe59545 ай бұрын
Any chance this can be coded in PINEScript to create a indicator in TV
@CodeTradingCafe5 ай бұрын
Hi, it can be translated but I don't do pinescript myself (try with chat GPT it might help)
@vishalkanodia48305 ай бұрын
hello please help me in using this in trading view for INDIAN share market
@CodeTradingCafe5 ай бұрын
Hi, unfortunately I don't trade specific markets but you can adapt any of my codes on this channel. Good luck!
@standup97295 ай бұрын
which market can use for this strategy? Can it use for forex, please?
@CodeTradingCafe5 ай бұрын
Any market might work and might not, we need to try it, but yes I think forex is a good start.
@dilanjayaweera16345 ай бұрын
Are you currently running any bot with real money? can you share the status of that bots like you previously did?
@CodeTradingCafe5 ай бұрын
Hi, actually around +8% to +14% yearly return (so I can't buy an airplane yet). I run it on low risk setup but I can push it up to 20% yearly I just don't like risk. It runs on the daily and 4H timeframe so it's slow, around 2 signals per month.
@dilanjayaweera16345 ай бұрын
@@CodeTradingCafe Thank you for replying
@luisfranco53964 ай бұрын
Is this strategy only for Forex? Thank you in advance for your help and support.
@CodeTradingCafe4 ай бұрын
technical strategies can be applied to any chart, however they might work better on a selection of assets. There is one way to find out :)
@luisfranco53964 ай бұрын
@@CodeTradingCafe l guess l have to do a backtesting first to answer my own questions
@saumikhan26555 ай бұрын
hi sir, how can i put this python code in mql4 file ? if i put it there and execute it would it be turned into mql4 ea file?
@CodeTradingCafe5 ай бұрын
Hi, you need to translate from python to mql language.
@abishekmajee80644 ай бұрын
Can you code this for Indian Stock Market Nifty 500 Stocks? This will be very useful to me
@CodeTradingCafe4 ай бұрын
Hi any strategy here is technical so it can be tested on any market, try it on the indian assets and you will get a gist of how it's working.
@kshitizmiglani64024 ай бұрын
great content. just subscribed. when i comment this line: df=df[df.High!=df.Low] winrate drops to around 45% which is huge is this step something you do for most strategies or is this part of this setup specifically? Will play around and report soon
@kshitizmiglani64024 ай бұрын
and i tested that varying lens for bband 20 30 40 50 60 70. gives best result at bband(len=30->40) winrate 66->75
@kshitizmiglani64024 ай бұрын
bbandlen = 40 rsilen = 21 winrate = 80%
@CodeTradingCafe4 ай бұрын
Hi, yes I use this line to remove candles that represent weekends or days off so no movement at all, they are noise.
@davidsalzgeber47925 ай бұрын
Your videos inspired my to build my own trading bot. I created a oanda demo account and wrote some code and deployed it. The problem i currently have, is that i have to pay a lot of swap. (I did some research, as far as I understand its just overnight fees.) The swap is in my case really high, nearly 0.1% of my invested capital per day. When investing in stocks over a few months, the swap would eat all my profits. Especially on the daily timeframe. What can i do about that? (I am new to that subject, so it is possible that i missed something very obvious)
@CodeTradingCafe5 ай бұрын
Hi, yes I suffered from swap at some point with Oanda, and sometimes swap can be positive meaning you earn on the opened trades! yes it's a small interest for some forex pairs and in one direction for example on USDCHF if you buy/long you get interest but if you short you pay interest... anyway to get rid of this check in your region if Oanda has other types of accounts that don't make you pay swap or overnight fees, if not check other brokers as well, my friend uses CFI in the MiddleEast region he can leave Forex trades opened for 3 month with no additional fees!
@davidsalzgeber47925 ай бұрын
@@CodeTradingCafe Thank you for the explanation! It makes a lot of sense. I am currently working an a BTCUSD Trading Bot and it got great results in the backtests over the last 4 years. The strange thing is, that i have to pay swap for going long and short. I will probably have to switch the broker, but that should not be that big of a deal.
@BoHorror5 ай бұрын
You found the holy grail, congratulations
@CodeTradingCafe5 ай бұрын
Lol thank you, it's a good start but need more tests on robustness.
@LolkeDijkstra5 ай бұрын
Hi, Thanks for the tutorial. I have a question: If I print the list of trades : print(stats['_trades'], I get an overview of the actual trades that were executed, with columns EntryTime, ExitTime and Duration. So, the trades are being closed. I don't understand how that works. I don't see a close / exit anywhere in the code, nor do I see the exit conditions.
@CodeTradingCafe4 ай бұрын
Hi, recheck again usually when you print _trades you get the size and entry and exit bars and prices, profit loss, entry time exit time and duration... so basically all the details needed for a trade.
@LolkeDijkstra4 ай бұрын
@@CodeTradingCafe that's not the question. I do see all those details, but there's no close in the code
@CodeTradingCafe4 ай бұрын
Ah sorry now I understand, it actually follows the take profit and stop loss values, these are defined when you open the trade and they automatically close the trade when the price reaches TP or SL.
@priyansh02chawda5 ай бұрын
This works best in only sideways market
@CodeTradingCafe5 ай бұрын
I agree it doesn't seem robust enough to me, can be revisited with mods later on maybe.
@jorgecasas92635 ай бұрын
You're totally right. I checked in top Nasdaq stocks and the return is much lower than buyandhold anyways it's interesting for sideways
@TheEcherriman5 ай бұрын
Thanks again !
@CodeTradingCafe5 ай бұрын
Thank you too for your support, much appreciated.
@CherylChan30303 ай бұрын
Where did you get the stock/ currency market data thanks
@CodeTradingCafe3 ай бұрын
yfinance, broker, dukascopy, alphavantage all free
@fusionsamayal63845 ай бұрын
Hi this is wonderful high probability setups. Thanks for sharing. Whrere can I find the python code?
@CodeTradingCafe5 ай бұрын
Hi, thank you, the code is in the link in the description
@fusionsamayal63845 ай бұрын
@@CodeTradingCafe Thanks for the reply. Tried the code shows error
@JohnQuezadaHuayamave5 ай бұрын
excelente video.
@CodeTradingCafe5 ай бұрын
Thank you so much!
@rajutandale66635 ай бұрын
sir pl. code for india stock market
@CodeTradingCafe5 ай бұрын
Hi, really sorry I am not familiar with the indian market, but if you like a strategy here you can adapt easily to any asset you are trading.
@sachin67575 ай бұрын
@CodeTradingCafe I have a strategy. Could you please check and let me know 1. RSI above RSI MA 2. close should be above 20 ema to take entry
@CodeTradingCafe5 ай бұрын
Hi, this is not a strategy, it's 2 indicators combined, there is a lot to consider when you need to backtest including the trade management part. You need to provide more details like the length of the RSI, the length of the MA of the RSI, when RSI above MA are we talking exactly about when the RSI crosses above the MA?... If you decide to code strategies, the advantage you will gain is thinking in details :) I strongly encourage you to try, your whole trading experience will change. Edit: sorry I just noticed how long my message is.
@sachin67575 ай бұрын
@@CodeTradingCafe thanks for your reply. Yes, I am working on strategy based on these 2 indicators to take entry.
@vladimirdavidovic443822 күн бұрын
Hey thanks for the great videos, I am trying to learn but I encounter an error which I struggle to correct, after downloading the data and the script and running everything I get this error: UserWarning: Data index is not datetime. Assuming simple periods, but `pd.DateTimeIndex` is advised. after running the 'optimize' chunk. Afterward, the analysis fall apart as the data are not the same anymore. Anybody know how to solve this please. It is a recurring problem.
@CodeTradingCafe16 күн бұрын
Hi, you need to cast the index to date time format using pandas, but it was working on my side so try to run all the cells in order first maybe it will save you some searching.
@maheshmohan38855 ай бұрын
Bro I want to backtest it on Btc usdt 4HR time frame I will do backtest and put the result as comments here....
@CodeTradingCafe5 ай бұрын
Good luck! and thank you for sharing!
@marekludwig8475 ай бұрын
Hi, do you have some results already? I am thinking about same thing. We could wokr together.
@luisfranco53965 ай бұрын
l am having the following error "no viable alternative at character '{' " Any help is very welcome
@CodeTradingCafe5 ай бұрын
do you know at which part of the code?
@luisfranco53965 ай бұрын
@@CodeTradingCafe is after this line strategy("Bollinger Bands and RSI", overlay = true)
@bipmix5 ай бұрын
Just joined and the code link won’t load into Phythpn or Anaconda to test, any suggestion is appreciated
@CodeTradingCafe5 ай бұрын
Open Jupyter notebook and try to load/open the file from there.
@ChandanSah-un2xg5 ай бұрын
60% return from 2011 to 2024?
@CodeTradingCafe5 ай бұрын
Yes but these strategies can be deployed on multiple assets at the same time so you can trade for instance 30 assets in parallel.
@davidsaurel40125 ай бұрын
Discarding short trades and you get 100% WR
@CodeTradingCafe5 ай бұрын
Thank you for pointing this out. But I am afraid the total number of trades is low so this is not very accurate we would have to test it on different assets as well.
@aarjavjain30744 ай бұрын
I tried this strategy on many indian stocks, doesn't work at all, simple buy and hold are like 10k% but this is just 60-70% on many stocks in last 5 years last 10 years or 20 years whatever
@CodeTradingCafe4 ай бұрын
Hi, thank you for sharing this, interesting to see different markets.
5 ай бұрын
Only 18 trades and 66% return over such immense timeframe (13 years) is actually pretty bad. Notice that the dataframe has an open value of 59.2 in the first row and a close value of 101.386 in the last row. Buying the asset in the first day and selling in the last yields a return of 71.26% by doing absolutely nothing. The strategy is actually underperforming the simplest strategy, which is buying and holding.
@CodeTradingCafe5 ай бұрын
Hi, thank you for sharing, I understand your point I do agree partially though. The buy and hold strategy works only on increasing assets, imagine I tried the same strategy on a different stock or a forex that went down so basically the buy and hold will be in the negative, I avoid taking it as a reference. I do agree though that the number of trades is low however I have read many professional traders books and they do have this kind of "selective" strategies too, the solution is to run the strategy on multiple assets at the same time.
5 ай бұрын
@@CodeTradingCafe it isn't about actually deploying a buy-and-hold strategy, but to establish a baseline for comparison. The strategy in the video spans through more than a decade and it is easy to lose perspective. Taking 18 trades and having 66% return, while keeping the capital committed to run it, is really ridiculous. The point is: the performance evaluation invalidates the strategy completely.
@נועםפוזיילוב5 ай бұрын
Hi, I have a bot Idea if you want to test
@CodeTradingCafe5 ай бұрын
Hi, send me an email, I will check if it has potential... codingntrading at gmail com
@orderflowdojo5 ай бұрын
😎📈
@CodeTradingCafe5 ай бұрын
Thank you!
@JonahScott-on7md5 ай бұрын
Great transmission, as always. I appreciate the no-nonsense approach you take to the news and the markets. A lot has changed and that's about it ,but the truth is that I don't even care much about the bull or bear market anymore because Sarah Mackenzie covered me while I'm doing comfortable.20k 30k every week and I'm still counting thanks to her ❤💗💗
@FridayNaomi5 ай бұрын
Sarah Mackenzie's crypto knowledge is like a secret recipe for success
@EvelynDiana7735 ай бұрын
@Stevenuer0iq5 ай бұрын
I remain eternally grateful to Sarah Mackenzie for her efforts that got me to this point , finally paid off my mortgage and all my debts, what more could I've asked for. She changed my life for good
@martinevans25475 ай бұрын
Please educate me, I've come across this before. How can I get to her please?
@Doreenmolly5 ай бұрын
Get her on
@yashpatel24585 ай бұрын
❤
@CodeTradingCafe5 ай бұрын
Thank you !
@TheEcherriman5 ай бұрын
Hi, I've been trying to adapt your code for FX (EURUSD H1 in this case) In the Scatter chart part (e.g) the following line threw a type error line=dict(color='green', width=1), - which was corrected with line={'color': 'green', 'width': 1}, However, once I was in the backtest section, the following errors occurred ValueError: Long orders require: SL (1.080610316351981) < LIMIT (1.08264156) < TP (1.0825096836480192) ValueError: Short orders require: TP (1.1016589696057346) < LIMIT (1.10151738) < SL (1.1035810303942652) Any tips on how to debug this, please ?
@CodeTradingCafe5 ай бұрын
Hi, yes the TP values are not aligned with the trades and the TP distances, recheck the conditions why and how are these values messed up, so it's basically the values of TP and sL you need to recheck the rules and make sure the values are computer correctly.