Python Backtest: Profitable Scalping Strategy with VWAP, Bollinger Bands and RSI Indicators

Поділитися
Вставка
  • Опубліковано 10 гру 2024

КОМЕНТАРІ • 532

  • @tradingbotconale
    @tradingbotconale Рік тому +49

    I appreciate a lot your content. The snippet that evaluate uptrend or downtrend is very slow, I've refactorized it removing loops and now is very fast. I share my update. Thanks for your effort and strategies. Alex.
    df['Max_Open_Close'] = np.maximum(df['Open'], df['Close'])
    df['Min_Open_Close'] = np.minimum(df['Open'], df['Close'])
    df['upt'] = 1
    df['dnt'] = 1
    df.loc[(df['Max_Open_Close'] >= df['VWAP']), 'dnt'] = 0
    df.loc[(df['Min_Open_Close']

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +4

      Thanks a lot for your input, the code looks nice, I will pin your comment for other viewers in case they need the improved version.

    • @kisumang7971
      @kisumang7971 9 місяців тому +2

      hi im newbie for python. would you help me where input this code? thanks much!

    • @tamaspete8299
      @tamaspete8299 8 місяців тому +1

      can you help for me how i can replace these code? I think I place the wrong place and it crashed

    • @leventebozsoki7679
      @leventebozsoki7679 6 місяців тому

      @@tamaspete8299 # Determine VWAP signals
      for row in range(backcandles, len(df)):
      upt = 1
      dnt = 1
      for i in range(row - backcandles, row + 1):
      if max(df.Open.iloc[i], df.Close.iloc[i]) >= df.VWAP.iloc[i]:
      dnt = 0
      if min(df.Open.iloc[i], df.Close.iloc[i])

    • @mekabozar6855
      @mekabozar6855 5 місяців тому

      @@tamaspete8299 chek the dependencies of your python

  • @lennard4454
    @lennard4454 2 роки тому +61

    I was able to archive 3000% in return with this algorithm and some improvements in the parameters for Bitcoin 5m chart data, backtested from Jan 2022 until today.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +11

      Thank you for your feedback, just be careful with the drawdown keep it on your radar.

    • @troygomez4089
      @troygomez4089 2 роки тому +3

      👌 Did you add technical indicators or just adjust the values for the given tis?

    • @lennard4454
      @lennard4454 2 роки тому +36

      ​@@troygomez4089 just adjusted the parameters:
      rsi length: 16
      bbands length: 15
      bbands std: 2.0
      back_candles: 26
      total signal buy below rsi: 46
      total signal sell above rsi: 59
      atr index: 7
      slatr: 1.2
      tpsl_ratio: 1.89
      close long above/equal rsi: 90
      close short below/equal rsi: 10

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +12

      Thank you for sharing

    • @lennard4454
      @lennard4454 2 роки тому +6

      @@troygomez4089 also had a typo ... used BBL instead of BBU to confirm the total sell signal... but correcting it decreased the success in return and win rate ... I guess the other parameters would have to be optimized again - although still 1300% return

  • @rupindersingh1312
    @rupindersingh1312 2 роки тому +17

    i have no words how to express my gratitude for this channel . Really your every video is making a change in my journey of algo trading .

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Thank you for your supportive comment, it's nice to know and very encouraging! Good luck!

  • @davidhuber563
    @davidhuber563 Рік тому +2

    Thank you for this video ! I began algo trading 1 year ago and your video helped me a lot. Seeing a scalping video on your Chanel is very cool, because there are no big ressources on scalping strategies that are reliable on UA-cam and the internet in my opinion, so thank you !

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +3

      Hi, thank you for your comment. Indeed I didn't want to make scalping video at first because it's challenging the data has too much noise, but this was requested so many times, and I think the VWAP is really good and also the BBands help define a good entry point. Good luck to you! (actually it has been a while I haven't looked into lower timeframes maybe I will revisit scalping soon).

    • @ruffianragu2809
      @ruffianragu2809 5 місяців тому

      Hi Bro,
      I want you use Algo trading please let you guide me..

  • @fernando1296
    @fernando1296 Рік тому +5

    at minute 10:37,
    To verify that entry below the VWAP, perhaps you could calculate the difference between the VWAP and the Bollinger line, and from there if it passes a percentage it is taken as valid.
    And maybe a bit more complicated to verify the sail in major or minor frames, and see a confirmation there...
    Or adding more indicators like the MACD, EMA, or volume.
    In addition, support or resistance could be taken into account (later video), or Wickokff accumulation zones, distribution zones, doing nothing at market openings (a lot of volatility), perhaps it could improve performance

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +2

      Support and resistance levels are crucial, I agree and the trading time wasn't included yet so trades are opened anytime the market is opened this can be improved definitely.

    • @gawags4709
      @gawags4709 Рік тому

      ​@@CodeTradingCafe I use volume data to confirm signal above or below vwap. I want to see heavy buying or selling volume moving the price action in relation to time. I use at least 2 or 3 time scales on the chart such as (1, 5, 10, 15, daily). I only focus on trading 1 stock/product at a time and get to know how it moves and try to understand the time frames that larger investors make their trades. It's always interesting to see how light volume moves the price after these heavier volume periods. Everything you discussed in this video is pretty similar to the strategy I use to scalp with.

  • @Maximus18.6
    @Maximus18.6 11 місяців тому +5

    First of all let me congratulate you for such amasing explanation and presentation. You explain very complex concepts of financial indicators and programming in only 15 minutes, that is spectacular. It will be very interesting to add some market sentiment analysis using Python to find news that impact stock price.

    • @CodeTradingCafe
      @CodeTradingCafe  11 місяців тому +2

      Thank you for your supportive comment. Sentiment analysis is on my list at least to show how it can be implemented, the only challenge is that you never know when the sentiment will be reflected on the market in a day, a week or more, but I think this is something we can discuss when I make the video. Have great new year!

  • @warwick3805
    @warwick3805 Рік тому +2

    Great video mate, thanks.
    I am not a coder, but I try, with what I have learnt, to get an Algo that works. I am now a follower and look forward to learning more.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Probably one of the most rewarding/satisfying comments! Glad I could help! Good luck!

  • @kro8732
    @kro8732 2 роки тому +19

    Hey! You can optimize parameters with methods like differential evolution. I'm not sure if that will do better but you can give it a try. Great video as always.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +5

      Thank you for your support! You're right it is worth trying an optimization see what it gives, I am not sure how much improvement there will be.

  • @Nico-uu2yk
    @Nico-uu2yk 6 місяців тому

    I'm just getting into algo trading, no algorithm deployed yet but thats such a great video thank you! There is not much information available regarding scalping so thankful your channel exists!

    • @CodeTradingCafe
      @CodeTradingCafe  6 місяців тому +1

      Glad it was helpful! and thank you for your support. Please keep in mind this backtest doesn't include commissions so the trade management part need to be human controlled. On the other hand scalping is way more difficult to automate than higher timeframes... in my opinion but I might be wrong. Good luck!

    • @Nico-uu2yk
      @Nico-uu2yk 6 місяців тому

      @@CodeTradingCafe how much can you realistically get in return using longer timeframes?

    • @CodeTradingCafe
      @CodeTradingCafe  6 місяців тому +1

      Around 8-20 % per year all costs included (my experience, but maybe other algo traders do better)

    • @Nico-uu2yk
      @Nico-uu2yk 6 місяців тому +1

      @@CodeTradingCafe damn not as much as I thought. I thought it would be like 2-5% per month at least. Thanks for your insight tho!

    • @CodeTradingCafe
      @CodeTradingCafe  6 місяців тому +1

      If you have time to do hybrid trading, meaning an algorithm will detect patterns and send you notifications but then the trading is done manually you might reach 5% monthly with good trade and risk management, but this requires a lot of waiting time as well.

  • @horexas
    @horexas 2 роки тому +7

    Great content! Perfectly synchronised with my current experiment

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Happy you liked it, I like the vwap recently it's a nice indicator

  • @freepluralism6652
    @freepluralism6652 2 роки тому +1

    simple but decent strategy. getting => 22% Net Profit / 70% Profitable / 4% Drawdown on BTC/USD 5min TF. I'm using SL x2 and TP x1.5 and a cross above of the lowerband for a long position and vice versa

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thank you for sharing, it's nice to know how it works on different assets. Good luck!

    • @vpx_mbyt7663
      @vpx_mbyt7663 Рік тому

      Hello, may I kindly speak to you

  • @JohnQuezadaHuayamave
    @JohnQuezadaHuayamave 2 роки тому +1

    Your videos are incredible, I'm going to review them all, I'm new, I just saw the first video today, sorry if I don't write very well, it's that I speak Spanish and English is not precisely my strong language and you could use a weighted moving average of 150 and 300 to see trends.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Hey, thank you for your comment, I will try weighted moving average see how it goes. Good luck!

  • @jorgecasas9263
    @jorgecasas9263 2 роки тому +4

    Fist at all thank for all your content, super great, Keep it up!!.
    I checked Microsoft (5 min), doesn't look good:
    Start 2022-07-15 09:30:00
    End 2022-10-12 15:55:00
    Duration 89 days 06:25:00
    Exposure Time [%] 1.750102
    Equity Final [$] 80.747453
    Equity Peak [$] 102.614197
    Return [%] -19.252547
    Buy & Hold Return [%] -12.418022
    Return (Ann.) [%] -57.487629
    Volatility (Ann.) [%] 28.451232
    Max. Drawdown [%] -31.08406
    Avg. Drawdown [%] -31.08406
    Max. Drawdown Duration 84 days 03:00:00
    Avg. Drawdown Duration 84 days 03:00:00
    # Trades 17

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +2

      Hi thank you for the update, it might need some tuning, mainly the SL TP ratio and SL position, it should be fine for some set of parameters.

  • @sadootaqoo981
    @sadootaqoo981 2 роки тому +5

    Before testing other parameters, try m1 candles to m30 and see which one yields the most win rate, very good content btw , cant wait for an update

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +2

      Thank you, yes I was thinking m15 might be a good candidate... There only one way to find out

  • @epiktrader2656
    @epiktrader2656 2 роки тому +7

    This is very good. Please bring more scalping and intrday strategy backtest. Can you please add a initial capital, so that we can see how much a particular amount will grow.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +2

      Thank you for your comment, don't forget that fees were not included here so initial capital might not be very accurate

    • @epiktrader2656
      @epiktrader2656 2 роки тому +3

      @@CodeTradingCafe Thanks for replying. Will you consider making more videos on intraday and scalping strategy

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +3

      I will try but lower timeframes are more challenging for coding it's much easier on daily timeframes, but yes I will keep this ongoing see if we can sort a nice strategy

  • @lautaa33
    @lautaa33 Рік тому +6

    Great content! Btw you can do the "VWAP Signal" calculation vectorized instead of iteratively so that it takes less than a second instead of the few minutes that takes in your code:
    downtrend = df[["Open", "Close"]].rolling(backcandles).max().max(axis=1) < df.VWAP, # if the highest candle body is below vwap then all candles in the rolling window are below vwap
    uptrend = df[["Open", "Close"]].rolling(backcandles).min().min(axis=1) > df.VWAP # if the lowest candle body is above vwap then all candles in the rolling window are above vwap

    • @lautaa33
      @lautaa33 Рік тому +1

      actually my code would only look at 1 vwap value for each window, but surely there is another way to do it right

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi thank you for sharing this, actually yes we can vectorize most of the computed values. But just for the sake of this discussion, sometimes if you are streaming for a live trading bot it's easier to have a function to call for each candle (can't explain clearly in the comment only in some particular cases of live trading it works better this way, but definitely slower).

    • @lautaa33
      @lautaa33 Рік тому +1

      ​ @CodeTrading Ah yeah I understand, you get a live feed candle by candle, and you want to pass to a function only the last n candles to calculate just the very latest vwap signal.
      Anyways, for anyone that wants the vectorized form for doing parameter optimization, I finally came up with the solution:
      downtrend_mask = df[["Open", "Close"]].max(axis=1).lt(df["VWAP"]).rolling(backcandles+1).sum().eq(backcandles+1)
      uptrend_mask = df[["Open", "Close"]].min(axis=1).gt(df["VWAP"]).rolling(backcandles+1).sum().eq(backcandles+1)
      df['VWAPSignal'] = 0
      df.loc[downtrend_mask, "VWAPSignal"] = 1
      df.loc[uptrend_mask, "VWAPSignal"] = 2
      ---
      The +1 after backcandles is to count the current row AND n backcandles (same effect as what is done in the iterative version done in the video/jupyter)

    • @lautaa33
      @lautaa33 Рік тому +2

      @@CodeTradingCafe Today I learned that you can just add the decorator @njit from the numba library to your function and will probably run faster than my complicated vectorized stuff. Might need to pass the pandas columns as numpy arrays but @njit takes the iterative loop, does just-in-time compilation of it and efficiently executes it, and can do it in a vectorized way

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      @@lautaa33 Hey thanks, I didn't know this, have to check it out!

  • @maciekpaciarski9343
    @maciekpaciarski9343 2 роки тому +3

    Great work. Please continue

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thank you for your support and encouragement 🙂

  • @leobike-1920
    @leobike-1920 Рік тому +3

    thx bro for this great video as usual, can i understand more the purpose of close trades when RSI >= 90 or RSI < =10.
    if len(self.trades)>0:
    if self.trades[-1].is_long and self.data.RSI[-1]>=90:
    self.trades[-1].close()
    elif self.trades[-1].is_short and self.data.RSI[-1]

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, yes we close the trade if the rsi goes above 90 for long positions and below 10 for short positions, since the rsi will show the overbought and oversold ranges of an asset.

  • @rezafeizabadi-vf1xt
    @rezafeizabadi-vf1xt 8 місяців тому

    Thank you for very good video. To identify the type of trend, the following condition can be replaced, if the price is higher than ATR in 80% of the past candlesticks, for example, it can be concluded that the price is bullish.

    • @CodeTradingCafe
      @CodeTradingCafe  8 місяців тому

      Hi, thank you for sharing, but the ATR is always below the price value, it's just the range, can you be more specific?

  • @joaosobral1354
    @joaosobral1354 2 роки тому +1

    Amazing video. Keep up the good work

  • @tmyersf4
    @tmyersf4 2 роки тому +1

    Was watching some of your videos today on detecting triangle and channel patterns so nice to see videos on this topics. Maybe you could also do a future video on harmonic pattern detection.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thank you for your comment, harmonics are not reliable, just my opinion (and my experience) but I might be wrong.

  • @ЭльмарИдрисов-г5э
    @ЭльмарИдрисов-г5э 2 роки тому +18

    Great content as usual. Definitely expand more on the strategy. Question: have you integrated your Python code with some trading platform? I mean, the code shows whether to buy or sell, but how the actual act of buying/selling is happening? Is it automated and Python does it for you or you do it manually based on the results of your code?

    • @ЭльмарИдрисов-г5э
      @ЭльмарИдрисов-г5э 2 роки тому +2

      @@thinketh2408, I see. So, first and foremost, the trading platform I am using should be allowing (providing api). Only then I can automate the process via building/using a trading bot.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +5

      Yes it depends on the platform they usually provide a python interface that you can add to your program and automate the trading process, I have an old video on this using oanda s API.

    • @ЭльмарИдрисов-г5э
      @ЭльмарИдрисов-г5э 2 роки тому +1

      @@CodeTradingCafe , thx for the reply. I will definitely check it out!

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      @@dxtrmst_FutureMusic I think it is being rejected when spread is high

    • @jaykishan3299
      @jaykishan3299 2 роки тому

      @@CodeTradingCafe suggest

  • @mouradelcadi
    @mouradelcadi Рік тому +1

    I'm completely newbie 😌 thanks so much

  • @khaleelgaffar3436
    @khaleelgaffar3436 2 роки тому +1

    Lovely video as usual!

  • @tdrmahdi
    @tdrmahdi Рік тому +1

    great work boss,, keep them coming

  • @patrickmekanna11
    @patrickmekanna11 5 місяців тому

    I would maybe include and define a feature that identifies range days since after range days we could expect bigger movements. Love the content. Thanks

    • @CodeTradingCafe
      @CodeTradingCafe  5 місяців тому

      Thank you for sharing. I agree, there strategies working on range days and break outs, working on one right now I will try and put it in a video.

  • @mike5iiii
    @mike5iiii 10 місяців тому

    nice job, I learned so much from you. Thanks

    • @CodeTradingCafe
      @CodeTradingCafe  10 місяців тому

      Thanks for watching! and for your support!

  • @MelarDev
    @MelarDev Рік тому +2

    One suggestion for a future video, Detect Fair Value Gaps and implement a strategy (ICT) based on it.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Hi thank you, I will look into this for the coming year.

  • @jaseemali7634
    @jaseemali7634 2 роки тому +1

    Thanks for the video, Great Content. Waiting for your complete automated trading course including live trading in udemy !!!.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thank you for your support ! Glad you enjoy the learning process.

  • @sw-ln1hh
    @sw-ln1hh Рік тому +1

    very awesome thank you for your coin test

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Hey, thank you for your constant support, glad the vid is helpful

  • @KaFaiTam-kl6lr
    @KaFaiTam-kl6lr Рік тому +1

    Interesting but, For my strategy list, I would BUY when RSI first time cross over 55 and reverse to sell when first time cross below 45 on day/week chart.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      that's one variation we can try maybe I can do it in a future video

  • @rainnerl
    @rainnerl 2 роки тому +1

    hi, first i want to thank you for your content is extremely educative... looking forward for a simple TrendLine Breakout Detection or TrendLine Touch Bounce....

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thank you for your support, your idea is something on my list I always vouch for a simple approach. Good luck!

  • @aliyananwar3727
    @aliyananwar3727 2 роки тому +1

    I am working on Exponential Moving Average indicators backtesting with 8 period 13 period and 21 period. 8 period crossover with 21 period and their spread will indicate whether the trend is strong or not.

  • @Themaugy90
    @Themaugy90 Місяць тому

    ТОП связка, прогоняю денежку постоянно.

  • @robertcayman1105
    @robertcayman1105 7 місяців тому +1

    please make a video with the standard deviation + vwap as a strategy !

    • @CodeTradingCafe
      @CodeTradingCafe  7 місяців тому +1

      it's on my list, but it might take me a while to reach it...

  • @anshmiester78900
    @anshmiester78900 2 роки тому +2

    Hi I really liked your videos. I wanted to know how can we determine which option to buy at which strike price after getting a positive signal. Please do make a video on that too

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thank you for your support, I usually only buy what the signal indicates, I don't know if this answers your question

  • @Maximus18.6
    @Maximus18.6 4 місяці тому +2

    Mate, you are doing an amasing job, an exceptional contribution to the trading and programming fields. My infinite gratitude for your contributions. Is there any way to contribute economically to your channel? God bless you.

    • @CodeTradingCafe
      @CodeTradingCafe  4 місяці тому +1

      Much appreciated! thank you. There is a join button next to the subscribe one, but you don't have to... mostly enjoy the content, share ideas and trade safe :)

  • @paulb9842
    @paulb9842 Рік тому +2

    how do I get the output in 13:48?

  • @adonisdeleon7729
    @adonisdeleon7729 2 роки тому +1

    this is very awsome but icant find the vwap on trading view thanks for sharing this you made me some profits bro

  • @БарбосМолокосос
    @БарбосМолокосос 2 роки тому +2

    Hello. I found something, but not the easy way. Try this as an entry point. use in strips length 20 and std 2.5 . This will show both the highs and lows that can be support and resistance at 0 and 1.
    data['HZ'] = (data['close'] - data['BBL_20_2.5'])/(data['BBU_20_2.5'] - data['BBL_20_2.5'])

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +2

      I like it and it's easier then another method I published here for support and resistance. Thank you

    • @БарбосМолокосос
      @БарбосМолокосос 2 роки тому +1

      @@CodeTradingCafe
      Thank you, too. I will be waiting for your next video.

  • @sz8558
    @sz8558 Рік тому +1

    Excellent video and thx for the code. Be great to see you test on say 80% of the sample data and then run it without adjustment on the remaining 20% to simulate real time trading.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Thank you for your support, you are right ideally we can fit on 2 month and trade one week for example, then slide our fitting window for a new trading period, I will include this in one of my future videos.

  • @robinprashantha1
    @robinprashantha1 2 роки тому +1

    Thanks for helping me to learn the backtesting strategies. I just want to know how to use bactesting optimize function(bt.optimize) for this custom startegy. So that we can get better results. Your help is much appreciated. Thanks

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Hi, thank you for your comment, I agree the optimize function is important to show I will have to make a video about it soon.

    • @robinprashantha1
      @robinprashantha1 2 роки тому +1

      Thanks for the help. Waiting for the same

  • @Nononononononope
    @Nononononononope 2 місяці тому +1

    you're a gem, thank you for the generosity. I will sign up for your course. my friend with 811 trades you really should include commissions and/or a minimum spread. did I miss where you have this set?

    • @CodeTradingCafe
      @CodeTradingCafe  2 місяці тому +1

      Hi in this video commissions and fees were not included, I was testing the indicator, usually for slower timeframes it's easier to get away with it even if fees are relatively high.

  • @eliotharreau7627
    @eliotharreau7627 2 роки тому

    Very nice code. This can help a lot. Thnx bro.

    • @eliotharreau7627
      @eliotharreau7627 2 роки тому

      You can see this videos, a very elegant way to use the BB. 👌👌 ua-cam.com/video/PcVHTx5HYwc/v-deo.html

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Thank you for your support and encouragement, good luck!

  • @sadikelouahabi398
    @sadikelouahabi398 2 роки тому +1

    thank you very much for your fantastic work for free for your subscribers.
    If you can add the divergence I think the winning ratio will increase a lot.
    thank you

  • @thinketh2408
    @thinketh2408 Рік тому +2

    Hi sir how to identity if strategy is good..
    Like what should be it max draw down percentage and period,, profit, sharpe ratio etc....

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, depending on how much risk you want to take, you can have extra safe strategy but only 1 percent return per month or very high risk and more return. All the parameters will change accordingly.

    • @thinketh2408
      @thinketh2408 Рік тому +1

      @@CodeTradingCafe thanks mate... I wanted to know you preference regarding this...
      Like what should be the minimum sharpe ratio and maximum draw down before you start using the strategy for real trading...

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +2

      I would say Sharpe ratio minimum 2 preferably 2.5 with spread fees included is a good start

    • @thinketh2408
      @thinketh2408 Рік тому +1

      @@CodeTradingCafe thanks

  • @ЕкатеринаМ-ф5к
    @ЕкатеринаМ-ф5к 2 місяці тому +2

    Do you have a video where commission are included in the backtesting?

    • @CodeTradingCafe
      @CodeTradingCafe  2 місяці тому

      Plenty, usually for slower timeframes (daily) you can easily afford commissions. These are more recent videos check them out in this playlist.

  • @basitali7267
    @basitali7267 5 місяців тому

    Your work and you both are great! I loved all your videos, it is amazing. I feel like I am Fan of you. Quite impressed (obviously the work) but looking at the replies more impressed. Hates off!!

    • @CodeTradingCafe
      @CodeTradingCafe  5 місяців тому

      Thank you so much 😀 your support is much appreciated! Good luck for your coding... and trading.

  • @christolabuschagne4382
    @christolabuschagne4382 Рік тому +2

    Trying to play around with the project. Very well done. I can't seem to figure out how to correctly compinsate for a commission of something like 0.5%. You would need to add it to the backtest init as 0.005, but then the buy and sell sl and tp values does not calculate correctly. Can anyone please point me into the right direction? Or is it just that the fees would kill you quick?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, I have to recheck how backtesting library is calculating the commission fees when we use for example 0.005 (the parameter in the backtesting function we are using), so far I didn't include the fees because I wanted to show indicators effects and compare among different indicators combinations.

  • @paulb9842
    @paulb9842 Рік тому +2

    is there a follow up video to this strategy?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Good point! there should be, but so many ideas came up and never got back to this one.

  • @rahuldavar7209
    @rahuldavar7209 2 роки тому +1

    Thank you so much!

  • @taraspanamarev6281
    @taraspanamarev6281 2 роки тому +1

    Thanks for the video! The strategy is interesting but very unstable. I mean it is very sensitive to changes in parameters

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Yes robustness must be tested as well to find the best parameters set, it's a start base as it seems. Usually scalping strategies are hard to tune I was happy with this one.

  • @santhoshdasari7
    @santhoshdasari7 2 роки тому +1

    Thanks a lot for sharing

  • @vpx_mbyt7663
    @vpx_mbyt7663 Рік тому +2

    Hi, the VWAP made in python, doesn't work like the one on tradingview. Can someone assist me please 😢

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      It might a variation, you can code your own as well if you need a specific VWAP. I hope this helps.

  • @boamahmarcus4002
    @boamahmarcus4002 6 місяців тому +1

    Great DR

  • @Pythonology
    @Pythonology Рік тому +1

    great! love your videos so far! how do you use this to run on the current market and make trades?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Thank you, to use a strategy live we can link it to a broker API, check this one: ua-cam.com/video/WcfKaZL4vpA/v-deo.html

  • @pedrocaluiz
    @pedrocaluiz 11 місяців тому +2

    Hello, thanks for video!!
    Please help me with the bt.plot, I have this error : ValueError: Length of values (2) does not match length of index (1)
    Do you know about that?
    thanks

    • @CodeTradingCafe
      @CodeTradingCafe  11 місяців тому

      it seems that you are trying to plot data with only 2 values and 1 index value, I don't where the mismatch is coming from, are you sure bt.run() completed successfully?

    • @egnatjovanich7661
      @egnatjovanich7661 8 місяців тому

      I also have the same problem, after run 'bt', it shows results, but after line bt.plot(show_legend=False)
      it shows error:
      "
      Data contains too many candlesticks to plot; downsampling to '1H'. See `Backtest.plot(resample=...)`
      ..... (many lines)
      ValueError: Length of values (2) does not match length of index (1)

  • @rezasadeghi2520
    @rezasadeghi2520 2 роки тому +1

    Thank you so much.

  • @gusalexanian5454
    @gusalexanian5454 Рік тому +1

    How would we go about optimizing parameters in this strategy as well as any others? Is there a universal way to do it?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Hi, thanks, I think optimization can be done using different libraries, there is a module in backtesting package I should have a look at it.

    • @gusalexanian5454
      @gusalexanian5454 Рік тому

      @@CodeTradingCafe It would be awesome to get a video on this. Love your videos thanks man

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      For some reason I didn't receive your comment it was flagged as spam by YT sorry about this!

  • @sajjadnaghshineh4224
    @sajjadnaghshineh4224 11 місяців тому +1

    Hi, thanks a lot for sharing this profitable strategy and I have a question about Max Drawdown Duration, it is 280 days right? I think it is actually 280 canldes which means in 5M time frame it is about one day , and because the default of backtesting module is 1Day time frame it calculate each candle as a day. Am I think correctly or not?

    • @CodeTradingCafe
      @CodeTradingCafe  10 місяців тому

      Hi, actually it is in days, and yes it's a lot but the test was on 3 years I think. So the system might work for a year then stop working for a while or so.

  • @muntedme203
    @muntedme203 Рік тому +1

    You are using Ask data only. Impact of Bid price ??? Can be massive. You need to use both bid and offer data for actual trades unless you are buying at market only.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      I agree, this is just to compare indicators performance rather than a full strategy, if you are keen to add spread into this a quick way is to apply a 2/1000 commission rate, it accounts for spread (but not for commissions that are broker dependent). Thank you for your comment! Good luck!

  • @bhumanyusingh6347
    @bhumanyusingh6347 Місяць тому

    i am new to trading and technical analysis. i wanted to understand if this strategy will work better in sideways markets or trending markets? In general, when should we go for scalping and when momentum? which indicators are best to find momentum

    • @CodeTradingCafe
      @CodeTradingCafe  Місяць тому

      Hi, this particular strategy is good for trending markets it catches a good entry point using the bollingers. The rest is a lot more complicated to be discussed in the comment, it depends on your trading personality.

    • @bhumanyusingh6347
      @bhumanyusingh6347 Місяць тому

      @CodeTradingCafe Thanks! Really appreciate you replying.

  • @MrDanZig
    @MrDanZig Рік тому +1

    Wow man! This is gold! How far is this from a trading bot that implements this strategy?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, thank you, I haven't tested the robustness of this strategy yet, I must say it's easy to get lost in the numerous ways one can trade and always trying to choose the best.

  • @AbishaiHuukena
    @AbishaiHuukena 3 місяці тому

    Hello, i have a question. In Forex market, in my case, lotsize is 100000(doesn't matter the money), i have 1:30 leverage i can buy 0.03 of a instrument. How can i transpose those data in my backtesing strategy ? Btw Thanks a lot for your content.

    • @CodeTradingCafe
      @CodeTradingCafe  3 місяці тому

      Hi, thank you for your support. You can use the backtesting package to buy size lot 3000 this 0.03 and when backtesting pass the margin parameter as margin = 1/30 this will run the backtest in your conditions.

  • @loganbishop4619
    @loganbishop4619 Рік тому +1

    So if we are checking the VWAP and STDV, if something is above 2 STDV, then by definition, it is above VWAP. So, why check both? Maybe I am confused about the calculation, but this should be true if STDV is calculated from VWAP. Maybe if it is from regular average, then it could be different. Let me know your thoughts.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, you have a good point! the stdv is computed from the moving average, but also the VWAP is used to test if consecutive candles are above or below the curve, the stdv is used only on the current candle. I hope it's a bit clearer.

  • @zeerar
    @zeerar Рік тому +2

    Thanks

  • @jrm0695
    @jrm0695 Рік тому +2

    Great content thank you ! Could you please provide where do you get the data ? It find it hard to find data at this timeframe

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, thank you for your support, my data is rom yfinance or dukascopy (free data), you can also download from your broker. I will make a video maybe this week showing how to download data, I am getting this question a lot, so probably worth it :)

  • @paulb9842
    @paulb9842 Рік тому +2

    why not implement this in mq4? Performance reasons?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Hi, at the time I moved to Python I was chasing machine learning which Python offered in large libraries with so many shiny choices... and I simply stayed with Python :)

    • @paulb9842
      @paulb9842 Рік тому

      @@CodeTradingCafe do you have a video how convert this to live trading with mt4?

  • @icometofightrocky
    @icometofightrocky 10 місяців тому

    Another good video to give me some new trading ideas ! Instead of using the VWAP maybe you can use the 200 EMA to confirm buying above or selling below, if the price breaks the lower Bollinger Band ?

    • @CodeTradingCafe
      @CodeTradingCafe  10 місяців тому

      Hi, we used the moving average in other videos, this one was for vwap and it wasn't as bad.

  • @Aram-SEMO
    @Aram-SEMO 2 роки тому +2

    Hello, how we can make a strategy only long position that includes the vwap without stop loss and take profit. did i miss the video ?

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Hi, well it's kind of easy simply comment the lines where sell positions are opened and erase the SL TP from the function, but how will you backtest this if it never closes a position

    • @Aram-SEMO
      @Aram-SEMO 2 роки тому +2

      @@CodeTradingCafe To close the position use another indicator, why i don't use SL and TP because after so many tests me and my best friend the 'AI' 😅 we find out that it's not good to use it,
      """ I don't encourage anyone not to use SL and TP, do your own research and testing , good luck 🤗 """,
      i use several vwap z-score indicators and other indicators like sma cross for example to open or close the position I try to do it with the backtest library and I don't have the same result with my back_test script.

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Ah ok I understand, thank you for your reply!

  • @carlamontenegro8carlamonten
    @carlamontenegro8carlamonten Рік тому +1

    Hi, great video, I did not know that backtesting, it is quite intuitive and easy to interpret.
    With CFDs or forex, how would you do the backtesting? because you have ask and bid data, in addition to the spread which is dynamic?
    And this backtesting would support hedging? i.e. if for example I open the position, and 90% of the way I want to move the stop loss to cover profits, that could be done?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Great that you liked these videos. Yes the spread can be included as 2/1000 commission (depending on broker and asset) it's not very dynamic but the approximation is ok. And yes you can apply hedging using backtesting I did it in one of my recent videos on trading the grid system where we buy and sell 2 positions at the same time.

  • @rgodim
    @rgodim Рік тому +1

    Great content, would it be possible to access strategy code? Thank you❤❤😊

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, sure, check the link in the description of the video. Good luck!

  • @jflebas1217
    @jflebas1217 2 роки тому +2

    Could be interesting to try higher tf (Like h1) but smaller periods like 2-3 BBperiod

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Yes it can be tuned this way but vwap is not applicable for higher timeframes so maybe we switch to different indicator.

  • @saisac7357
    @saisac7357 2 роки тому +1

    Sir New video not coming, plzz share a video for Intraday scalp trading,1 min timeframe... Thanks

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Hi, really sorry but working hard all day now I I am waiting for holidays for a new video.

  • @abdulazizshomurodov
    @abdulazizshomurodov Рік тому +1

    WoW🤩

  • @sararhymestvhindi5481
    @sararhymestvhindi5481 Рік тому +1

    Thank you so much for providing the wonderful strategy could you please confirm is it going to work on options trading in any instrument in Indian market

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi thank you for your support, there is only one way to find out ... Backtesting, and it might need some parameters tuning depending on the traded asset. Good luck!

  • @НастяСироткина-з5с
    @НастяСироткина-з5с 2 місяці тому +1

    How do you know which point to buy or sell?

    • @CodeTradingCafe
      @CodeTradingCafe  2 місяці тому

      When the price dips below or above the bollinger bands

  • @peterwestermann5265
    @peterwestermann5265 Місяць тому

    Thank you so much for sharing, may I ask what is the platform/broker you use to actually go live with these strategies? Aain thank you very much.

    • @CodeTradingCafe
      @CodeTradingCafe  Місяць тому +1

      Hi, usually Oanda, Interactive Brokers or Binance provide good python APIs. I am more used to Oanda's though.

    • @peterwestermann5265
      @peterwestermann5265 Місяць тому

      @@CodeTradingCafe Thank you very much!!

  • @hanspetterfasteng3726
    @hanspetterfasteng3726 2 роки тому +3

    Yes, can it be testede for a longer time than 3 years? Let's say 10? 🙂 I like all your videos and the format. Do not expectet to trade - but the codex is very interesting. Can you consider adding a video about ruining Python code on a demo accout from a broker? Stocks/forex?

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +2

      Hi thank you, at some point yes I will make a demo trading live but I am still tuning strategies...

  • @ricardospinoza4063
    @ricardospinoza4063 Рік тому +1

    Great content!!! I have question. The strategy apply crypto market?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Thank you for your support! yes it works on any chart because it purely technical, but the results might be different, and you definitely have to tweak the parameters.

  • @luisfranco5396
    @luisfranco5396 4 місяці тому +1

    l am getting an error message in line 4615 which is NameError: name 'null' is not defined. Line 4615 is ],
    "y":
    [

    • @CodeTradingCafe
      @CodeTradingCafe  4 місяці тому +1

      it's probably some modifications you applied in the code, mainly to the name of a column or so. It's hard to debug like that.

  • @janvosatka474
    @janvosatka474 Рік тому +1

    Hi nice video, please where could i find classes Strategy, Backtest from backtesting. Thx

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, thank you for your support, the classes are from a package called backtesting py you can install it using pip install backtesting and their web documentation is on git kernc.github.io/backtesting.py/ I hope this helps, Good luck!

  • @leandrogoethals6599
    @leandrogoethals6599 Рік тому +1

    Can u make a video how the execute trades with python via MT4/MT5 ?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, thank you for sharing this, it has been proposed before, I think it's a good idea to link Python and MT4/5 I will add it to my list.

  • @santhosh6700
    @santhosh6700 Місяць тому

    Great video bro, ❤ from 🇮🇳
    Thank you for the effort,
    Suggestion :
    Can you make a video using PyQt and Plotly.
    I mean we can plot the dat using plotly and should render in pyqt window, in this windows we can change meteics like SL, TP, different stock instruments, start data end date and so many other things, so that we dont to change manually and it will very interactive

    • @CodeTradingCafe
      @CodeTradingCafe  Місяць тому

      Thanks for the idea! the issue is that is takes a bit more coding effort for an interactive interface.

  • @mohammedalmontaser1578
    @mohammedalmontaser1578 Рік тому +1

    Thanks for your nice content 👍... can you please tell me which is the best scalping strategy in your opinion and you are personally using ... this will be very appreciated

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      My favorite is using VWAP and wait for the price to bounce on after completed retracement, 5min or 15 min timeframe (I prefer 5 min) but in general I avoid scalping it's tiring for me, I start making mistakes after 1 hour of scalping.

    • @vpx_mbyt7663
      @vpx_mbyt7663 Рік тому

      @@CodeTradingCafe but arent u using this trading bot??

  • @dmitriys4279
    @dmitriys4279 8 місяців тому +1

    thank you bro

    • @CodeTradingCafe
      @CodeTradingCafe  8 місяців тому

      You're welcome! Thank you for your support.

  • @acksonmutoba3420
    @acksonmutoba3420 11 місяців тому

    I read your response that the annual profitability of some of these strategies varies by 8-14%. You mentioned again a concept of instead deploying the algorithm but using it for entry signals which calls for more work. Do you imply the profit percent will be higher if we use these algorithms for entry signals only? if so what would be the approximate return percent if we use these algorithms for signals?

    • @CodeTradingCafe
      @CodeTradingCafe  11 місяців тому

      Hi, yes if you use these algorithms just for signaling, but then you as a human trader validate or reject the entry signal, plus you manage the trade manually you will get better results (around 25% annual, only my estimation other traders might be better and provide 50% or more... not me). So basically the algorithms are only here to do the waiting on your behalf and when the pattern is detected it becomes your job to trade.

  • @lance3401
    @lance3401 Рік тому +1

    If would be good if you add pendind stop and limit positions, but for accounts > $1000, and to close positions just with % can be 1% or 2%, I have a working robot in mql4, but I only looking for best entries not even using SL or TP, so as mentioned just % reached, I've watching many videos from you really great videos, I love to code python as well and to find the best indicators tips and adjustments keep it up thank you.

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi thank you for sharing, yes I agree with you actually I haven't introduced any proper trade management yet in these videos, I will get something ready showing the different ways of closing a trade, your percentage idea is also a good one! Good luck!

  • @babubhaigoud
    @babubhaigoud 2 місяці тому

    This is amazing video. Can we use this strategy for Stock and index future?

    • @CodeTradingCafe
      @CodeTradingCafe  2 місяці тому

      Definitely yes, as long as you rely on technicals it's all the same, but of course the strategy parameters have to be adjusted to the assets

  • @pobchubbington6759
    @pobchubbington6759 8 місяців тому +1

    In a strategy ive back tested ive managed to get 3.14 sharpe ratio, i heard if its too high youd need to be careful? My startegy is High frequency trades so the commission is rediculous when i factor it in... Which reduces the sharpe ratio quite alot - how can I reduce commission costs?

    • @CodeTradingCafe
      @CodeTradingCafe  8 місяців тому +1

      You can check if your broker has low commission accounts, or look for a different broker for this. Some brokers offer no commission trading as long as you don't leave trades opened overnight. But spread will always be there.

    • @pobchubbington6759
      @pobchubbington6759 8 місяців тому +1

      @@CodeTradingCafe Ou very nice to know! - Which brokers are commisionless? And allow you to integrate trading algorithms into their broker.

    • @CodeTradingCafe
      @CodeTradingCafe  8 місяців тому +1

      It depends where you are located, different places have different rules for brokers, I know in the Middle East for example CFI have no overnight commissions on Forex, just an example, Oanda have different types of accounts with different fees but come need a minimum deposit amount.

    • @pobchubbington6759
      @pobchubbington6759 7 місяців тому

      @@CodeTradingCafe im based in UK, which zero commission broker could i use? Im excited to test out the algorithm in live trading!

    • @pobchubbington6759
      @pobchubbington6759 7 місяців тому

      @@CodeTradingCafe?

  • @andreagiunta168
    @andreagiunta168 Рік тому +1

    hi there. I would like use Bollinger Bands and consider "lenght" and "stdev" as variables to be used within the optimization function. have you got some solving answer?!??!?! pllsssssss

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      It's relatively simple but the problem you will have to deal with the names of the Bollinger columns created by pandas_ta for each set of parameter. Other than that putting everything into functions and calling an arching function to execute all the files can work well.

  • @БарбосМолокосос
    @БарбосМолокосос 2 роки тому +1

    Great video... I'll test it.... There is one question: Can I somehow learn more about signal sorting ??

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Hi thank you for your comment, I am not sure I understand what you mean by signal sorting.

    • @БарбосМолокосос
      @БарбосМолокосос 2 роки тому +1

      @@CodeTradingCafe I reviewed the video carefully... The question is removed... I was a little mistaken..

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Glad you worked it out, good luck!

  • @jefferystartm9442
    @jefferystartm9442 4 місяці тому +1

    😮 bro , adopt me - my papers are ready

  • @Yoncir
    @Yoncir 2 роки тому +1

    Good morning, greetings from Venezuela. I'm starting to watch your videos and they are phenomenal... what does this code work with thanks for the support

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Hi thank you for your comment, this is python notebooks so you need jupyter notebook installed, try installing anaconda (see my very first video of this channel)

    • @Yoncir
      @Yoncir 2 роки тому +1

      @@CodeTradingCafe great bro, you just gained a subscriber and python student. where I enter the broker's data to do the tests, thank you very much. Greetings from Venezuela

  • @thinketh2408
    @thinketh2408 2 роки тому +2

    Wow thanks...

  • @thinketh2408
    @thinketh2408 2 роки тому +2

    sir where can i to find historic candlestick data ?

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +1

      Hi, dukascopy or yfinance provide data

    • @thinketh2408
      @thinketh2408 2 роки тому +2

      @@CodeTradingCafe thanks... Sir for forex stocks and crypto what work best with algos...
      Kindly share your experience...

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому +2

      @@thinketh2408 support resistance and engulfing candles ... and trend is your friend

    • @thinketh2408
      @thinketh2408 2 роки тому +2

      @@CodeTradingCafe thanks man taking time to reply our comments...
      Waiting for next video..

  • @norimanghazi2782
    @norimanghazi2782 2 роки тому +1

    Hi,
    Is there a possible to consider commission's fee for Trading bot? For example 2% or 0.1% because some of the Broker's have Commission's fee and It's very important to consider this fee.
    It's a great concept.
    I would like to see in future how to connect this bot to Broker's platform with API.
    Thanks,

    • @CodeTradingCafe
      @CodeTradingCafe  2 роки тому

      Sure it's possible to add fees, backtesting library can do this but I don't know how it's counting fees in the background, or we can do it manually as well. Connection with the broker... I have to make a new video about it, in the meantime check this one ua-cam.com/video/e1Ut4Iap10M/v-deo.html

  • @AlvaroBozo-s5g
    @AlvaroBozo-s5g Рік тому +1

    excellent work, where did you get the data?

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому +1

      Hi thank you, yfinance or dukascopy both provide data.

  • @jaafarjrm5160
    @jaafarjrm5160 Рік тому +1

    Thapnk you about all info how can i use this code on live account apfter i download it

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      You will have to modify the code to connect to your broker's API, this shown how in this video: ua-cam.com/video/WcfKaZL4vpA/v-deo.html

    • @jaafarjrm5160
      @jaafarjrm5160 Рік тому

      @@CodeTradingCafe can I make it work as expert advisor on mt5

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, you will have to translate into mql5 language.

  • @ikiyytours2320
    @ikiyytours2320 Рік тому +1

    Very nice.... can I use it in mt5

    • @CodeTradingCafe
      @CodeTradingCafe  Рік тому

      Hi, thank you! The language I am using is python so the code as is will not work in MT5 you will need to translate into mql5.

    • @ikiyytours2320
      @ikiyytours2320 Рік тому

      Thanks bruh....