Automated RSI Scalping Strategy Tested In Python
ฝัง
- เผยแพร่เมื่อ 12 มิ.ย. 2024
- An Automated RSI Scalping Strategy is presented and backtested using python algorithmic trading over 3 years of data showing positive returns. The Test details of the strategy and the code are presented and explained as well as the resulting returns up to 250% equity profit. A good way to test a strategy is by using algorithmic trading skills in an automated code sych as python, hopefully it will be of help. Good luck!
🍓 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!
For code geeks you can download the code using the following links:
For 1 min timeframe:
drive.google.com/file/d/12Ez9...
For 15 min timeframe:
drive.google.com/file/d/1ruvf...
For 1h timeframe:
drive.google.com/file/d/1nb9E...
#TradingBot #PythonCoding #forexanalysis
00:00 RSI Scalping Indicators
04:20 Python Code
16:00 Backtesting And Modifications
What a great TH-cam channel I found. Thank you very much, explained very well. I would also add a heat map to determine the best parameters for indicators and stops.
Great tip! Thank you for your support.
Yet again an amazing video! The exit strategy could be enhanced with implementing support and resistance (+- offset) based tp and sl. the offset could rely on fibonacci lines on a lower time frame
Thank you! I agree with the support/resistance TP and SL, however I am not a believer in Fibo levels ... I might be wrong though
@@CodeTradingCafe I would love to see a support/resistance implementation in one of your upcoming videos. Can't wait to see with what will you come up next :D
@@cptherr3309 will try to include SR levels in the future, hopefully we will not be disappointed 🙂
Very valuable content in your work. Have you explored the option of having multiple TP levels and SL set at the buy price after 1st TP ?
Thank you! Not yet, actually I tried none of the trading management approaches yet, which is something very interesting in my opinion, I will have to make a video at some point. It might be a good solution to limit drawdowns.
Thank you for creating such a great video. I have a question that bothers me for a while, is even driven backtest more accurate than vectorize backtest? I heard someone say that if you did properly, the vectorize backtest were even more accurate...what do you think?
Theoretically if done properly both backtest methods should provide the same results otherwise there is an error somewhere. Good luck
This is the first time I've seen your video
, wonderful!
btw, from backtesting import Strategy, Backtest
so how to install backtesting package?
Thank you for your comment, backtesting can be installed from the conda command prompt (if you are using anaconda) type pip install backtesting
Hi. nice technique you have. Could you post the csv file?
thank you for your video.
Thank you for your support 😊
If we consider market conditions also into consideration like sideways market, bull or bear market and incorporate different entry exit techniques according to type of market, the results could be even better.
True, the trend can help but mostly I am eager to include advanced trades management entry/exit
Nice explanation. What about the consideration of bid/offer spread? Was it discussed?
Hi, thank you, no spread and fees are not added, I usually compare strategies in raw format then if one is working well we can add fees on top to see the performance.
Thanks a lot for sharing
Thank you for your support
Great video !
I do have a question, where do you get a data base with 1 million candles of 1minute ?
I tried to find a website to get these, but the most I could get was like 100k candles....
Hi, you can use dukascopy or a broker like oanda they provide data like this, if I remember correctly the data in this video is from dukascopy. I hope this helps.
Amazing video! Thanks for this.
Could you please tell where to find such old data? e.g. from 2010 to today for EURUSD etc. I only found from 3 moths back
Hi, thank you, data can be obtained from your broker if they provide it, yfinance or Dukascopy (the latter is great).
@@CodeTradingCafe Ok, I didn't find any data so I created a bot in C# and used the data from my current broker and my results are very bad for EURUSD M15.
The effectiveness is 35% and fees ate all profits.
I changed the following elements:
- Instead of EMA I used BB to eliminate the consolidation
- Changed interval to H1 and multiplier in SL (2 instead of 1.3)
From 01.01.2023 to 22.04.2024
- EURUSD, the effectiveness of the strategy is 45.56% not bad
- US100 the effectiveness is 44.3% similar
- BTCUSD the effectiveness is 37.5% poorly
In general, I only used the opening price of the m1 bars, so some of the trades are loss-making and should not be (missing some bars, bad ticks etc.). There is potential I will continue to test it, maybe I will find good parameters
It's usually the hardest part now, to understand why it's not working and come up with an idea to filter the cases where risk is high.
great videos. All video are increible. But how can I put the strategy in the real platform. What platform can i use?
Thank you, I usually use python to connect with oanda, other platforms like binance are also possible. However if you are not experimented in Coding it might be challenging. I must make a video on this like how to connect with trading platforms using python
Hello!. I have a question. For some reason I'm having a ValueError once I set a commission of 4% and a Spread of 0.2% telling me that the TP for short and long trades is not setted well (I'm using the ATR for SL and TP). Could I send you a mail with my problem and see if you have any idea how to solve it, please?
It might be that at some point with these settings the account is totalled (bad news I know) try for example decreasing the lot size or the spread just to test it out
@@CodeTradingCafe Hey, bro!. Could you make a backtest using a commission of 4usd per lot traded and an average of 0.3pips of spread, please?
A spread of 0.2% is too big. Most brokers offer a max of 0.02% for popular pairs.
THANK YOU SIR🙏🏻 YOUR VIDEOS INCREASE MY ANALYSIS STYLE.
SIR PLEASE MAKE VIDEO ON ALL STATISTICAL INSTRUMENT USE IN QUANTATIVE ANALYSIS.
Thank you for your comment, which statistical instruments you mean?
@@CodeTradingCafe PLEASE SIR FIRST MEKE A SHORT VIDEO TO INFORM NAME OF ALL STATISTICAL INSTUMENT.
THEN WHICH YOU PREFER ONE BY ONE.
I KNOW IT IS VERY TIME CONSUMING.PLEASE SIR. IS IT POSSIBLE SIR?
@@user-cz6ht4ot7o which statistical instruments? I don't understand
@@CodeTradingCafe LIKE HYPOTHISIS TESTING,CDF,PDF,NORMAL DISTRIBUTION.THANK YOU SIR
SIR PLEASE REPLY🙏
Im thinking of a strategy that combines causality in ML with correlation
The best is to start with easy stats and correlating indicators, choosing uncorrelated ones and so on, I also had something like this in mind, I think I will do it at some point, step 1 stats and correlations step 2 maybe ML
Thxs
Thank you!
Where i can download the csv data? Thanks
you can get any data you want from yfinance or dukascopy, check this video th-cam.com/video/yunQT598664/w-d-xo.html
I was trying to run this on ^RUI but I seem to be doing something wrong.. It doesn't seem to do anything.
Hi, just make sure you have the data file for ^RUI in the same folder as the code.
@@CodeTradingCafe I was using yfinance to download it. But I realized I may have the wrong candlestick interval. They dont keep old 15min data, do they? I will have to find a different source maybe
Hi there, yfinance does have 15 min and lower timeframe data, however it is limited to the last 60 days of data so you can't download 2 or 3 years of data for lower timeframes. Try Dukascopy as long as it's free.
what does "margin = 1/50" means?
Hi, it's a leverage for example if your account is 1000$ cash it's trading value is 50*1000 so 50000$ check online about leverage and how it works, I am also showing the leverage effect in my next video (for a specific strategy)
Didn't work for me, 93% drawdown
Can you share the data you backtested with too?
of course it didn't work
Thx bro, question on check trending with ema200
df.High[row]>=df.EMA200[row]:
dnt=0
if df.Low[row]
Q: why not using df.Close instead of df.High
Thx bro
Hi, because we want to check if the candles close above the ema, you could also try with the high price as well.
Thank you for your videos, they are very informative.
Could you post the csv files for us :)
Yes sorry for the delay I will add a link in the description ASAP
How do i modify ur code to use binance API
Hi the best is to start with binance documentation to know the functions you need.
@@CodeTradingCafe Can you do that? No coding experience! I`ll do some donation on ur channel since ur videos are gems. thnx
@@harrisansari8984 Hey, no need to donate I can do it for free, but it will take me couple of months because I am not able to make a lot of video I have long working/life hours. Anyway Binance is on my list.
can you give me fileof bot mql 4
hi, I am not programming mql4 recently, python rocks! :)
It was a little slow for me, so I changed this part:
upt = 0
dnt = 0
VWAPsignal = [0]*len(df)
backcandles = 15
for row in range(0, len(df)):
dnt = 0 if max(df.Open[ row ], df.Close[ row ])>=df.VWAP[ row ] else dnt +1
upt = 0 if min(df.Open[row], df.Close[row])= backcandles :
VWAPsignal[row] = 1
if upt >= backcandles :
VWAPsignal[row] = 2
df['VWAPSignal'] = VWAPsignal
I thought why not just count the candles we're in trend.
I thought this is too good to be true, so I added a little commission of 0.2%, since I don't know any place where I could trade the forex through API for zero fee.
The results are worse instantly:
Start 2019-09-30 00:00:00
End 2020-09-30 04:25:00
Duration 366 days 04:25:00
Exposure Time [%] 45.774667
Equity Final [$] 68.741901
Equity Peak [$] 100.002493
Return [%] -31.258099
Buy & Hold Return [%] 7.246403
Return (Ann.) [%] -25.760915
Volatility (Ann.) [%] 2.698652
Sharpe Ratio 0.0
Sortino Ratio 0.0
Calmar Ratio 0.0
Max. Drawdown [%] -31.781563
Avg. Drawdown [%] -16.071779
Max. Drawdown Duration 364 days 07:30:00
Avg. Drawdown Duration 182 days 18:50:00
# Trades 410
Win Rate [%] 42.195122
Best Trade [%] 0.460719
Worst Trade [%] -0.436018
Avg. Trade [%] -0.092922
Max. Trade Duration 3 days 17:45:00
Avg. Trade Duration 0 days 10:38:00
Profit Factor 0.367788
Expectancy [%] -0.092731
SQN -9.679237
Hi thank you for sharing. First try it without the commission just to see if the logic works in the good direction. And the commission you added is huge (0.2%) they usually advise 0.001% to account for the spread and another 0.001% for the commission (I recap something like this from the backtesting library docs but we need to reverify).