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

ความคิดเห็น • 67

  • @7rang.
    @7rang. 4 หลายเดือนก่อน +2

    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.

    • @CodeTradingCafe
      @CodeTradingCafe  4 หลายเดือนก่อน +1

      Great tip! Thank you for your support.

  • @cptherr3309
    @cptherr3309 2 ปีที่แล้ว +6

    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

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว +1

      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

    • @cptherr3309
      @cptherr3309 2 ปีที่แล้ว +1

      @@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

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว +2

      @@cptherr3309 will try to include SR levels in the future, hopefully we will not be disappointed 🙂

  • @ionutoceanu1434
    @ionutoceanu1434 ปีที่แล้ว +2

    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 ?

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว

      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.

  • @Leo-cw6dr
    @Leo-cw6dr 2 ปีที่แล้ว +2

    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?

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว +2

      Theoretically if done properly both backtest methods should provide the same results otherwise there is an error somewhere. Good luck

  • @wuyunhua7368
    @wuyunhua7368 ปีที่แล้ว +1

    This is the first time I've seen your video
    , wonderful!
    btw, from backtesting import Strategy, Backtest
    so how to install backtesting package?

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว

      Thank you for your comment, backtesting can be installed from the conda command prompt (if you are using anaconda) type pip install backtesting

  • @MarcioAramuni
    @MarcioAramuni ปีที่แล้ว +2

    Hi. nice technique you have. Could you post the csv file?

  • @planb5386
    @planb5386 2 ปีที่แล้ว +2

    thank you for your video.

  • @somaraju8631
    @somaraju8631 ปีที่แล้ว +2

    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.

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว +1

      True, the trend can help but mostly I am eager to include advanced trades management entry/exit

  • @alrey72
    @alrey72 ปีที่แล้ว

    Nice explanation. What about the consideration of bid/offer spread? Was it discussed?

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว

      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.

  • @santhoshdasari7
    @santhoshdasari7 2 ปีที่แล้ว +1

    Thanks a lot for sharing

  • @dorontobiano1134
    @dorontobiano1134 11 หลายเดือนก่อน +1

    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....

    • @CodeTradingCafe
      @CodeTradingCafe  11 หลายเดือนก่อน

      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.

  • @Hubert66613
    @Hubert66613 หลายเดือนก่อน +1

    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

    • @CodeTradingCafe
      @CodeTradingCafe  หลายเดือนก่อน

      Hi, thank you, data can be obtained from your broker if they provide it, yfinance or Dukascopy (the latter is great).

    • @Hubert66613
      @Hubert66613 หลายเดือนก่อน

      @@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

    • @CodeTradingCafe
      @CodeTradingCafe  หลายเดือนก่อน

      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.

  • @juanbatista6075
    @juanbatista6075 2 ปีที่แล้ว +2

    great videos. All video are increible. But how can I put the strategy in the real platform. What platform can i use?

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว

      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

  • @samueltamayogaviria3377
    @samueltamayogaviria3377 2 ปีที่แล้ว +1

    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?

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว

      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

    • @samueltamayogaviria3377
      @samueltamayogaviria3377 2 ปีที่แล้ว

      @@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?

    • @alrey72
      @alrey72 ปีที่แล้ว +1

      A spread of 0.2% is too big. Most brokers offer a max of 0.02% for popular pairs.

  • @user-cz6ht4ot7o
    @user-cz6ht4ot7o 2 ปีที่แล้ว +2

    THANK YOU SIR🙏🏻 YOUR VIDEOS INCREASE MY ANALYSIS STYLE.
    SIR PLEASE MAKE VIDEO ON ALL STATISTICAL INSTRUMENT USE IN QUANTATIVE ANALYSIS.

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว

      Thank you for your comment, which statistical instruments you mean?

    • @user-cz6ht4ot7o
      @user-cz6ht4ot7o 2 ปีที่แล้ว +1

      @@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?

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว

      @@user-cz6ht4ot7o which statistical instruments? I don't understand

    • @user-cz6ht4ot7o
      @user-cz6ht4ot7o 2 ปีที่แล้ว +1

      @@CodeTradingCafe LIKE HYPOTHISIS TESTING,CDF,PDF,NORMAL DISTRIBUTION.THANK YOU SIR

    • @user-cz6ht4ot7o
      @user-cz6ht4ot7o 2 ปีที่แล้ว +1

      SIR PLEASE REPLY🙏

  • @connectrRomania
    @connectrRomania 2 ปีที่แล้ว +1

    Im thinking of a strategy that combines causality in ML with correlation

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว +1

      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

  • @ventiladorbueno1846
    @ventiladorbueno1846 2 ปีที่แล้ว +2

    Thxs

  • @jack_separo
    @jack_separo 10 หลายเดือนก่อน +1

    Where i can download the csv data? Thanks

    • @CodeTradingCafe
      @CodeTradingCafe  10 หลายเดือนก่อน

      you can get any data you want from yfinance or dukascopy, check this video th-cam.com/video/yunQT598664/w-d-xo.html

  • @sigmareaver680
    @sigmareaver680 9 หลายเดือนก่อน +1

    I was trying to run this on ^RUI but I seem to be doing something wrong.. It doesn't seem to do anything.

    • @CodeTradingCafe
      @CodeTradingCafe  9 หลายเดือนก่อน +1

      Hi, just make sure you have the data file for ^RUI in the same folder as the code.

    • @sigmareaver680
      @sigmareaver680 9 หลายเดือนก่อน +1

      @@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

    • @CodeTradingCafe
      @CodeTradingCafe  9 หลายเดือนก่อน +1

      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.

  • @Ruhguevara
    @Ruhguevara ปีที่แล้ว +1

    what does "margin = 1/50" means?

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว

      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)

  • @iritesh
    @iritesh ปีที่แล้ว +1

    Didn't work for me, 93% drawdown
    Can you share the data you backtested with too?

    • @Kevinschart
      @Kevinschart ปีที่แล้ว

      of course it didn't work

  • @leocycling
    @leocycling ปีที่แล้ว +1

    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

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว +1

      Hi, because we want to check if the candles close above the ema, you could also try with the high price as well.

  • @dimi1789
    @dimi1789 2 ปีที่แล้ว +1

    Thank you for your videos, they are very informative.
    Could you post the csv files for us :)

    • @CodeTradingCafe
      @CodeTradingCafe  2 ปีที่แล้ว +2

      Yes sorry for the delay I will add a link in the description ASAP

  • @harrisansari8984
    @harrisansari8984 ปีที่แล้ว +1

    How do i modify ur code to use binance API

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว

      Hi the best is to start with binance documentation to know the functions you need.

    • @harrisansari8984
      @harrisansari8984 ปีที่แล้ว +1

      @@CodeTradingCafe Can you do that? No coding experience! I`ll do some donation on ur channel since ur videos are gems. thnx

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว

      @@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.

  • @loomefy9062
    @loomefy9062 ปีที่แล้ว +1

    can you give me fileof bot mql 4

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว

      hi, I am not programming mql4 recently, python rocks! :)

  • @user-zx6zc6ct2v
    @user-zx6zc6ct2v ปีที่แล้ว +1

    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

    • @CodeTradingCafe
      @CodeTradingCafe  ปีที่แล้ว

      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).