Hi. I just watched all (38) CodeTrading videos. Very good presentation of the idea of various strategies and their implementation in Python code. But the optimization in these presentations is all about manually sizing the parameters. Could you please present how to automate the process of searching for the optimal size of parameters.
Hi, thank you for your support! true I didn't automate it, for 2 reasons ... Sometimes it's time consuming computing wise when you have more than 4 parameters... Second it only leads to overfiting meaning the algo finds the perfect combination that works for past data but unfortunately not for future data and this is really disappointing. Best is to find a set of parameters that 'makes sense' with some kind of logic behind. At least it's my experience.
Nice video, I’ve been building something similar in backtrader. You could increase your trades by running over a larger set of symbols. Ie all futures, cryptos, ftse etc. it’s actually quite interesting to see the differences between markets. I forward test in 12 month intervals to validate robustness of parameters to minimise overfitting. Anyway just some ideas, keep up the good work.
Good question ! Probably fitting a line on the last N candles the slope has to be close to zero and the ATR above a fixed limit, the parameters will depend on the asset and the timeframe.
Thank you for your hard work! Is it possible to show how to change the index that Backtrading uses from integer to date. It would be helpful to line up what Backtrading executed to actual dates.
Thank you for your support, I actually did it in one of my previous videos, but shame on me I am not able to remember which one, I only remember I did it so we can compute the Sharpe ratio for the backtesting.
My thanks for the clip. I don't recall whether or not which version of Python is used? Just started learning Python a few days back. The differences from one edition to another can be a little surprising and unexpected.
Hi, thank you for your support. I have 3 python versions on my system I don't recap which one I used, I usually hover between 3.8 and 3.10, I don't think it makes any difference for the content shown in this video. Good luck!
excellent video thank you. Question, how do you buy on margin? I know you need a margin account but how do you enter a trade with specific margin like 1:5?
Hi, actually when you setup your account you need to specify the account leverage or margin, then it's fixed for all the trades you open through that account. This is why in the backtest it's a constant parameter in the function of the backtester.
Thank you for your support, yes there is a way to select points/values and plot these, if I understand your question correctly, this video might be helpful ua-cam.com/video/phy57DZOIwc/v-deo.html Good luck
@@CodeTradingCafe yes it's somewhat closer... I am looking to create something like this... I am not sure if it is correct... # fig.add_trace(go.Scatter(x=dfpl.index, y=dfpl.HH, mode='lines', name='HH')) # fig.add_trace(go.Scatter(x=dfpl.index, y=dfpl.LL, mode='lines', name='LL')) # fig.add_trace(go.Scatter(x=dfpl.index, y=dfpl.LH, mode='lines', name='LH')) # fig.add_trace(go.Scatter(x=dfpl.index, y=dfpl.LL, mode='lines', name='LL')) something like this... forexbee.co/wp-content/uploads/2022/01/Screenshot-572-1-760x417.png
@@CodeTradingCafe Yes, daily. Did not modify your code at all. I have my own version with some minor changes, however the win ratio is a little higher than 50%. By the way, I made a trading bot that works with Robinhood API, but after running it for about a month last year, I decided to switch it off, the results were 50/50. So now I am looking for different strategies, and came across your videos.
There are many winning strategies but you have to find a low commissions broker/type of account. And yes I think the parameters should be optimized for the strategy in the video
What is interesting is that this model relies on margin without which you under perform B&H. With margin you expose yourself to a roller coaster of panic as every dollar loss is multiplied. Few can withstand that kind of pain.
I agree it's not realistically tradable, on the B and H matter, it's really hard to find a strategy that beats BH for long term uptrending stocks like apple, amazon, microsoft, gold ... however BH is easily discarded on ranging or downtrending assets.
Drawdown of -95% or -45% or even -20-25% is inacceptable. Imagine you put $100.000 cash and after a while suddenly you see -$50.000, even -$20.000 it's a lot. Of course it gives to you +30.000% but this is just because you tested it on index funds or stocks and these have mostly an uptrend. Try to see how it works when there is a lot of variation and volatility like Forex scalping or anything thing else that is not mostly in uptrend.
Yes it's only shown for demo purpose only. First I would decrease leverage and have a steady curve up. Actually have you seen the first video of the Bollinger bands strategy? It has no drawdown. Let me know what you think.
I have seen all your videos already but I have just seen once more that one you are talking about. -28% drawdown is HUGE. Second, it is wrong to optimize parameters because it will find best settings for already known data but it will fail on new data because it is like AI it is optimized for what it already knows and trying to predict the future based on past data is wrong just because data doesn't repeat, it is different, the future data is different than the past data, that's why it is not working. Also, just two or three trades it is not enough, it must be more than 500 trades let's say at minimum because in real life it will do a lot of trades. Also, index funds or stocks have mostly uptrends and very few downtrends which means that there is no variation, no volatility and it will fail big when the economic situation is bad, in fact when it meets the real fluctuations and volatility. You should choose for testing assets with very high volatility and fluctuations which are very hard to predict and to trade and where there isn't any clear trend up or down. For this I think 1 minute data is very good which also allows you to do a lot of trades to see how it works in real life and in hard to predict conditions because these conditions appears even in a clear trend and bland situation and when they appear they will destroy your strategy if it is not prepared for them. Also, try to add a trailing stop to see how it works. Expecting a new vide from you on the subject! 🤗
@@Krisler12 you said that using past data to predict future is wrong because the future will not repeat. So my question to you is, what is the best strategy to trade? Where can I get profitable trading strategy? Or what can I do to trade profitably if this kind of approach or AI do not work.
I don't know. If someone will find the best way to solve this problem he or she will be a billionaire and the richest man in the world. I think just using a more general strategy that could work on many assets and a trailing stop and also a good money management strategy could somehow give a good strategy.
@@Krisler12 in my experience Real algos achieve 8% to 15% max per year, we're not talking leverage because it's not a good idea to increase risk. Some years returns are higher but that's just luck, normal automated systems are around 10% a year on average. I have discussed this with a real trading and investment company and this is the reality. Now other trading forms like high frequency or having access to restricted data can bring more power to the algorithm and this is where it gets interesting, but the data is restricted by law and money (have to be a certain type of registered company to ask access to advanced market data and you pay a lot for it annually). That being said it's still fun to try algos around, I tried recurrent neural networks recently I will post the code in a video... soon
It's harder to make it work for low timeframes, but for some reason every strategy I tried on the daily time frame worked well but it's slow, one trade per month so we need to run on more assets ... so more money is needed in the account.
so basically you gain money when trend is going up and losing when its going down, if we find some way to not los money (buy when its still down trend) we will have higher wr for sure
Hi, thanks for sharing. As it is, yes you are right for the algo deals well with one trend direction. You can also have another algo tuned for downtrends and the 2 algos running together might be a good hybrid solution.
I agree it's not an absolute estimate but it allows me to compare strategies and indicators together at some point we can retest a strategy if it looks promising adding commissions. Also trade management is very simple here it can be improved as well (this part I find fascinating)
Well you can still make money while sleeping but not enough to be rich... Rich like buying a hotel a boat and a supercar, trading makes 20 percent return per year so it's limited. But again you can make some money out of it.
It's not misleading if you already know the strategy works in trending markets, other strategies work in ranging markets... there is no single strategy that works in all types of markets. But yes I understand that it can't be applied blindly to all circumstances, it simply wouldn't work. However the Bollinger entry trick does bring an advantage in most cases.
4:15 this isn't good practise. one should not use python lists and slow for loops but perform the operations directly on the dataframe: df['EMA_SIG'] = np.nan df.loc[df.EMA_1 < df.EMA_2, 'EMA_SIG'] = SIG_BEAR df.loc[df.EMA_1 > df.EMA_2, 'EMA_SIG'] = SIG_BULL
I can only say “I love you and your videos!”
Thank you for your support 😊
Hi. I just watched all (38) CodeTrading videos. Very good presentation of the idea of various strategies and their implementation in Python code. But the optimization in these presentations is all about manually sizing the parameters. Could you please present how to automate the process of searching for the optimal size of parameters.
Hi, thank you for your support! true I didn't automate it, for 2 reasons ... Sometimes it's time consuming computing wise when you have more than 4 parameters... Second it only leads to overfiting meaning the algo finds the perfect combination that works for past data but unfortunately not for future data and this is really disappointing. Best is to find a set of parameters that 'makes sense' with some kind of logic behind. At least it's my experience.
Nice video, I’ve been building something similar in backtrader. You could increase your trades by running over a larger set of symbols. Ie all futures, cryptos, ftse etc. it’s actually quite interesting to see the differences between markets. I forward test in 12 month intervals to validate robustness of parameters to minimise overfitting. Anyway just some ideas, keep up the good work.
Thanks for sharing, yes the best is to decrease risk and test on different markets. Good luck!
Thank you for videos! How would you define choppy market?
Good question ! Probably fitting a line on the last N candles the slope has to be close to zero and the ATR above a fixed limit, the parameters will depend on the asset and the timeframe.
Thank you for your hard work! Is it possible to show how to change the index that Backtrading uses from integer to date. It would be helpful to line up what Backtrading executed to actual dates.
Thank you for your support, I actually did it in one of my previous videos, but shame on me I am not able to remember which one, I only remember I did it so we can compute the Sharpe ratio for the backtesting.
@@CodeTradingCafe thanks! Lol I guess I need to catch up with you other videos then. Looking forward to watching more of them today.
Seria possível fazer uma (IA) que analisasse o gráfico e pudesse prever a continuidade do movimento?
Hi I did something close to your description it's a video about channel detection you can do it by checking the slope of the fits
My thanks for the clip. I don't recall whether or not which version of Python is used? Just started learning Python a few days back. The differences from one edition to another can be a little surprising and unexpected.
Hi, thank you for your support. I have 3 python versions on my system I don't recap which one I used, I usually hover between 3.8 and 3.10, I don't think it makes any difference for the content shown in this video. Good luck!
excellent video thank you. Question, how do you buy on margin? I know you need a margin account but how do you enter a trade with specific margin like 1:5?
Hi, actually when you setup your account you need to specify the account leverage or margin, then it's fixed for all the trades you open through that account. This is why in the backtest it's a constant parameter in the function of the backtester.
Nice video... Is there a automated way to plot HH, HL, LL, LH with python...?
Thank you for your support, yes there is a way to select points/values and plot these, if I understand your question correctly, this video might be helpful ua-cam.com/video/phy57DZOIwc/v-deo.html
Good luck
@@CodeTradingCafe yes it's somewhat closer... I am looking to create something like this... I am not sure if it is correct... # fig.add_trace(go.Scatter(x=dfpl.index, y=dfpl.HH, mode='lines', name='HH'))
# fig.add_trace(go.Scatter(x=dfpl.index, y=dfpl.LL, mode='lines', name='LL'))
# fig.add_trace(go.Scatter(x=dfpl.index, y=dfpl.LH, mode='lines', name='LH'))
# fig.add_trace(go.Scatter(x=dfpl.index, y=dfpl.LL, mode='lines', name='LL'))
something like this...
forexbee.co/wp-content/uploads/2022/01/Screenshot-572-1-760x417.png
Something is off, tried running on AAPL for 2015-01-01 until 2023-01-21 and the return % is negative. The strategy needs further optimization.
Hi, thank you for your feedback, did you use the daily timeframe?
@@CodeTradingCafe Yes, daily. Did not modify your code at all. I have my own version with some minor changes, however the win ratio is a little higher than 50%. By the way, I made a trading bot that works with Robinhood API, but after running it for about a month last year, I decided to switch it off, the results were 50/50. So now I am looking for different strategies, and came across your videos.
There are many winning strategies but you have to find a low commissions broker/type of account. And yes I think the parameters should be optimized for the strategy in the video
Can I change the timeframe from daily chart to 1 minute chart?
Hi I don't think it's going to work, that's huge difference!
What is interesting is that this model relies on margin without which you under perform B&H. With margin you expose yourself to a roller coaster of panic as every dollar loss is multiplied. Few can withstand that kind of pain.
I agree it's not realistically tradable, on the B and H matter, it's really hard to find a strategy that beats BH for long term uptrending stocks like apple, amazon, microsoft, gold ... however BH is easily discarded on ranging or downtrending assets.
thanks
Thank you for your support
Drawdown of -95% or -45% or even -20-25% is inacceptable. Imagine you put $100.000 cash and after a while suddenly you see -$50.000, even -$20.000 it's a lot.
Of course it gives to you +30.000% but this is just because you tested it on index funds or stocks and these have mostly an uptrend. Try to see how it works when there is a lot of variation and volatility like Forex scalping or anything thing else that is not mostly in uptrend.
Yes it's only shown for demo purpose only. First I would decrease leverage and have a steady curve up. Actually have you seen the first video of the Bollinger bands strategy? It has no drawdown. Let me know what you think.
I have seen all your videos already but I have just seen once more that one you are talking about. -28% drawdown is HUGE.
Second, it is wrong to optimize parameters because it will find best settings for already known data but it will fail on new data because it is like AI it is optimized for what it already knows and trying to predict the future based on past data is wrong just because data doesn't repeat, it is different, the future data is different than the past data, that's why it is not working.
Also, just two or three trades it is not enough, it must be more than 500 trades let's say at minimum because in real life it will do a lot of trades.
Also, index funds or stocks have mostly uptrends and very few downtrends which means that there is no variation, no volatility and it will fail big when the economic situation is bad, in fact when it meets the real fluctuations and volatility. You should choose for testing assets with very high volatility and fluctuations which are very hard to predict and to trade and where there isn't any clear trend up or down. For this I think 1 minute data is very good which also allows you to do a lot of trades to see how it works in real life and in hard to predict conditions because these conditions appears even in a clear trend and bland situation and when they appear they will destroy your strategy if it is not prepared for them.
Also, try to add a trailing stop to see how it works.
Expecting a new vide from you on the subject! 🤗
@@Krisler12 you said that using past data to predict future is wrong because the future will not repeat. So my question to you is, what is the best strategy to trade? Where can I get profitable trading strategy? Or what can I do to trade profitably if this kind of approach or AI do not work.
I don't know. If someone will find the best way to solve this problem he or she will be a billionaire and the richest man in the world. I think just using a more general strategy that could work on many assets and a trailing stop and also a good money management strategy could somehow give a good strategy.
@@Krisler12 in my experience Real algos achieve 8% to 15% max per year, we're not talking leverage because it's not a good idea to increase risk. Some years returns are higher but that's just luck, normal automated systems are around 10% a year on average. I have discussed this with a real trading and investment company and this is the reality. Now other trading forms like high frequency or having access to restricted data can bring more power to the algorithm and this is where it gets interesting, but the data is restricted by law and money (have to be a certain type of registered company to ask access to advanced market data and you pay a lot for it annually). That being said it's still fun to try algos around, I tried recurrent neural networks recently I will post the code in a video... soon
hai sir , can you do robo for IQ OPTION / OLYMP TRADE like binary option concepts?
Hi you can directly adapt this code for any market you desire. Good luck!
Edit: check my last video for building a trading bot.
@@CodeTradingCafe can i contact you sir? please
Hi, unfortunately I can't take any developments at the moment, lots of projects going on. But you can make it just walk through the videos.
@@CodeTradingCafe any other developers can u recommend,
@@CodeTradingCafe thanks for your responce
Yes but does it translate forward on the data not seen by the training/optimization. Don’t believe so.
It's harder to make it work for low timeframes, but for some reason every strategy I tried on the daily time frame worked well but it's slow, one trade per month so we need to run on more assets ... so more money is needed in the account.
so basically you gain money when trend is going up and losing when its going down, if we find some way to not los money (buy when its still down trend) we will have higher wr for sure
Hi, thanks for sharing. As it is, yes you are right for the algo deals well with one trend direction. You can also have another algo tuned for downtrends and the 2 algos running together might be a good hybrid solution.
15:1 margins and no fees included. So it’s purely hypothetical and not using real world conditions
I agree it's not an absolute estimate but it allows me to compare strategies and indicators together at some point we can retest a strategy if it looks promising adding commissions. Also trade management is very simple here it can be improved as well (this part I find fascinating)
where is the code for mt5?
Sorry coding only in python these days.
it's just in a theory ..............practical case is totally different
Yes this one is not advised for real trading, just a python exercise
Thank you sir the problem is u r using large timr data we want to get rich fast while sleeping hh😂😅 (as you said in 9ne of your videos )
I must make a video about this becoming rich fast issue 🙂 I get this question a lot as well.
@@CodeTradingCafe we know sir hhh just jocking make a video about getting rich while sleeping 😂😂😂
Getting rich in our dreams maybe 😂😂😂
Well you can still make money while sleeping but not enough to be rich... Rich like buying a hotel a boat and a supercar, trading makes 20 percent return per year so it's limited. But again you can make some money out of it.
Unsurprisingly, the strat lost money during COVID outbreak (black swan event).
I didn't notice the link, might be true! Thank you for your comment
Are we just going to slide right past that drawdown 😂
yep :) this is mainly what happens when greed pushes leverage up.
inspiring videos, BRAVO
Glad you like them! thank you!
Very misleading. This market is already in a strong uptrend. It's hard not to make money.
It's not misleading if you already know the strategy works in trending markets, other strategies work in ranging markets... there is no single strategy that works in all types of markets. But yes I understand that it can't be applied blindly to all circumstances, it simply wouldn't work. However the Bollinger entry trick does bring an advantage in most cases.
Hi @codetrading can you show how to use it on Crypto exchange like coinbase or other please. thank you for the videos
Hi it's possible only if the platform has python API, like binance for example for the rest I have to check
@@CodeTradingCafe Thank you do have video to show how to use on binance please. Much appreciated
Hi you can use ccxt library
4:15 this isn't good practise. one should not use python lists and slow for loops but perform the operations directly on the dataframe:
df['EMA_SIG'] = np.nan
df.loc[df.EMA_1 < df.EMA_2, 'EMA_SIG'] = SIG_BEAR
df.loc[df.EMA_1 > df.EMA_2, 'EMA_SIG'] = SIG_BULL
Hi, thank you, I agree vectorized approach is more efficient.
Try this code on h1 timeframe
Someone did they told me it's highly profitable!