{"id":1888,"date":"2023-09-05T20:41:10","date_gmt":"2023-09-05T20:41:10","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=1888"},"modified":"2025-02-05T12:22:06","modified_gmt":"2025-02-05T12:22:06","slug":"sp-500-sma200-trading-strategy","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","title":{"rendered":"S&amp;P 500 &#8211; SMA200 Trading Strategy"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-medium-to-long-term-investing-into-the-s-amp-p-500\">Medium-to-Long term investing into the S&amp;P 500<\/h2>\n\n\n\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-the-s-amp-p-500\">What is the S&amp;P 500?<\/h2>\n\n\n\n<p>The S&amp;P 500 was established in 1957, and is a stock market index that measures the stock performance of 500 large companies listed on stock exchanges in the United States. It is one of the most widely followed equity indices in the world and serves as an indicator and predictor of future trends or events for the U.S. stock market. The significant history of the S&amp;P 500 is valuable for both real-world financial strategies and academic studies allowing for in-depth historical analysis. It is also great for backtesting trading strategies to evaluate how they perform in a variety of different conditions.<\/p>\n\n\n\n<p>The S&amp;P 500 represents approximately 80% of the total market value of the U.S. stock market. As such, it gives a good indication of the overall health and performance of the U.S. equity market. If you are interested in which companies are in the S&amp;P 500, you can find the <a style=\"font-size: 18px\" href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_S%26P_500_companies\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">list of companies<\/a> on Wikipedia. You may notice that there are in fact more than 500 entries in the S&amp;P 500, and that is because some companies have more than one class of share.<\/p>\n\n\n\n<p>The S&amp;P 500 is also useful in that it covers a wide variety of sectors, making it more diversified than indices that track a specific sector. This diversity can provide a broader picture of the economic health across various industries.<\/p>\n\n\n\n<p>The S&amp;P 500 is used as a benchmark by many investment funds and portfolio managers to gauge the relative performance of their investments. When you hear that a fund &#8220;outperformed the S&amp;P 500,&#8221; it means the fund did better than the average return of the 500 stocks in the index over the same period.<\/p>\n\n\n\n<p>Many financial products, such as mutual funds and exchange-traded funds (ETFs), are tied to or based on the S&amp;P 500. This makes it easier for individual investors to invest in a product that mirrors the performance of the broader market.<\/p>\n\n\n\n<p>The wide media coverage of the S&amp;P 500, coupled with the availability of derivative products (like futures and options), makes it popular among traders and investors.<\/p>\n\n\n\n<p>Stocks that are part of the S&amp;P 500 are among the most traded in the world, which means they are highly liquid. This liquidity is attractive to traders and large institutional investors because they can make large transactions without significantly affecting the stock price.<\/p>\n\n\n\n<p>The performance of the S&amp;P 500 is often used as a proxy for the overall U.S. economy&#8217;s health. Rising markets might suggest investor optimism about the economy, while declining markets can indicate pessimism.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-s-amp-p-500-historical-data\">S&amp;P 500 Historical Data<\/h2>\n\n\n\n<p>You are able to obtain the historical data for the S&amp;P 500 from <a style=\"font-size: 18px\" href=\"https:\/\/eodhd.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">EODHD API&#8217;s<\/a>. The <a style=\"font-size: 18px\" href=\"https:\/\/eodhd.com\/financial-apis\" target=\"_blank\" rel=\"noreferrer noopener\">full documentation of their APIs<\/a> can be found on their website. I personally prefer to use their <a href=\"https:\/\/eodhd.com\/financial-apis\/python-financial-libraries-and-code-samples\/#EODHD_APIs_Python_Financial_Library_by_Michael_Whittle\" target=\"_blank\" rel=\"noreferrer noopener\">official Python library<\/a> and it vastly simplifies access to the data.<\/p>\n\n\n\n<p><\/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=\"h-using-the-python-library\">Using the Python library<\/h2>\n\n\n\n<p>The prerequisites for using the Python library is to have Python and PIP installed. There are plenty of guides available online, but I would recommend the <a style=\"font-size: 18px\" href=\"https:\/\/realpython.com\/installing-python\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Real Python<\/a> documentation. If all has gone to plan you should be able to check the Python and PIP versions like this:<\/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\">% <strong>python3 --version<\/strong>       \nPython 3.11.4\n% <strong>pip3 --version<\/strong>          \npip 23.2.1 from \/usr\/local\/lib\/python3.11\/site-packages\/pip (python 3.11)\n% <strong>python3 -m pip --version<\/strong>\npip 23.2.1 from \/usr\/local\/lib\/python3.11\/site-packages\/pip (python 3.11)<\/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>You will also want to install the Python virtual environment (&#8220;venv&#8221;) as follows:<\/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\">% <strong>python3 -m pip install virtualenv<\/strong>\n\n% <strong>python3 -m venv --help <\/strong>  \nusage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps] ENV_DIR [ENV_DIR ...]\n\nCreates virtual Python environments in one or more target directories.<\/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>Presuming you have Python3, PIP3, and venv installed, the next step is to create yourself a working directory and virtual environment. Once that is done you will be able to install the Python library.<\/p>\n\n\n\n<p>% <strong style=\"font-size: 18px\">mkdir EODHD_APIs<\/strong><br>% <strong style=\"font-size: 18px\">cd EODHD_APIs <\/strong><br>EODHD_APIs % <strong style=\"font-size: 18px\">python3 -m venv venv<\/strong><br>EODHD_APIs % <strong style=\"font-size: 18px\">source venv\/bin\/activate<\/strong><br>(venv) EODHD_APIs % <strong style=\"font-size: 18px\">python3 -m pip install eodhd -U<\/strong><br>Collecting eodhd<br>  Downloading eodhd-1.0.21-py3-none-any.whl (25 kB)<br>&lt;snip&gt;<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-quick-test-to-confirm-the-python-library-installed-properly\">Quick test to confirm the Python library installed properly<\/h2>\n\n\n\n<p>In order to confirm the &#8220;<a href=\"https:\/\/eodhd.com\/financial-apis\/python-financial-libraries-and-code-samples\/#EODHD_APIs_Python_Financial_Library_by_Michael_Whittle\" target=\"_blank\" rel=\"noreferrer noopener\">eodhd<\/a>&#8221; Python library has installed correctly, we can run a quick test by creating a Python script and importing the library.<\/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\">from eodhd import APIClient\n\n\ndef main():\n    api = APIClient(\"&lt;Your_API_Key&gt;\")\n    print(isinstance(api, APIClient))\n\n\nif __name__ == \"__main__\":\n    main()<\/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>Running the script will look like this:<\/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\">(venv) EODHD_APIs % <strong style=\"font-size: 18px\">python3 main.py<\/strong> \nTraceback (most recent call last):\n  File \"\/EODHD_APIs\/venv\/lib\/python3.11\/site-packages\/eodhd\/apiclient.py\", line 78, in __init__\n    raise ValueError(\"API key is invalid\")\nValueError: API key is invalid\n(venv) EODHD_APIs %<\/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 error is expected as I didn&#8217;t include my API key from <a style=\"font-size: 18px\" href=\"https:\/\/eodhd.com\/register\" target=\"_blank\" rel=\"noreferrer noopener\">EODHD APIs<\/a>. If you don&#8217;t already have an API key, you will need to register for one.<\/p>\n\n\n\n<p>The main objective of this test is to confirm the library imports and runs without an error, and it does.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-retrieving-the-s-amp-p-500-data\">Retrieving the S&amp;P 500 data<\/h2>\n\n\n\n<p>I want to find the S&amp;P 500 index on <a style=\"font-size: 18px\" href=\"https:\/\/eodhd.com\/register\" target=\"_blank\" rel=\"noreferrer noopener\">EODHD APIs<\/a>, but I can&#8217;t remember the stock code. I&#8217;m going to show you how I located it.<\/p>\n\n\n\n<p>The first step was to find the exchange code for &#8220;London Exchange&#8221;.<\/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\">    df = api.get_exchanges()\n    print(df[df[\"Name\"].str.contains(\"London Exchange\")])\n<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1104\" height=\"60\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-03-at-13.23.28.png\" alt=\"\" class=\"wp-image-1890\"\/><\/figure>\n\n\n\n<p>I can see it&#8217;s &#8220;<strong style=\"font-size: 18px\">LSE<\/strong>&#8220;. I know the index I&#8217;m looking for is an ETF from HSBC.<\/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\">    df = api.get_exchange_symbols(\"LSE\")\n    df = df[df[\"Type\"] == \"ETF\"]\n    df = df[df[\"Name\"].str.contains(\"HSBC\")]\n    df = df[df[\"Name\"].str.contains(\"500\")]\n    print(df)<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1314\" height=\"140\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-03-at-13.25.04.png\" alt=\"\" class=\"wp-image-1891\"\/><\/figure>\n\n\n\n<p>I can see it there, it&#8217;s &#8220;<strong>HSPX<\/strong>&#8220;.<\/p>\n\n\n\n<p>I now want to populate three data frames with Weekly, Daily and Hourly 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\">    df_weekly = api.get_historical_data(symbol=\"HSPX.LSE\", interval=\"w\", iso8601_start=\"2018-01-01\", iso8601_end=\"2023-09-04\")\n    print(df_weekly)<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1300\" height=\"422\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-12.40.15-1.png\" alt=\"\" class=\"wp-image-1901\"\/><\/figure>\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\">    df_daily = api.get_historical_data(symbol=\"HSPX.LSE\", interval=\"d\", iso8601_start=\"2022-01-01\", iso8601_end=\"2023-09-04\")\n    print(df_daily)\n<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1234\" height=\"420\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.09.17.png\" alt=\"\" class=\"wp-image-1906\"\/><\/figure>\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\">    df_hourly = api.get_historical_data(symbol=\"HSPX.LSE\", interval=\"1h\", iso8601_start=\"2023-01-01\", iso8601_end=\"2023-09-04\")\n    print(df_hourly)<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1730\" height=\"418\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-12.47.44.png\" alt=\"\" class=\"wp-image-1902\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-calculating-the-200-interval-simple-moving-averages-sma\">Calculating the 200-interval Simple Moving Averages (SMA)<\/h2>\n\n\n\n<p>It&#8217;s time to introduce the trading strategy&#8230;<\/p>\n\n\n\n<p>What we want to do is calculate the SMA200 for the weekly, daily, and hourly. The first deciding factor is if the SMA200 for the daily is above or below the SMA200 for the weekly. If it&#8217;s above, then the long term trend is up and we want to be trading, and if it&#8217;s below the long term trend is down and we don&#8217;t want to be trading.<\/p>\n\n\n\n<p>Assuming the SMA200 for the daily is above the SMA200 for the weekly, we then want to compare the SMA200 for the daily with the SMA200 for the hourly. If the SMA200 for the hourly crosses above the SMA200 for the daily, that&#8217;s a buy signal. If the SMA200 for the hourly crosses below the SMA200 for the daily, that&#8217;s a sell signal.<\/p>\n\n\n\n<p>Now that we&#8217;ve covered the basics, let&#8217;s create our moving averages for the three datasets.<\/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\">df_weekly[\"Weekly SMA200\"] = df_weekly[\"adjusted_close\"].rolling(200, min_periods=200).mean()\n<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1512\" height=\"416\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.04.06.png\" alt=\"\" class=\"wp-image-1905\"\/><\/figure>\n\n\n\n<p>As you can see we now have a feature called &#8220;Weekly SMA200&#8221; which starts showing the mean of the previous 200 weeks. The NaN means &#8220;Not a Number&#8221; and just means that the first 200 weeks we don&#8217;t have a mean yet.<\/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\">df_daily[\"Daily SMA200\"] = df_daily[\"adjusted_close\"].rolling(200, min_periods=200).mean()\n\ndf_hourly[\"Hourly SMA200\"] = df_hourly[\"close\"].rolling(200, min_periods=200).mean()\n<\/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<h2 class=\"wp-block-heading\" id=\"h-merging-the-daily-and-weekly-datasets\">Merging the Daily and Weekly datasets<\/h2>\n\n\n\n<p>We will now want to start merging the three datasets for comparison. A copy of the daily dataset with the SMA200 will be created and the SMA200 for the weekly will be merged in.<\/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\">    df_weekly_daily = df_daily.copy()\n    df_weekly_daily[\"Weekly SMA200\"] = df_weekly[\"Weekly SMA200\"]\n    print(df_weekly_daily)\n<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1638\" height=\"422\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.13.49.png\" alt=\"\" class=\"wp-image-1908\"\/><\/figure>\n\n\n\n<p>To visualise this we can use the &#8220;plot&#8221; function in Pandas, which uses Matplotlib.<\/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\">import matplotlib.pyplot as plt\n\n    df_plot = df_weekly_daily.dropna().loc[\"2022\":\"2023\", [\"adjusted_close\", \"Daily SMA200\", \"Weekly SMA200\"]]\n    df_plot.rename(columns={\"adjusted_close\": \"Close\"}, inplace=True)\n    print(df_plot)\n    df_plot.plot(title=\"S&amp;P 500 Weekly SMA 200 vs. Daily SMA 200\", kind=\"line\", color=[\"black\", \"green\", \"blue\"], figsize=(36, 12))\n    plt.show()\n\n<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"712\" height=\"1320\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.20.53.png\" alt=\"\" class=\"wp-image-1909\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"4574\" height=\"1808\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.21.32.png\" alt=\"\" class=\"wp-image-1910\"\/><\/figure>\n\n\n\n<p>The blue line is the weekly SMA200, and as you can see is trending upwards which is good. More importantly the green line which is the daily SMA200 is way above the SMA200 for the weekly. This is a strong indication that the S&amp;P 500 is a really good option to be trading.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-merging-the-daily-and-hourly-datasets\">Merging the Daily and Hourly datasets<\/h2>\n\n\n\n<p>The question now is when do we get in and out of our positions. To do this we&#8217;ll need to compare the SMA200 for the Daily and the SAM for the Hourly.<\/p>\n\n\n\n<p id=\"c8ae\">I want to merge the daily SMA200 dataframe with the hourly SMA200 dataframe. This is not as straightforward as it sounds. The index for the daily is only a date, but the index for the hourly is a date and time. This will prevent this from working without some work.<\/p>\n\n\n\n<p id=\"5b81\">The way I resolved this is to create a new dataframe called, \u201c<strong>df_hourly2<\/strong>\u201d with a copy of the, \u201c<strong>df_hourly<\/strong>\u201d dataframe. I created a new feature called \u201c<strong>JoinOnDate<\/strong>\u201d with only the date from the date and time index. I also stored the current index for later in \u201c<strong>StoreIndex<\/strong>\u201d.<\/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\">    df_hourly2 = df_hourly.copy()\n    df_hourly2[\"JoinOnDate\"] = df_hourly.index.date\n    df_hourly2[\"JoinOnDate\"] = pd.to_datetime(df_hourly2[\"JoinOnDate\"]).dt.date\n    df_hourly2[\"StoreIndex\"] = df_hourly.index\n    print(df_hourly2)\n<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"2384\" height=\"424\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.27.47.png\" alt=\"\" class=\"wp-image-1911\"\/><\/figure>\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\">    df_daily2 = df_daily.copy()\n    df_daily2[\"JoinOnDate\"] = df_daily2.index\n    df_daily2[\"JoinOnDate\"] = pd.to_datetime(df_daily2[\"JoinOnDate\"]).dt.date\n    print(df_daily2)\n<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1596\" height=\"424\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.31.09.png\" alt=\"\" class=\"wp-image-1912\"\/><\/figure>\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\">    df_daily_hourly = df_hourly2.merge(df_daily2[[\"JoinOnDate\", \"Daily SMA200\"]], on=\"JoinOnDate\", how=\"left\").set_index(\"StoreIndex\")\n    df_daily_hourly.index.name = \"Date\"\n    df_daily_hourly.drop([\"JoinOnDate\"], axis=1, inplace=True)\n    print(df_daily_hourly)<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"2130\" height=\"422\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.32.32.png\" alt=\"\" class=\"wp-image-1913\"\/><\/figure>\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\">    df_plot = df_daily_hourly.dropna().loc[\"2023\", [\"close\", \"Daily SMA200\", \"Hourly SMA200\"]]\n    df_plot = df_plot[df_plot[\"close\"] != 0]\n    df_plot.rename(columns={\"close\": \"Close\"}, inplace=True)\n    df_plot.plot(title=\"S&amp;P 500 Weekly SMA 200 vs. Daily SMA 200\", kind=\"line\", color=[\"black\", \"green\", \"blue\"], figsize=(36, 12))\n    plt.show()<\/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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"866\" height=\"420\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.40.25.png\" alt=\"\" class=\"wp-image-1914\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"4562\" height=\"1794\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-04-at-13.40.59.png\" alt=\"\" class=\"wp-image-1915\" style=\"width:840px;height:330px\"\/><\/figure>\n\n\n\n<p>The blue line is the Hourly SMA200, and the green line is the Daily SMA200. As you can see the Hourly SMA200 is above the Daily SMA200 which is really good. You can also see visually when the Daily crossed above the Weekly SMA200 which resulted in a strong upward trend on the price. If you had bought mid-June 2023 when the crossover happened, you would be in a pretty decent position now.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-in-summary\">In summary<\/h2>\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>Buy signal:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Daily SMA200 &gt; Weekly SMA200<\/li>\n\n\n\n<li>Hourly SMA200 &gt; Daily SMA200<\/li>\n<\/ul>\n\n\n\n<p>Sell signal:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hourly SMA200 &lt; Daily SMA200<\/li>\n<\/ul>\n\n\n\n<p>This strategy is not a day trading strategy. It&#8217;s meant for medium to long term investing. It&#8217;s tried and tested and confirmed with backtesting covering many years. A trade with some leverage would in almost all cases result in a profitable trade.<\/p>\n\n\n\n<p>I know one person who has been using this for years and in the last 100 trades, he had a 99% success rate which is pretty outstanding. I&#8217;m not sure what would have happened in that one failed trade but I expect he didn&#8217;t wait until the Hourly SMA200 had cleanly crossed above the Daily SMA200.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Medium-to-Long term investing into the S&amp;P 500 What is the S&amp;P 500? The S&amp;P 500 was established in 1957, and is a stock market index that measures the stock performance of 500 large companies listed on stock exchanges in the United States. It is one of the most widely followed equity indices in the world [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":1918,"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":[42,59],"tags":[],"coding-language":[30],"ready-to-go-solution":[56],"qualification":[32],"financial-apis-category":[36],"financial-apis-manuals":[39,47,38,40],"class_list":["post-1888","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stocks-data-analysis-examples","category-technical-analysis-examples","coding-language-python","ready-to-go-solution-eodhd-python-financial-library","qualification-guru","financial-apis-category-stock-market-prices","financial-apis-manuals-end-of-day","financial-apis-manuals-exchanges-data","financial-apis-manuals-intraday","financial-apis-manuals-technical-indicators","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>SP SMA Trading Strategy: Analyzing the History of the S&amp;P 500 | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Learn about the SP SMA Trading Strategy and how it can help you evaluate your trading strategies with historical data from the S&amp;P 500\" \/>\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\/technical-analysis-examples\/sp-500-sma200-trading-strategy\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"S&amp;P 500 - SMA200 Trading Strategy\" \/>\n<meta property=\"og:description\" content=\"Learn about the SP SMA Trading Strategy and how it can help you evaluate your trading strategies with historical data from the S&amp;P 500\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\" \/>\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-09-05T20:41:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T12:22:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"980\" \/>\n\t<meta property=\"og:image:height\" content=\"490\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Whittle\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\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=\"Michael Whittle\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\"},\"author\":{\"name\":\"Michael Whittle\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/50784c270b6267df5969514d80d510ad\"},\"headline\":\"S&amp;P 500 &#8211; SMA200 Trading Strategy\",\"datePublished\":\"2023-09-05T20:41:10+00:00\",\"dateModified\":\"2025-02-05T12:22:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\"},\"wordCount\":1478,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\",\"articleSection\":[\"Stocks Data Analysis Examples\",\"Technical Analysis Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\",\"name\":\"SP SMA Trading Strategy: Analyzing the History of the S&P 500 | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\",\"datePublished\":\"2023-09-05T20:41:10+00:00\",\"dateModified\":\"2025-02-05T12:22:06+00:00\",\"description\":\"Learn about the SP SMA Trading Strategy and how it can help you evaluate your trading strategies with historical data from the S&P 500\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\",\"width\":7000,\"height\":3500,\"caption\":\"S&amp;P 500 US Stock market exchange index. Financial trading investment concept.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"S&amp;P 500 &#8211; SMA200 Trading Strategy\"}]},{\"@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\/50784c270b6267df5969514d80d510ad\",\"name\":\"Michael Whittle\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g\",\"caption\":\"Michael Whittle\"},\"description\":\"Solution architect, developer, and analyst with over 20+ years experience (TOP author on Medium).\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/michaelwhittle\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SP SMA Trading Strategy: Analyzing the History of the S&P 500 | EODHD APIs Academy","description":"Learn about the SP SMA Trading Strategy and how it can help you evaluate your trading strategies with historical data from the S&P 500","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\/technical-analysis-examples\/sp-500-sma200-trading-strategy","og_locale":"en_US","og_type":"article","og_title":"S&amp;P 500 - SMA200 Trading Strategy","og_description":"Learn about the SP SMA Trading Strategy and how it can help you evaluate your trading strategies with historical data from the S&P 500","og_url":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2023-09-05T20:41:10+00:00","article_modified_time":"2025-02-05T12:22:06+00:00","og_image":[{"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","width":980,"height":490,"type":"image\/jpeg"}],"author":"Michael Whittle","twitter_card":"summary_large_image","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Michael Whittle","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy"},"author":{"name":"Michael Whittle","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/50784c270b6267df5969514d80d510ad"},"headline":"S&amp;P 500 &#8211; SMA200 Trading Strategy","datePublished":"2023-09-05T20:41:10+00:00","dateModified":"2025-02-05T12:22:06+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy"},"wordCount":1478,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","articleSection":["Stocks Data Analysis Examples","Technical Analysis Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","url":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","name":"SP SMA Trading Strategy: Analyzing the History of the S&P 500 | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","datePublished":"2023-09-05T20:41:10+00:00","dateModified":"2025-02-05T12:22:06+00:00","description":"Learn about the SP SMA Trading Strategy and how it can help you evaluate your trading strategies with historical data from the S&P 500","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","width":7000,"height":3500,"caption":"S&amp;P 500 US Stock market exchange index. Financial trading investment concept."},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"S&amp;P 500 &#8211; SMA200 Trading Strategy"}]},{"@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\/50784c270b6267df5969514d80d510ad","name":"Michael Whittle","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g","caption":"Michael Whittle"},"description":"Solution architect, developer, and analyst with over 20+ years experience (TOP author on Medium).","url":"https:\/\/eodhd.com\/financial-academy\/author\/michaelwhittle"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-us","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1888","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\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=1888"}],"version-history":[{"count":12,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1888\/revisions"}],"predecessor-version":[{"id":6253,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1888\/revisions\/6253"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/1918"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=1888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=1888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=1888"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=1888"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=1888"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=1888"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=1888"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=1888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}