{"id":3720,"date":"2023-11-22T14:04:53","date_gmt":"2023-11-22T14:04:53","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=3720"},"modified":"2025-02-05T12:54:03","modified_gmt":"2025-02-05T12:54:03","slug":"implementing-a-candlestick-momentum-strategy-in-python","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python","title":{"rendered":"Implementing a Candlestick Momentum Strategy in Python"},"content":{"rendered":"\n<p>Trading with the help of candlestick charts is a very traditional yet effective way of trading assets. As it gained popularity in the trading arena, day traders started developing and using a wide array of strategies that used the candlestick charts at its core.<\/p>\n\n\n\n<p>In this article, we are going to build one such momentum trading strategy with the help of candlesticks and backtest the strategy on Tesla stock in Python. Though it is possible to construct very complex strategies using candlesticks, we will be keeping our momentum strategy as simple as possible for the sake of understandability. With that said, let&#8217;s dive into the article.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Importing Packages<\/strong><\/h2>\n\n\n\n<p>Importing the required packages into the Python environment is a non-skippable step. The primary packages are going to be eodhd for extracting historical stock data, and Pandas for data formatting and manipulations. The secondary packages are going to be Math for mathematical functions and Termcolor for font customization (optional).<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\"># IMPORTING PACKAGES\n\nimport pandas as pd\nfrom eodhd import APIClient\nfrom termcolor import colored as cl\nimport math<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>With the required packages imported into Python, we can proceed to fetch historical data for Tesla using EODHD&#8217;s eodhd Python library. Also, if you haven\u2019t installed any of the imported packages, make sure to do so using the&nbsp;pip&nbsp;command in your terminal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a9f4\"><strong>API Key Activation<\/strong><\/h2>\n\n\n\n<p id=\"c710\">It is essential to register the EODHD API key with the package in order to use its functions. If you don\u2019t have an EODHD API key, firstly, head over to their&nbsp;<a href=\"https:\/\/eodhd.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">website<\/a>, then, finish the&nbsp;<a href=\"https:\/\/eodhd.com\/register\" target=\"_blank\" rel=\"noreferrer noopener\">registration<\/a>&nbsp;process to create an EODHD account, and finally, navigate to the \u2018<a href=\"https:\/\/eodhd.com\/cp\/settings\" target=\"_blank\" rel=\"noreferrer noopener\">Settings<\/a>\u2019 page where you could find your secret EODHD API key. It is important to ensure that this secret API key is not revealed to anyone. You can activate the API key by following this code:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\"># API KEY ACTIVATION\n\napi_key = '&lt;YOUR API KEY&gt;'\nclient = APIClient(api_key)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p id=\"fd3d\">The code is pretty simple. In the first line, we are storing the secret EODHD API key into the&nbsp;api_key&nbsp;and then in the second line, we are using the&nbsp;APIClient&nbsp;class provided by the&nbsp;eodhd&nbsp;package to activate the API key and stored the response in the&nbsp;client&nbsp;variable.<\/p>\n\n\n\n<p id=\"4634\">Note that you need to replace&nbsp;&lt;YOUR API KEY&gt;&nbsp;with your secret EODHD API key. Apart from directly storing the API key with text, there are other ways for better security such as utilizing environmental variables, and so on.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8568\"><strong>Extracting Historical Data<\/strong><\/h2>\n\n\n\n<p id=\"ac40\">Before heading into the extraction part, it is first essential to have some background about historical or end-of-day data. In a nutshell, historical data consists of information accumulated over a period of time. It helps in identifying patterns and trends in the data. It also assists in studying market behavior. Now, you can easily extract the historical data of Tesla using the&nbsp;eodhd&nbsp;package by following this code:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\"># EXTRACTING HISTORICAL DATA\n\ntsla = client.get_historical_data('TSLA', 'd', '2023-05-01', '2023-11-01').drop(['symbol','interval','close'], axis = 1)\ntsla.index = pd.to_datetime(tsla.index)\ntsla = tsla.rename(columns = {'adjusted_close':'close'})\n\ntsla.tail()<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>The code used here is pretty straightforward. First, we are using the get_historical_data function provided by the eodhd package. This function takes the stock&#8217;s symbol, the time interval between the data points, and the starting and ending date of the dataframe. After that, we are performing some data manipulation processes to format and clean the extracted historical data. Here&#8217;s the final dataframe:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\" id=\"AAPL_Historical_Dataframe\"><img loading=\"lazy\" decoding=\"async\" width=\"1618\" height=\"585\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/AAPL_Historical_Dataframe.png\" alt=\"\" class=\"wp-image-4265\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Backtesting the Candlestick Momentum Strategy<\/strong><\/h2>\n\n\n\n<p>Before actually coding the strategy, it&#8217;s essential to have some background on the candlestick momentum strategy that we&#8217;re going to build. Here&#8217;s an explanation of the logic of the strategy in a simplified way:<\/p>\n\n\n\n<p>We enter the market if: The closing price of the current candle is greater than the highest price of the previous three candles.<\/p>\n\n\n\n<p>We exit the market if: The closing price of the current candle is less than the lowest price of the previous three candles.<\/p>\n\n\n\n<p>As I mentioned before, this is a very simple momentum-based strategy and the following code backtests this strategy on the extracted historical data of Tesla:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\"># CREATING THE STRATEGY\n\ndef implement_strategy(df, investment):\n    \n    in_position = False\n    equity = investment\n    \n    for i in range(3, len(df)):\n        if df['close'][i] &gt; df['high'][i-3] and df['close'][i] &gt; df['high'][i-2] and df['close'][i] &gt; df['high'][i-1] and in_position == False:\n            no_of_shares = math.floor(equity\/df.close[i])\n            equity -= (no_of_shares * df.close[i])\n            in_position = True\n            print(cl('BUY: ', color = 'green', attrs = ['bold']), f'{no_of_shares} Shares are bought at ${df.close[i]} on {str(df.index[i])[:10]}')\n        elif df['close'][i] &lt; df['low'][i-3] and df['close'][i] &lt; df['low'][i-2] and df['close'][i] &lt; df['low'][i-1] and in_position == True:\n            equity += (no_of_shares * df.close[i])\n            in_position = False\n            print(cl('SELL: ', color = 'red', attrs = ['bold']), f'{no_of_shares} Shares are bought at ${df.close[i]} on {str(df.index[i])[:10]}')\n    if in_position == True:\n        equity += (no_of_shares * df.close[i])\n        print(cl(f'\\nClosing position at {df.close[i]} on {str(df.index[i])[:10]}', attrs = ['bold']))\n        in_position = False\n\n    earning = round(equity - investment, 2)\n    roi = round(earning \/ investment * 100, 2)\n    print(cl(f'EARNING: ${earning} ; ROI: {roi}%', attrs = ['bold']))\n    \nimplement_strategy(tsla, 100000)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>This code is heavily inspired by the backtesting code written by&nbsp;<a href=\"https:\/\/medium.com\/u\/1a7b4287ab33?source=post_page-----6930bb344856--------------------------------\" target=\"_blank\" rel=\"noreferrer noopener\">Yong Hong Tan<\/a>&nbsp;in his article about the SuperTrend indicator. A shoutout to him for this amazing code. The backtesting results are pretty interesting and these are the trades executed by the program:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\" id=\"Backtesting_Results_1d\"><img loading=\"lazy\" decoding=\"async\" width=\"1057\" height=\"569\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/Backtesting_Results_1d.png\" alt=\"\" class=\"wp-image-4266\"\/><\/figure>\n\n\n\n<p>It can be observed that the program has made around 12 transactions within a timespan of 6 months which is totally fine. At the end of the specified backtesting timeframe, our strategy has made approximately $48K with an ROI of 48%. That&#8217;s great!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Testing the Candlestick Momentum Strategy on Different Timeframes<\/strong><\/h2>\n\n\n\n<p>This is an optional step for validating the strategy&#8217;s performance and check its suitability for different timeframes. Let&#8217;s start off with backtesting the strategy on Tesla&#8217;s 1h intraday data.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">tsla_1h = client.get_historical_data('TSLA', '1h', '2023-10-15', '2023-11-01').drop(['symbol','interval','gmtoffset','epoch'], axis = 1)\ntsla_1h.index = pd.to_datetime(tsla_1h.index)\n\nimplement_strategy(tsla_1h, 100000)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>In the above code, we&#8217;re first using the get_historical_data function to extract the 1h intraday data of Tesla. To backtest the strategy on this data, we&#8217;re using the implement_strategy function which we defined earlier to conduct backtest on the 1-day historical. These are the backtesting results on 1h intraday data of Tesla:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\" id=\"Backtesting_Results_1h\"><img loading=\"lazy\" decoding=\"async\" width=\"1429\" height=\"664\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/Backtesting_Results_1h.png\" alt=\"\" class=\"wp-image-4267\"\/><\/figure>\n\n\n\n<p>The results are pretty contrasting to those of the 1-day historical data where we had an ROI of 48%, whereas here, we are facing a loss $7.3K. For further insights, let&#8217;s try backtesting the same strategy on 5-mins intraday data of Tesla.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">tsla_5m = client.get_historical_data('TSLA', '5m', '2023-10-27', '2023-11-01').drop(['symbol','interval','gmtoffset','epoch'], axis = 1)\ntsla_5m.index = pd.to_datetime(tsla_5m.index)\n\nimplement_strategy(tsla_5m, 100000)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>The code is almost the same as the 1h timeframe except here, we&#8217;re extracting and running the backtest on 5-mins intraday data. Here are the backtesting results:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\" id=\"Backtesting_Results_5m\"><img loading=\"lazy\" decoding=\"async\" width=\"918\" height=\"869\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/Backtesting_Results_5m.png\" alt=\"\" class=\"wp-image-4268\"\/><\/figure>\n\n\n\n<p>As you can see, the strategy has executed a huge number of trades and there is a high chance that a lot of them are executed based on false signals which can be a critical reason behind the loss we faced.<\/p>\n\n\n\n<p>The reason behind backtesting the strategy on different timeframes is to expose the strategy to varied situations and test its performance during those times. From our observations, it is evident that the strategy&#8217;s performance is phenomenal on the 1-day historical data and the results on the 1h and 5-mins data are relatively poor. Thus, it can be confidently said that our momentum strategy is most suitable for swing trading than for day trading.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>In this article, we learned to construct a very simple candlestick momentum strategy. We backtested the strategy on Tesla&#8217;s historical data with timeframes to better evaluate the efficiency of the strategy.<\/p>\n\n\n\n<p>Though we went through an extensive process of coding, there are still a lot of scope for improvements. For example, to make the backtesting results more reliable, transaction costs can be amounted for each trade the program executes. Then, several risk management approaches can be deployed for ensuring safe method of trading. These are some ways to improve the overall framework and there are many more to be explored.<\/p>\n\n\n\n<p>With that said, you&#8217;ve reached the end of the article. Hope you learned something new and useful today. Thank you very much for your time. Happy backtesting!<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A comprehensive study on implementing a candlestick momentum strategy using Python and APIs<\/p>\n","protected":false},"author":18,"featured_media":4274,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[65,1,59,61],"tags":[],"coding-language":[30],"ready-to-go-solution":[56],"qualification":[31,32],"financial-apis-category":[36],"financial-apis-manuals":[39,38],"class_list":["post-3720","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backtesting-strategies-examples","category-fundamental-analysis-examples","category-technical-analysis-examples","category-trading-indicators-implimentations","coding-language-python","ready-to-go-solution-eodhd-python-financial-library","qualification-experienced","qualification-guru","financial-apis-category-stock-market-prices","financial-apis-manuals-end-of-day","financial-apis-manuals-intraday","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.9 (Yoast SEO v26.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Implementing a Candlestick Momentum Strategy in Python | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"A comprehensive study on implementing and backtesting a candlestick momentum strategy using Python and EODHD APIs\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Implementing a Candlestick Momentum Strategy in Python\" \/>\n<meta property=\"og:description\" content=\"Implementation and backtesting of a momentum trading strategy using candlesticks with the help of Python and EODHD API\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python\" \/>\n<meta property=\"og:site_name\" content=\"Financial Academy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/eodhistoricaldata\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-22T14:04:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T12:54:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1125\" \/>\n\t<meta property=\"og:image:height\" content=\"750\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nikhil Adithyan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Implementing a Candlestick Momentum Strategy in Python\" \/>\n<meta name=\"twitter:creator\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:site\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikhil Adithyan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python\"},\"author\":{\"name\":\"Nikhil Adithyan\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402\"},\"headline\":\"Implementing a Candlestick Momentum Strategy in Python\",\"datePublished\":\"2023-11-22T14:04:53+00:00\",\"dateModified\":\"2025-02-05T12:54:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python\"},\"wordCount\":1171,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png\",\"articleSection\":[\"Backtesting Strategies Examples\",\"Fundamental Analysis Examples\",\"Technical Analysis Examples\",\"Trading Indicators Implimentations\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python\",\"name\":\"Implementing a Candlestick Momentum Strategy in Python | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png\",\"datePublished\":\"2023-11-22T14:04:53+00:00\",\"dateModified\":\"2025-02-05T12:54:03+00:00\",\"description\":\"A comprehensive study on implementing and backtesting a candlestick momentum strategy using Python and EODHD APIs\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png\",\"width\":1125,\"height\":750,\"caption\":\"Implementing a Candlestick Momentum Strategy in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Implementing a Candlestick Momentum Strategy in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"name\":\"Financial APIs Academy | EODHD\",\"description\":\"Financial Stock Market Academy\",\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\",\"name\":\"EODHD (EOD Historical Data)\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"width\":159,\"height\":82,\"caption\":\"EODHD (EOD Historical Data)\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/eodhistoricaldata\",\"https:\/\/x.com\/EOD_data\",\"https:\/\/www.reddit.com\/r\/EODHistoricalData\/\",\"https:\/\/eod-historical-data.medium.com\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402\",\"name\":\"Nikhil Adithyan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g\",\"caption\":\"Nikhil Adithyan\"},\"description\":\"Founder at BacktestZone | Streamlit Student Ambassador | FinTech &amp; Quantitative Finance enthusiast\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/nikhiladithyan\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Implementing a Candlestick Momentum Strategy in Python | EODHD APIs Academy","description":"A comprehensive study on implementing and backtesting a candlestick momentum strategy using Python and EODHD APIs","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python","og_locale":"en_US","og_type":"article","og_title":"Implementing a Candlestick Momentum Strategy in Python","og_description":"Implementation and backtesting of a momentum trading strategy using candlesticks with the help of Python and EODHD API","og_url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2023-11-22T14:04:53+00:00","article_modified_time":"2025-02-05T12:54:03+00:00","og_image":[{"width":1125,"height":750,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-2.png","type":"image\/png"}],"author":"Nikhil Adithyan","twitter_card":"summary_large_image","twitter_title":"Implementing a Candlestick Momentum Strategy in Python","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Nikhil Adithyan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python"},"author":{"name":"Nikhil Adithyan","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402"},"headline":"Implementing a Candlestick Momentum Strategy in Python","datePublished":"2023-11-22T14:04:53+00:00","dateModified":"2025-02-05T12:54:03+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python"},"wordCount":1171,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png","articleSection":["Backtesting Strategies Examples","Fundamental Analysis Examples","Technical Analysis Examples","Trading Indicators Implimentations"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python","url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python","name":"Implementing a Candlestick Momentum Strategy in Python | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png","datePublished":"2023-11-22T14:04:53+00:00","dateModified":"2025-02-05T12:54:03+00:00","description":"A comprehensive study on implementing and backtesting a candlestick momentum strategy using Python and EODHD APIs","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png","width":1125,"height":750,"caption":"Implementing a Candlestick Momentum Strategy in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/implementing-a-candlestick-momentum-strategy-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"Implementing a Candlestick Momentum Strategy in Python"}]},{"@type":"WebSite","@id":"https:\/\/eodhd.com\/financial-academy\/#website","url":"https:\/\/eodhd.com\/financial-academy\/","name":"Financial APIs Academy | EODHD","description":"Financial Stock Market Academy","publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/eodhd.com\/financial-academy\/#organization","name":"EODHD (EOD Historical Data)","url":"https:\/\/eodhd.com\/financial-academy\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","width":159,"height":82,"caption":"EODHD (EOD Historical Data)"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/eodhistoricaldata","https:\/\/x.com\/EOD_data","https:\/\/www.reddit.com\/r\/EODHistoricalData\/","https:\/\/eod-historical-data.medium.com\/"]},{"@type":"Person","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402","name":"Nikhil Adithyan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g","caption":"Nikhil Adithyan"},"description":"Founder at BacktestZone | Streamlit Student Ambassador | FinTech &amp; Quantitative Finance enthusiast","url":"https:\/\/eodhd.com\/financial-academy\/author\/nikhiladithyan"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Implementing_a_Candlestick_Momentum_Strategy_in_Python_CoverImage.png","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-Y0","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/3720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=3720"}],"version-history":[{"count":16,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/3720\/revisions"}],"predecessor-version":[{"id":6271,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/3720\/revisions\/6271"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/4274"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=3720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=3720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=3720"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=3720"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=3720"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=3720"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=3720"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=3720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}