How To Calculate Technical Indicators For Trading Using Pandas

  Рет қаралды 20,470

CodeTrading

CodeTrading

Күн бұрын

Пікірлер: 138
@pethiraj
@pethiraj Жыл бұрын
I had trouble finding a simple function for calculating and saving the slope in a dataframe. I couldn't find any clear examples or explanations anywhere. Your video on this topic was amazing and incredibly informative. Thank you so much for your valuable service and the effort you put into sharing knowledge. Your dedication is truly commendable.
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
Thank you so much for your support! it really makes a difference to know that these videos are helpful, good luck!
@direnbulut1318
@direnbulut1318 2 жыл бұрын
Thank you very much. If someone has same issue then i had: If Volume is written with capital letter, then u need to change it in second section
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Thank you for sharing
@nackyding
@nackyding 2 жыл бұрын
The way you define your target/label is nice.
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Thank you, it works for some strategies however might not be the best way for scalping for example.
@CristianoLanni
@CristianoLanni 2 жыл бұрын
Hi! very nice video! I was wondering why you don't use close[line] instead of open[line+1] when you compute value1 and value2 in the mytarget function. Congrats for your videos!
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hi thanks a lot for your support, in fact it's almost the same I was simply imagining myself trying to trade after the closing price happened, so at the open of the next candle. Sometimes you might have a closing price different then the next open. But yes in other programs I did use the closing price.
@harsh2656
@harsh2656 2 жыл бұрын
Just came across your channel great content Thank you!! Would love to see pattern screeners like double top/bottom/ Rectangle box breakout/ volatility contraction pattern in future
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hello, thank you for your comment, actually this was proposed many times now I think I should be considering it although might be a bit challenging. See you around 🙂
@danch_ranch6594
@danch_ranch6594 Жыл бұрын
Hey, great video! I am confused with the interpretation of the "Using RSI alone as indicator part". Do we see the signals indicated from the RSI alone? What about when we were not using RSI alone. Did we see a combination of all the indicators creating a signal? Help me out with whats going on under the deck please!
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
Hi thank you for your comment. In brief no RSI is not enough alone, I would suggest checking my recent videos for more interesting strategies and full backtests.
@Alloverthegolf
@Alloverthegolf Жыл бұрын
Perfectly done! Amazingly usefull!
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
Thank you for your support!
@MartinPleasant-ty1rw
@MartinPleasant-ty1rw 6 ай бұрын
Very helpful and interesting info! Definitely needs a second watch to follow along :)
@CodeTradingCafe
@CodeTradingCafe 6 ай бұрын
Glad you enjoyed it!
@AlgoTradingX
@AlgoTradingX 3 жыл бұрын
That's cool, KZbin randomly proposed me your content and I like it. Did you think of using a classification algorithm? It might help to boost your performance
@CodeTradingCafe
@CodeTradingCafe 3 жыл бұрын
Hi, thank you for your comment, actually I tried Xgboost classifier in one of the videos it was not bad, so you are right, however I didn't realize that it's too many information to show in one video so it's lost somewhere on my channel :)
@AlgoTradingX
@AlgoTradingX 3 жыл бұрын
@@CodeTradingCafe Fully understand, same on my channel, I am struggling to compress everything in one video. It is nice meeting fellow Algo traders programmers.
@CodeTradingCafe
@CodeTradingCafe 3 жыл бұрын
I will follow your work, seems similar with new ideas. Good luck to you!
@AlgoTradingX
@AlgoTradingX 3 жыл бұрын
@@CodeTradingCafe Thanks you too. We should make a collab in the future. Good luck for your channel
@CodeTradingCafe
@CodeTradingCafe 3 жыл бұрын
Sure why not... When we grow ,😁
@IceTea0Infinity
@IceTea0Infinity 6 ай бұрын
I love how you speak like George St. Pierre
@CodeTradingCafe
@CodeTradingCafe 6 ай бұрын
Haha, thank you, this was one of my early videos I was still not sure how to speak in front of a mic :)
@aidakhalil1394
@aidakhalil1394 2 жыл бұрын
Very nice Dr👍
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Thanks a lot
@MyStarPeopleExperiences
@MyStarPeopleExperiences 2 жыл бұрын
Made it up to 3:23. Now I cannot get the downloaded data to work with the Jupiter notebook. Anyone have any suggestions? Thanks. The .csv file is in my download folder. I assume it must be in an Anaconda folder, but there are many. Any idea which one the .csv should be placed in?
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hi the csv file should be in the same folder as your jupyter code file, or you can insert the path in double quotes
@zhangmr7955
@zhangmr7955 2 жыл бұрын
I have the same problem, there just found the ipyd file but no csv file
@streamcutthemoffbyswaygo
@streamcutthemoffbyswaygo 2 ай бұрын
at 7:20, what is the other applied function behind get_slope?
@CodeTradingCafe
@CodeTradingCafe 2 ай бұрын
Hi, you can download the jupyter notebook file from the link in the description, the code is there (I honestly don't remember what was after the function :) )
@streamcutthemoffbyswaygo
@streamcutthemoffbyswaygo 2 ай бұрын
@@CodeTradingCafe Hi, thank you so much! - MASSIVE help! :)
@IceTea0Infinity
@IceTea0Infinity 6 ай бұрын
I dot have problems with this part: #mytarget(barsfront to take into account, dataframe) df['mytarget'] = mytarget(16, df) df.head(). What should i do with that? Do i need to compute that? Do i have to replace df with anything?
@CodeTradingCafe
@CodeTradingCafe 5 ай бұрын
df.head() is just to print the first few lines of the dataframe to verify the content visually.
@sergiobarbosa9039
@sergiobarbosa9039 5 ай бұрын
@@CodeTradingCafe hi. im having a keyerror: 'high' when i run this part of the code. Can you help please?
@CodeTradingCafe
@CodeTradingCafe 5 ай бұрын
Check if it's high or High capital H it looks like pandas can't find the column high
@ridergami6821
@ridergami6821 8 ай бұрын
Tq. Python file still available for download even videos 2 years old
@CodeTradingCafe
@CodeTradingCafe 8 ай бұрын
Thank you for your support.
@md21ky38
@md21ky38 2 жыл бұрын
waiting on that ichimoku video ! :)
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Lol don't put pressure on me 😂 I got distracted by recurrent neural networks testing it was a pain... Video coming then ichimoku strategies definitely
@autarko
@autarko 2 жыл бұрын
I am enjoying your content but I have a suggestion for the future: Dukascopy may not be the best data source for learning. They require registration with email and phone number.
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hi, thank you for your feedback yes they require a registration (I guess no phone number don't remember to be honest) I understand it's cumbersome. Yfinance is easier in this case you can directly use it from within python, I will make a video about it.
@autarko
@autarko 2 жыл бұрын
@@CodeTradingCafeI'm looking forward to working through more of your videos!
@autarko
@autarko 2 жыл бұрын
Another suggestion, if you have time: it would be helpful if we could copy the code or notebook from github :)
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
@@autarko I will look into it maybe create an account, but can't promise when ... life keeps getting in the way 🙂
@zhangmr7955
@zhangmr7955 2 жыл бұрын
I've downloaded the historical data from Dukascopy but I have no idea where is the file position it stored. Generally, the downloaded file will go where?
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
try the csv file here drive.google.com/file/d/16BZc9arwQKkPTDU5IjUKrPj54Xif5jtd/view?usp=sharing let me know if it works
@HarpreetSingh-ps9rx
@HarpreetSingh-ps9rx 2 жыл бұрын
During 7th minute of the code, you don't scroll to the left so I can't see the code where you put the get slope function
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Yes I wasn't aware I am out of the recorded area. You can download the code from the link in the description of the video.
@mr.gk5
@mr.gk5 2 жыл бұрын
Would be great if you could make a video showing the probability distribution graphs of each indicator mentioned
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hi thank you for sharing, it's possible however what exactly is to be shown? Like the indicator has a distribution of which values it can take over the time but that doesn't provide a hint on future price
@mr.gk5
@mr.gk5 2 жыл бұрын
@@CodeTradingCafe I think it's just nice to know how well each indicator works on different stocks or asset classes
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
@@mr.gk5 I understand your point, to give a plain honest answer NONE of the indicators gives any statistically relevant hint on future trend Unfortunately. Sometimes combined technical indicators work better but still nothing that reads the future. I should make a video on this but no one likes such deceiving results...
@mr.gk5
@mr.gk5 2 жыл бұрын
@@CodeTradingCafe Well, hoping an indicator or any combination of indicators give a hint to future price is a little too ambitious anyway. But say an indicator with a 47% chance is still better than one with 30% chance on any given stock, right?
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
@@mr.gk5 Hi, yes true like a relative comparison between different indicators, I suspect they will all converge to 50/50 probabilities, but there's only one way to find out 🙂
@blasdelezo8396
@blasdelezo8396 Жыл бұрын
The csv data file is missing
@cesarecorrado7226
@cesarecorrado7226 Жыл бұрын
Does rescaling the features have any effect?
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
Hey, depending on the ML algorithm you will be using, anything based on decision trees is not affected by rescaling, but neural networks yes they need rescaling.
@jcoal_YT
@jcoal_YT Жыл бұрын
hey i am having trouble with the code df['MA40'] = df.ta.sma(length=40), i saw you gave a solution on a comment below on to fix it, but i didn't understand. Instead i decided to download the code. But it opened with visual studio code even though i was using anaconda jupyter notebook. Will the code still work properly on VSC? I am completely new to coding but very familiar with forex so i have no idea what I'm doing. How will i add the bot on mt4?
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
Hi yes the code will work in Vscode I sometimes use VSC as well. you can add these directly in mt4 because mql5 is a different language, but it's possible to translate from python to mql. Good luck!
@santrix1595
@santrix1595 Жыл бұрын
how can you check 2 features or indicators on the last part, how you can add more on the statement?
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
Hi, I usually combine features in the pandas dataframe it's the easiest way just to have the combined signal within the dataframe for later use.
@santievangelio4251
@santievangelio4251 2 жыл бұрын
the midprice line gives me an error
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hi, sorry it's hard to guess where exactly the error is coming from, however try to take the absolute difference between open and close prices and divide by 2, it should work when done manually
@webeasesolutions
@webeasesolutions Жыл бұрын
Man. I've been trying to figure this out for hours lol. I'm going to bed.
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
It might take some time, but it's fun 🙂
@jasonwells8321
@jasonwells8321 2 жыл бұрын
I get this error when I try to indexZeros
@jasonwells8321
@jasonwells8321 2 жыл бұрын
#Check if any zero volumes are available indexZeros = df[ df['volume'] == 0 ].index KeyError Traceback (most recent call last) ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 3360 try: -> 3361 return self._engine.get_loc(casted_key) 3362 except KeyError as err: ~\anaconda3\lib\site-packages\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() ~\anaconda3\lib\site-packages\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hi, not sure I understand which error
@jasonwells8321
@jasonwells8321 2 жыл бұрын
@@CodeTradingCafe I input this line of code #Check if any zero volumes are available indexZeros = df[ df['volume'] == 0 ].index
@jasonwells8321
@jasonwells8321 2 жыл бұрын
@@CodeTradingCafe and I get all those errors.
@Cryptosooner
@Cryptosooner Жыл бұрын
@@jasonwells8321 @CodeTrading I am getting the same error.
@webeasesolutions
@webeasesolutions Жыл бұрын
I'm very confused where this code reading the .csv file from. I can't find the .csv file anywhere and I don't understand how to replace this file with my own .csv file for updated information. Can you please help explain? Or can anyone else please explain? I feel like it's something simple, but this is all brand new to me. I watched your begginer Python videos, but I didn't learn this. I'd love if you could explain everything a bit more. Overall, I appreciate your videos. This is amazing. Thanks. I just want to get to the point where I can run this code and it starts trading automatically for me, either paper or live trades. import pandas as pd df = pd.read_csv("USDCHF_Candlestick_4_Hour_ASK_05.05.2003-19.10.2019.csv") df.tail()
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
Hi thank you. There CSV file is read from the same folder where we have our code notebook. So if you want to replace it with a new fly you can copy your fine inside the same folder where your Python file exists. It's good you started running through tutorials it will take time but it's fun after all. 🙂 Good luck!
@loganbishop4619
@loganbishop4619 10 ай бұрын
I dont understand max(0,open-high). Maybe i am reading this wrong, but this will always be 0
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Hi, no actually it provides the maximum between 0 and the open-high values, so if this latter is negative we get 0, this way we always have positive values.
@trocchiettoski
@trocchiettoski 7 ай бұрын
would be nice to know how to apply this strategy to a stock using a percentage with a 2 win loss ratio, because pips would not make sense for stocks
@CodeTradingCafe
@CodeTradingCafe 7 ай бұрын
it's possible we just need to scale from pips to the broker's unit of price
@XinhLe
@XinhLe 2 жыл бұрын
Please check, the df.ta.sma function is not working. It reports errors for me. for me: the df.ta.sma(length=40) generates a data frame, not a column of data as expected. that's why I have error. how can I fix this. Thanks!
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hi, depends which version of pandas_ta you have, try the following function ta.sma(data=df,...) Or something like that
@XinhLe
@XinhLe 2 жыл бұрын
@@CodeTradingCafe appreciated!
@corneliusluka3555
@corneliusluka3555 11 ай бұрын
Can you do tutorial on reversal, thank you very much
@CodeTradingCafe
@CodeTradingCafe 10 ай бұрын
Hi, reversal is a wide topic, do you have anything specific in mind? check this video for example: kzbin.info/www/bejne/aILCooujg8imkNk
@talsabiri
@talsabiri 3 жыл бұрын
this is so advanced 😅
@CodeTradingCafe
@CodeTradingCafe 3 жыл бұрын
Sorry about that, actually you are right I have to do something more affordable, I guess something like an algorithmic trading in Python playlist for beginners (thank you for the idea 😁)
@CodeTradingCafe
@CodeTradingCafe 3 жыл бұрын
... actually sometimes you can skip The coding part and just check the results to see if it's worth the pain Good luck
@eurisko7119
@eurisko7119 2 жыл бұрын
@@CodeTradingCafe that's will be very useful look forward new subscriber
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
@@eurisko7119 thank you for your support 😊
@itstandart
@itstandart 3 жыл бұрын
hi, for midprice is required set up high and low parameters, tell me please which value i should take?
@CodeTradingCafe
@CodeTradingCafe 3 жыл бұрын
Midprice is usually the open plus closing price all divided by 2, it gives a rough estimation
@itstandart
@itstandart 3 жыл бұрын
I mean that the code gives an exception bad_parameters on midprice
@CodeTradingCafe
@CodeTradingCafe 3 жыл бұрын
@@itstandart I tried to reproduce the error, all is working fine at mine, where exactly did you get this message at which part of the code?
@ajaniwalker9435
@ajaniwalker9435 2 жыл бұрын
@@CodeTradingCafe I had the same thing happen to me. I'm at the part where I am typing df['MA40'] = df.ta.sma(length=40) df['MA80'] = df.ta.sma(length=80) df['MA160'] = df.ta.sma(length=160) I get the error: ValueError: Wrong number of items passed 10, placement implies 1 I don't understand why this would be a problem since the length 40 is a good argument to pass into it
@ajaniwalker9435
@ajaniwalker9435 2 жыл бұрын
@@CodeTradingCafe also, I didn't see what all to apply in the part after the backrollingN was defined
@zhangmr7955
@zhangmr7955 2 жыл бұрын
I cannot find the file : USDCHF_Candlestick_4_Hour_ASK_05.05.2003-19.10.2019.csv
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Hi, it's downloadable from different sources if you have time check my learning python playlist there is a video especially focused on data download directly from the notebook.
@zhangmr7955
@zhangmr7955 2 жыл бұрын
@@CodeTradingCafe You mean the "Python Learning" Series?
@zhangmr7955
@zhangmr7955 2 жыл бұрын
@@CodeTradingCafe I know Python, I know how to download the csv file. But the file of USDCHF_Candlestick_4_Hour_ASK_05.05.2003-19.10.2019.csv not found from your provided files. And I downloaded it from Dukascopy directly, but there is no clue where the downloaded file is. So I need your help, Generally the files downloaded from Dukascopy will enter which file on local desktop.
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
@@zhangmr7955 ah ok I see, usually when the download is done you still have the option to click save as and the file is saved under downloads... actually give me few minutes I will add a link to the video
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
try this csv file: drive.google.com/file/d/16BZc9arwQKkPTDU5IjUKrPj54Xif5jtd/view?usp=sharing
@kevinnjoroge3273
@kevinnjoroge3273 2 жыл бұрын
Thank you so much for the amazing content but am having an issue with data cleaning though...There is an error where it says df is not defined and everything seems right.
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
Thank you for your comment, if you are using jupyter notebook you have to run the cells in order, meaning you might have forgotten to run the first cell where df is defined for example, check it out
@kevinnjoroge3273
@kevinnjoroge3273 2 жыл бұрын
@@CodeTradingCafe Thank You .It had completely slipped my mind...🤦‍♂
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
I am happy it worked
@kevinnjoroge3273
@kevinnjoroge3273 2 жыл бұрын
@@CodeTradingCafe Hey again..I am unfortunately getting another error Input In [106], in () 1 # mytarget(barsfront to take into account, dataframe) ----> 2 df['mytarget'] = mytarget(16 , df) 3 df.tail() This is a copy of the error am getting when takin into account the bars up front for our target.
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
@@kevinnjoroge3273 what's the last line of the error message
@philomenantonybenhur6780
@philomenantonybenhur6780 2 жыл бұрын
Thank you so much for this video. I am trying to follow your code and execute the same, but I am getting an error from pandas ta for on calculating the average column 'df['Average'] = df.ta.midprice(length=1) #midprice'. The error message is 'Exception: TA_MIDPRICE function failed with error code 2: Bad Parameter (TA_BAD_PARAM)'. Could you please let me know how to fix this. Thank You once again.
@CodeTradingCafe
@CodeTradingCafe 2 жыл бұрын
To be honest others have signaled the same error but I can't reproduce it at mine it's working well. Instead of using midprice just replace by the closing price with little tweaks it should be fine hopefully. You'll find less errors in the more recent videos 🙂
@philomenantonybenhur6780
@philomenantonybenhur6780 2 жыл бұрын
@@CodeTradingCafe Thank You, will follow the same..
@santrix1595
@santrix1595 Жыл бұрын
@@CodeTradingCafe The error you are getting is because the new update they did on pandas_ta requires the length on midprince to be null, if you delete that and leave it on blank the issue will dissapear.
@CodeTradingCafe
@CodeTradingCafe Жыл бұрын
@@santrix1595 thank you for the update, I haven't visited this part of the code since a while
Technical Indicators Comparison Using Machine Learning In Python
14:42
How do Cats Eat Watermelon? 🍉
00:21
One More
Рет қаралды 8 МЛН
Cute
00:16
Oyuncak Avı
Рет қаралды 12 МЛН
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 66 МЛН
Moving Average for Python in 6 mins
6:59
James Cutajar
Рет қаралды 8 М.
Generative AI in a Nutshell - how to survive and thrive in the age of AI
17:57
Exploratory Data Analysis with Pandas Python
40:22
Rob Mulla
Рет қаралды 475 М.
Moving Average Trading Strategy Backtesting In Python
16:16
CodeTrading
Рет қаралды 9 М.
Reinforcement Learning, by the Book
18:19
Mutual Information
Рет қаралды 95 М.
How do Cats Eat Watermelon? 🍉
00:21
One More
Рет қаралды 8 МЛН