{"id":15622,"date":"2021-05-04T02:22:24","date_gmt":"2021-05-03T18:22:24","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=15622"},"modified":"2023-08-04T10:14:17","modified_gmt":"2023-08-04T02:14:17","slug":"technical-analysis","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/","title":{"rendered":"Technical Analysis"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"682\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\/image-227-1024x682.png\" alt=\"\" class=\"wp-image-15623\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-227-1024x682.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-227-300x200.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-227-150x100.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-227-768x512.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-227.png 1400w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"2154\">Most investors mainly do their investment from<strong>&nbsp;the technical analysis, the fundamental analysis and the chip analysis.&nbsp;<\/strong>The technical analysis will use a lot of historical data among these 3 methods. Therefore, we are going to&nbsp;<strong>use Python to share some technical analysis indicators<\/strong>&nbsp;which investors used frequently this week.<\/p>\n<\/blockquote>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f5e80e29302\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f5e80e29302\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#Highlights_of_this_article\" >Highlights of this article<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#Links_related_to_this_article\" >Links related to this article<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#What_is_technical_analysisTA\" >What is technical analysis(TA)?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#TA_Indicators_Introduction\" >TA Indicators Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#MACDMoving_Average_Convergence_Divergence\" >MACD(Moving Average Convergence Divergence)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#Bollinger_Bands\" >Bollinger Bands<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#RSIRelative_Strength_Index\" >RSI(Relative Strength Index)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#ATRAverage_True_Range\" >ATR(Average True Range)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#KD_Indicator\" >KD Indicator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#Using_TA_Indicators_to_perform_backtesting\" >Using TA Indicators to perform backtesting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.tejwin.com\/en\/insight\/technical-analysis\/#Links_related_to_this_article_again\" >Links related to this article again!<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"afda\"><span class=\"ez-toc-section\" id=\"Highlights_of_this_article\"><\/span><strong>Highlights of this article <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83c\udf1f Technical Analysis Intro\/Indicators Intro<\/li>\n\n\n\n<li>\ud83c\udf1f Backtesting Sample<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"209c\"><span class=\"ez-toc-section\" id=\"Links_related_to_this_article\"><\/span><strong>Links related to this article<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1\ufe0f\u20e3 API Official Website:&nbsp;<\/strong><a href=\"https:\/\/api.tej.com.tw\/\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ API Official Website<\/strong><\/a><\/li>\n\n\n\n<li><strong>2\ufe0f\u20e3 The Product Package:&nbsp;<\/strong><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/1\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ E-SHOP<\/strong><\/a><\/li>\n\n\n\n<li><strong>3\ufe0f\u20e3 Source Code:&nbsp;<\/strong><a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Quant\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ GITHUB<\/strong><\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"67c1\"><span class=\"ez-toc-section\" id=\"What_is_technical_analysisTA\"><\/span>What is technical analysis(TA)?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"bdfc\"><strong>The technical analysis mainly uses past information such as historical data to explain the trends or determining the timing of investment.<\/strong>&nbsp;However, the past is the past. But when you want to have a quantitative understanding of the current market situations, technical analysis can provide some indicators for investors to&nbsp;<strong>simplify the past information<\/strong>&nbsp;for them to reference.<\/p>\n\n\n\n<p id=\"95c5\"><strong>We are not going to compare the pros and cons of the technical analysis in this article. How to use codes to have a further understanding of the commonly used technical indicators is the main goal this time!<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Example of TA\uff1aMoving Average, KD Indicators, RSI, MACD, etc.<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e0ca\"><span class=\"ez-toc-section\" id=\"TA_Indicators_Introduction\"><\/span>TA Indicators Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"7039\">Before we start the introduction, let\u2019s get the data for our TEJ API first! We are going to use the historical data of UMC(2303) this time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tejapi \nimport pandas as pd\nimport numpy as np\nimport datetime\ntejapi.ApiConfig.api_key = \"your key\"\nUMC = tejapi.get( \n    'TWN\/EWPRCD', \n    coid = '2303',\n    mdate={'gte':'2020-04-01', 'lte':'2021-04-25'},\n    opts={'columns': &#91;'mdate','open_d','high_d','low_d','close_d',              'volume']}, \n    paginate=True)\nUMC = UMC.set_index('mdate')<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1aVwit6o_jPRvB1XqYspFRQ.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">UMC Historical Data<\/figcaption><\/figure>\n\n\n\n<p id=\"96d6\">After getting the historical data, now we can enter our next step!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3f56\"><span class=\"ez-toc-section\" id=\"MACDMoving_Average_Convergence_Divergence\"><\/span>MACD(Moving Average Convergence Divergence)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"6e33\">MACD compares the exponential moving average(EMA) of long(26) and short(12) days, subtracts to find the difference(DIF), and then calculates the difference again on the EMA. To put it simply,&nbsp;<strong>MACD is used to judge the trading timing of the target through the staggered condition between the EMA of long and short days.<\/strong><\/p>\n\n\n\n<p id=\"a8b7\"><strong>EMA:<\/strong>\u00a0The difference between the simple moving average is that EMA places a greater weight and significance on the most recent data points.<br><strong>DIF(Short-term):<\/strong>\u00a0The subtraction of short-term and long-term EMA, which usually represents a short-term trend.<br><strong>MACD(Long-term):<\/strong>\u00a0Taking the EMA of DIF again, which usually can judge the long-term trend.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def MACD(DF, a = 12, b =26, c =9):\n    '''\n    SMA: rolling\n    EMA: ewm\n    '''\n    df = DF.copy()\n    df&#91;\"EMA_Fast\"] = \n         df&#91;'open_d'].ewm(span = a, min_periods = a).mean()\n    df&#91;\"EMA_Slow\"] = \n         df&#91;'open_d'].ewm(span = b, min_periods = b).mean()\n    df&#91;\"DIF\"] = df&#91;\"EMA_Fast\"] - df&#91;\"EMA_Slow\"]\n    df&#91;\"MACD\"] = df&#91;'MACD'].ewm(span = c, min_periods = c).mean()\n    \n    return df<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1QI3JbBugCvOUK75pnSz_Rg.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1857\"><span class=\"ez-toc-section\" id=\"Bollinger_Bands\"><\/span>Bollinger Bands<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"53d4\">The Bollinger Bands are made by the combination of 3 lines, which are&nbsp;<strong>the simple moving average, the upper standard deviation line, and the lower standard deviation line<\/strong>&nbsp;to show the safe area of the stock price.<\/p>\n\n\n\n<p id=\"26f8\">The reason for using 2 standard deviations is that in the statistical normal distribution, there is a 95% probability that it will fall between the 2 standard deviations. Although the market may not completely follow the normal distribution, it will still fall between 2 standard deviations most of the time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def BollingerBand(DF, n=20):\n    '''\n    Standard Deviation: std\n    '''\n    df = DF.copy()\n    df&#91;'SMA'] = df&#91;'close_d'].rolling(window = n).mean()\n    df&#91;'BB_20dstd_up'] = \n         df&#91;'SMA'] + 2*df&#91;'close_d'].rolling(window = n).std(ddof=0)\n    df&#91;'BB_20dstd_down'] = \n         df&#91;'SMA'] - 2*df&#91;'close_d'].rolling(window = n).std(ddof=0)\n    df&#91;'BB_width'] = df&#91;'BB_20dstd_up'] - df&#91;'BB_20dstd_down']\n    df.dropna(inplace = True)\n    \n    return df<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/10vNfxhlJVEEAQI34ki7Qgw.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"0dfa\"><span class=\"ez-toc-section\" id=\"RSIRelative_Strength_Index\"><\/span>RSI(Relative Strength Index)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"a40a\"><strong>The Relative Strength Index is mainly used to access the \u201cstrength of the buyer\u2019s and seller\u2019s strength\u201d<\/strong>\u00a0in the stock market, and to access the overbought\/oversold situation through the recent price changes. The value of\u00a0<strong>RSI is within 0 to 100. The larger or smaller the value, the stronger the strength.<\/strong>\u00a0Usually, below 30 means oversold, over 70 means overbought.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def RSI(DF, n=14):\n    '''\n    n-day avarage increase = sum of n-day total daily increase \u00f7 n\n    n-day avarage decrease = sum of n-day total daily decrease \u00f7 n\n    '''\n    df = DF.copy()\n    df&#91;'daliy_change'] = \n         df&#91;'close_d'] - df&#91;'close_d'].shift(1)\n    df&#91;'dUp'] = \n         np.where(df&#91;'daliy_change'] >= 0, df&#91;'daliy_change'], 0)\n    df&#91;'dDown'] = \n         np.where(df&#91;'daliy_change'] &lt; 0, -df&#91;'daliy_change'], 0)\navg_dUp = &#91;]\n    avg_dDown = &#91;]\n    dUp = df&#91;'dUp'].tolist()\n    dDown = df&#91;'dDown'].tolist()\n    \n    for i in range(len(df)):\n        if i &lt; n:\n            avg_dUp.append(0)\n            avg_dDown.append(0)\n        elif i == n:\n            avg_dUp.append(df&#91;'dUp'].ewm(span = n).mean()&#91;n])\n            avg_dDown.append(df&#91;'dDown'].ewm(span = n).mean()&#91;n])\n        else:\n            avg_dUp.append(((n-1)*avg_dUp&#91;i-1] + dUp&#91;i])\/n)\n            avg_dDown.append(((n-1)*avg_dDown&#91;i-1] + dDown&#91;i])\/n)\n    \n    df&#91;'avg_dUp'] = np.array(avg_dUp)\n    df&#91;'avg_dDown'] = np.array(avg_dDown)\ndf&#91;'RS'] = df&#91;'avg_dUp']\/df&#91;'avg_dDown']\n    df&#91;'RSI'] = df&#91;'RS'].apply(lambda x: x\/(1+x) * 100)\n        \n    return df<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_1-kfnbSMY7IjneYlEXP8niw.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3954\"><span class=\"ez-toc-section\" id=\"ATRAverage_True_Range\"><\/span>ATR(Average True Range)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"da12\"><strong>ATR refers to the true range of the stock price fluctuations within a period of time(14 days used in this article), which is a measure of the volatility of the target.<\/strong><\/p>\n\n\n\n<p id=\"89af\">In order to calculate the ATR, we must first calculate the TR, and<strong>\u00a0the TR refers to the largest number among the following 3 numbers:<\/strong><br><strong>1. H-L:<\/strong>\u00a0Today\u2019s high minus today\u2019s low.<br><strong>2. H-PC:<\/strong>\u00a0The absolute value of today\u2019s high minus yesterday\u2019s close.<br><strong>3. L-PC:<\/strong>\u00a0The absolute value of today\u2019s low minus yesterday\u2019s close.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def ATR(DF, n=14):\n    '''\n    Close Price of Previous Day: close.shift()\n    '''\n    df = DF.copy()\n    df&#91;'H-L'] = abs(df&#91;'high_d'] - df&#91;'low_d'])\n    df&#91;'H-PC'] = abs(df&#91;'high_d'] - df&#91;'close_d'].shift())\n    df&#91;'L-PC'] = abs(df&#91;'low_d'] - df&#91;'close_d'].shift())\n    df&#91;'TR'] = df&#91;&#91;'H-L', 'H-PC', 'L-PC']].max(axis =1, skipna =False)\n    df&#91;'ATR'] = df&#91;'TR'].ewm(span =n, min_periods=n).mean()\n    \n    return df<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1Ms7HuU9yElF2c_rghiIX7g.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dc1c\"><span class=\"ez-toc-section\" id=\"KD_Indicator\"><\/span>KD Indicator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"7125\"><strong>The KD Indicator is mainly used to show the trend of the asset\u2019s price in the past period of time.<\/strong>&nbsp;The 2 values of K and D are used to find possible price turning points as trading signals. The concept of the KD indicator is similar to RSI,&nbsp;<strong>but the difference is that the KD indicator is based on the relative high or low of the latest price, while the RSI comparing the ratio of the strength of the buy\/sell.<\/strong><\/p>\n\n\n\n<p id=\"5d9b\"><strong>Calculation:<br>RSV:\u00a0<\/strong>(Today\u2019s close -14day LOW)\uff0f(14day High -14day Low) * 100<strong><br>K:\u00a0<\/strong>Yesterday\u2019s K*(2\/3)\uff0bToday\u2019s RSV*(1\/3)<strong><br>D:\u00a0<\/strong>Yesterday\u2019s D*(2\/3)\uff0bToday\u2019s K*(1\/3)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def KD(DF, n = 14):\n    '''\n    function to calculate KD\n    '''\n    df = DF.copy()\n    df&#91;'High_9D'] = df&#91;'high_d'].rolling(n).max()\n    df&#91;'Low_9D'] = df&#91;'low_d'].rolling(n).min()\n    df&#91;'RSV'] = \n        (df&#91;'close_d'] - df&#91;'Low_9D']) \/ (df&#91;'High_9D'] - df&#91;'Low_9D']) * 100\ndf = df.dropna()    \n    df&#91;'K'] = np.zeros(len(df))\n    df&#91;'D'] = np.zeros(len(df))\n    \n    for i in range(len(df)):\n        if i == 0:\n            df&#91;'K']&#91;i] = 50\n            df&#91;'D']&#91;i] = 50\n        else:\n            df&#91;'K']&#91;i] = df&#91;'K']&#91;i-1]*(2\/3) + df&#91;'RSV']&#91;i]*(1\/3)\n            df&#91;'D']&#91;i] = df&#91;'D']&#91;i-1]*(2\/3) + df&#91;'K']&#91;i]*(1\/3)\n    \n    return df<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1U1gM3WXdD-9GZF98sK3Q-Q.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3fc7\"><span class=\"ez-toc-section\" id=\"Using_TA_Indicators_to_perform_backtesting\"><\/span>Using TA Indicators to perform backtesting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"592d\">We are going to use some indicators we\u2019ve mentioned above to construct our strategy.&nbsp;<strong>Notice!! The signals are built without serious testing. The purpose is only to introduce how to applicate those indicators, so even if the results are not bad, you shouldn\u2019t use them directly!!<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Strategy Example<\/strong><br>&#8211; Buy Signal:<br>MACD Increase and K &gt; 70 and Today\u2019s K &gt; Yesterday\u2019s K<br>&#8211; Sell Signal:<br>Today\u2019s Low &lt; (Yesterday\u2019s Close \u2014 Yesterday\u2019s ATR)<\/li>\n\n\n\n<li><strong>Strategy Assumption<\/strong><br>&#8211; We invest NT$1 dollar to buy when the buying signal appears and hold till the selling point appears.<br>&#8211; We ignore the transaction fees and security tax.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>print(\"Calculating returns for \",\"UMC\")\nret = &#91;]\nfor i in range(1,len(UMC)):\n    buy_signal = UMC&#91;\"DIF\"]&#91;i]> UMC&#91;\"MACD\"]&#91;i] and \\\n                 UMC&#91;\"K\"]&#91;i]> 70 and \\\n                 UMC&#91;\"K\"]&#91;i] > UMC&#91;\"K\"]&#91;i-1]\nsell_signal = \n\u3000\u3000\u3000\u3000\u3000UMC&#91;\"low_d\"]&#91;i] &lt; UMC&#91;\"close_d\"]&#91;i-1] - UMC&#91;\"ATR\"]&#91;i-1]\nif tickers_signal&#91;\"UMC\"] == \"\":\n        tickers_ret&#91;\"UMC\"].append(0)\n        if buy_signal:\n            tickers_signal&#91;\"UMC\"] = \"Buy\"\nelif tickers_signal&#91;\"UMC\"] == \"Buy\":\n        if sell_signal:\n            tickers_signal&#91;\"UMC\"] = \"\"\n            tickers_ret&#91;\"UMC\"].append(\n    ((UMC&#91;\"close_d\"]&#91;i] - UMC&#91;\"close_d\"]&#91;i-1])\/UMC&#91;\"close_d\"]&#91;i-1]))\n        else:\n            tickers_ret&#91;\"UMC\"].append(\n      (UMC&#91;\"close_d\"]&#91;i]\/UMC&#91;\"close_d\"]&#91;i-1])-1)\nUMC&#91;'ret'] = np.array(tickers_ret&#91;\"UMC\"])\n<\/code><\/pre>\n\n\n\n<p id=\"fef6\">After finding the signal points and the rate of return, let\u2019s make a simple plot to see how this strategy performs!<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1ljI7T7Pm1A5MZozlvIQAMw.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"4b1c\">It seems that our performance is acceptable, but we have ignored many possible costs of course. However, we could understand that if<strong>&nbsp;we use the technical analysis indicators properly, investors can indeed simplify a lot of past information&nbsp;<\/strong>and find the trading signals.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"f1aa\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"19ae\"><strong>Different people will have different opinions toward the same data, but the indicators created from the data could still be used as a tool for investors to judge whether to buy or sell.&nbsp;<\/strong>This article is to share how to build these indicators through Python by yourself. Of course, there are many packages that have included these indicators, but through these processes, you will understand more about these indicators and can adjust the parameters by yourself in the future!\ud83d\udcaa\ud83d\udcaa<\/p>\n\n\n\n<p id=\"c514\"><strong>If you like this topic, please click \ud83d\udc4f below, giving us more support and encouragement. Additionally, if you have any questions or suggestions, please leave a message or email us, we will try our best to reply to you.\ud83d\udc4d\ud83d\udc4d<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"d9f0\"><span class=\"ez-toc-section\" id=\"Links_related_to_this_article_again\"><\/span>Links related to this article again!<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1\ufe0f\u20e3 API Official Website:\u00a0<\/strong><a href=\"https:\/\/api.tej.com.tw\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\"><strong>TEJ API Official Website<\/strong><\/a><\/li>\n\n\n\n<li><strong>2\ufe0f\u20e3 The Product Package:&nbsp;<\/strong><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/1\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ E-SHOP<\/strong><\/a><\/li>\n\n\n\n<li><strong>3\ufe0f\u20e3 Source Code:&nbsp;<\/strong><a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Quant\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ GITHUB<\/strong><\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Most investors mainly do their investment from&nbsp;the technical analysis, the fundamental analysis and the chip analysis.&nbsp;The technical analysis will use a lot of historical data among these 3 methods. Therefore, we are going to&nbsp;use Python to share some technical analysis indicators&nbsp;which investors used frequently this week. Highlights of this article Links related to this article [&hellip;]<\/p>\n","protected":false},"featured_media":6729,"template":"","tags":[2371,2639,3008],"insight-category":[690,50],"class_list":["post-15622","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-python","tag-technical-analysis","tag-tejapi-quant","insight-category-data-analysis","insight-category-fintech"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/15622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight"}],"about":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/types\/insight"}],"version-history":[{"count":0,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/15622\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/6729"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=15622"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=15622"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=15622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}