{"id":23183,"date":"2024-05-02T13:00:00","date_gmt":"2024-05-02T05:00:00","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=23183"},"modified":"2024-06-12T11:21:54","modified_gmt":"2024-06-12T03:21:54","slug":"tquant-lab-ichimoku-kinko-hyo","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/","title":{"rendered":"TQuant Lab Ichimoku Kinko Hyo Strategy, A Self-contained Technical Analysis Indicator"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-full caption-align-center\"><img fetchpriority=\"high\" decoding=\"async\" width=\"5719\" height=\"3720\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Mt.-Fuji-photo.jpg\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-22909\" style=\"aspect-ratio:1.5;object-fit:cover\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Mt.-Fuji-photo.jpg 5719w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Mt.-Fuji-photo-300x195.jpg 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Mt.-Fuji-photo-1024x666.jpg 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Mt.-Fuji-photo-150x98.jpg 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Mt.-Fuji-photo-768x500.jpg 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Mt.-Fuji-photo-1536x999.jpg 1536w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Mt.-Fuji-photo-2048x1332.jpg 2048w\" sizes=\"(max-width: 5719px) 100vw, 5719px\" \/><figcaption class=\"wp-element-caption\">Photo by <a href=\"https:\/\/unsplash.com\/@manucosen?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\" target=\"_blank\" rel=\"noopener\">Manuel Cosentino<\/a> on <a href=\"https:\/\/unsplash.com\/photos\/mt-fuji-n--CMLApjfI?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Unsplash<\/a><\/figcaption><\/figure>\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-69f10c7b16356\" 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-69f10c7b16356\"  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\/tquant-lab-ichimoku-kinko-hyo\/#Highlight\" >Highlight<\/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\/tquant-lab-ichimoku-kinko-hyo\/#Introduction\" >Introduction<\/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\/tquant-lab-ichimoku-kinko-hyo\/#Introduction_to_Ichimoku_Kinko_Hyo_Framework\" >Introduction to Ichimoku Kinko Hyo Framework<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Time_Theory\" >Time Theory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Interpretation_Method\" >Interpretation Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Turning_Lines_and_Standard_Lines\" >Turning Lines and Standard Lines<\/a><\/li><\/ul><\/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\/tquant-lab-ichimoku-kinko-hyo\/#Editing_Environment_and_Module_Requirements\" >Editing Environment and Module Requirements&nbsp;<\/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\/tquant-lab-ichimoku-kinko-hyo\/#Data_Import_and_Use_of_get_universe_Function_to_Obtain_Stock_Pool\" >Data Import and Use of get_universe Function to Obtain Stock Pool<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Using_TEJToolAPI_to_Fetch_MSCI_Component_Stocks\" >Using TEJToolAPI to Fetch MSCI Component Stocks<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Loading_data_into_bundle\" >Loading data into bundle<\/a><\/li><\/ul><\/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\/tquant-lab-ichimoku-kinko-hyo\/#Creating_Pipeline_Function\" >Creating Pipeline Function<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Creating_Custom_Factor\" >Creating Custom Factor<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Creating_Initialize_Function\" >Creating Initialize Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Creating_Handle_data_Function\" >Creating Handle_data Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Executing_Trading_Strategy\" >Executing Trading Strategy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Evaluating_performance_using_Pyfolio\" >Evaluating performance using&nbsp;Pyfolio<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Viewing_the_performance_of_a_specific_stock_under_the_Ichimoku_Kinko_Hyo_strategy\" >Viewing the performance of a specific stock under the Ichimoku Kinko Hyo strategy<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Source_Code\" >Source Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#Extended_Reading\" >Extended Reading<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tquant-lab-ichimoku-kinko-hyo\/#About\" >About<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Highlight\"><\/span><strong><strong>Highlight<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Difficulty\uff1a\u2605\u2605\u2605\u2606\u2606<\/li>\n\n\n\n<li>Introduction to Ichimoku Kinko Hyo and trailing stop.<\/li>\n\n\n\n<li>Write an Ichimoku Kinko Hyo strategy using TQuant Lab backtesting platform and backtest risk and performance.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span><strong>Introduction<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Ichimoku Kinko Hyo (also known as Cloud Charts, \u3044\u3061\u3082\u304f\u304d\u3093\u3053\u3046\u3072\u3087\u3046) was invented by Japanese journalist Goichi Hosoda, but it was not publicly disclosed at the time. Forty years later, between 1975 and 6 years after that, Goichi Hosoda, using the pseudonym Ichimoku Sanjin, published seven series of works under the name &#8220;Ichimoku Kinko Hyo,&#8221; explaining in detail this indicator and the philosophical thinking behind its trading system.<\/p>\n\n\n\n<p>Unlike traditional concepts such as stock prices influenced by price-volume relationships, supply and demand for buying and selling, and fundamental aspects of companies, Ichimoku Kinko Hyo believes that time is an essential factor affecting price changes, especially under the influence of time, prices have cyclical changes. There is always a market concern that stocks will fall after rising for a long time and rise after falling for a long time. The overall market sentiment reflects a regularity of fluctuations in market behavior under the influence of time, which forms the basis of the &#8220;Time Theory&#8221; of Ichimoku Kinko Hyo.<\/p>\n\n\n\n<p>In addition, Ichimoku Kinko Hyo is a philosophical, technical analysis indicator. Rather than being an indicator per se, the author believes it should be regarded as Goichi Hosoda&#8217;s analysis and reflection on the market and society. The thought behind it is worth exploring in depth. Due to space constraints, this article does not elaborate on this. The author believes that <a href=\"https:\/\/medium.com\/trading-mind\/%E4%B8%80%E7%9B%AE%E5%9D%87%E8%A1%A1%E8%A1%A8%E7%90%86%E8%AB%96%E8%88%87%E5%B8%82%E5%A0%B4%E5%B9%B3%E8%A1%A1-27b49068c95\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">the theory of Ichimoku Kinko Hyo and market equilibrium<\/a> has good insights into Ichimoku Kinko Hyo. Those interested can refer to it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction_to_Ichimoku_Kinko_Hyo_Framework\"><\/span><strong>Introduction to Ichimoku Kinko Hyo Framework<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Time_Theory\"><\/span><strong>Time Theory<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The time theory of Ichimoku Kinko Hyo is a method of analyzing time and market turning points. &#8220;9, 17, 26&#8221; are the basic numbers and can be used to examine whether the market will likely have a turning point during this period, which is a significant value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Interpretation_Method\"><\/span><strong>Interpretation Method<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Conversion&nbsp;Line (<code>tenkan_sen<\/code>): The turning line (also known as&nbsp;the reversal line) is the average of the highest and lowest prices in the past nine days. If the turning line rises, it is judged that the upward momentum is strong, and if it falls, it is considered that the downward trend is strong.&nbsp;Because it is calculated based on a&nbsp;short&nbsp;period&nbsp;of nine days, it is used to analyze short-term trends.<\/li>\n\n\n\n<li>Base&nbsp;Line (<code>kijun_sen<\/code>): The standard line&nbsp;is the average of&nbsp;the highest and lowest prices over the past 26 days. If the standard line rises, it is judged that the upward momentum is strong, and if it falls, it is considered that the downward trend is strong. Since it is calculated based on a period of 26 days, it is used to analyze medium-term trends.<\/li>\n\n\n\n<li>Leading Span A \/ B (<code>senkou_span_a\/b<\/code>): Leading Span A predicts the future trend for the next 26 days based on the average turning line and the standard line. Leading Span B is a line that predicts the trend for the next 26 days based on the average of the highest and lowest prices of the past 52 days. Since both show the average trend for the next 26 days, they help analyze future price changes. After shading between Leading Span A and Leading Span B, the &#8220;cloud region or cloud band&#8221; is called the part with A &lt; B, green, and the part with A &gt; B, red.<\/li>\n\n\n\n<li>Lagging Span (<code>chikou_span<\/code>): The lagging span is the stock price 26 days ago. If it is above the price line, it indicates a strong upward trend in the market; if it is below the price line, it indicates a solid downward trend.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Turning_Lines_and_Standard_Lines\"><\/span><strong>Turning Lines and Standard Lines<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Ichimoku Kinko Hyo also has a method called &#8220;Three-Line Confirmation&#8221; and &#8220;Three-Line Reversal&#8221; for interpreting. &#8220;Three-line confirmation&#8221; represents a buy signal, and &#8220;Three-Line Reversal&#8221; represents a sell signal. Usually, if the three-line confirmation is met outside the stock&#8217;s price range, there will be a stronger upward trend, and vice versa. This article will fine-tune the buy signal based on the three-line confirmation.<\/p>\n\n\n\n<p><strong>Conditions for Three-Line Confirmation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Conversion Line exceeds the&nbsp;Base Line.<\/li>\n\n\n\n<li>The Lagging Span is above the price.<\/li>\n\n\n\n<li>The price exceeds the cloud area.<\/li>\n<\/ul>\n\n\n\n<p><strong>Conditions for Three-Line Reversal:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Conversion Line is below the&nbsp;Base Line.<\/li>\n\n\n\n<li>The Lagging Span is below the price.<\/li>\n\n\n\n<li>The price is below the cloud area.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Editing_Environment_and_Module_Requirements\"><\/span><strong>Editing Environment and Module Requirements<\/strong>&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This article uses MacOS and Jupyter Notebook as the editor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Data_Import_and_Use_of_get_universe_Function_to_Obtain_Stock_Pool\"><\/span><strong>Data Import and Use of <code>get_universe<\/code> Function to Obtain Stock Pool<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This strategy first fetches all stock codes of common stocks, including both listed and over-the-counter (OTC) markets, for one year, from April 1, 2018, to March 31, 2019.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport tejapi\nimport pandas as pd\nimport numpy as np\n\nos.environ&#91;'TEJAPI_KEY'] = \"your key\"\nos.environ&#91;'TEJAPI_BASE'] = \"https:\/\/api.tej.com.tw\"\nstart = '2018-04-01'\nend = '2019-03-31'\nfrom zipline.sources.TEJ_Api_Data import get_universe\npool = get_universe(start, end, mkt = &#91;'TWSE', 'OTC'], stktp_e=&#91;'Common Stock-Foreign', 'Common Stock'])\nlen(pool)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_TEJToolAPI_to_Fetch_MSCI_Component_Stocks\"><\/span><strong>Using TEJToolAPI to Fetch MSCI Component Stocks<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The Ichimoku Kinko Hyo strategy selects MSCI component stocks from the above stock codes using the TEJToolAPI.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>average_vol = df.groupby('\u80a1\u7968\u4ee3\u78bc')&#91;'\u6210\u4ea4\u91cf_\u5343\u80a1'].mean().reset_index()\naverage_vol = average_vol.rename(columns={'\u6210\u4ea4\u91cf_\u5343\u80a1': '\u5e73\u5747\u6210\u4ea4\u91cf'})\nhigh_price_stocks = df.groupby('\u80a1\u7968\u4ee3\u78bc')&#91;'\u6700\u4f4e\u50f9'].min().reset_index()\nhigh_price_stocks = high_price_stocks&#91;high_price_stocks&#91;'\u6700\u4f4e\u50f9'] &gt;= 50]\nmerge_data = pd.merge(average_vol, high_price_stocks, on='\u80a1\u7968\u4ee3\u78bc', how='inner')\ntop_100_vol = merge_data.sort_values(by='\u5e73\u5747\u6210\u4ea4\u91cf', ascending=False).head(100)\ntop_100_vol<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"807\" height=\"671\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.13.56.png\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-22914\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.13.56.png 807w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.13.56-300x249.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.13.56-150x125.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.13.56-768x639.png 768w\" sizes=\"(max-width: 807px) 100vw, 807px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Loading_data_into_bundle\"><\/span>Loading data into bundle<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To avoid lookahead bias, this strategy&#8217;s five-year backtesting period is from April 1, 2019, to April 1, 2024. It includes the aforementioned 91 constituent stocks, along with the Taiwan Weighted Index (<em>IR0001<\/em>), as a benchmark for market comparison.<\/p>\n\n\n\n<p>Below is the list of the 91 constituent stocks and the Taiwan Weighted Index:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>!zipline ingest -b tquant\n!zipline bundle-info<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full caption-align-center\"><img decoding=\"async\" width=\"505\" height=\"278\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53484.26.58.png\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-23054\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53484.26.58.png 505w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53484.26.58-300x165.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53484.26.58-150x83.png 150w\" sizes=\"(max-width: 505px) 100vw, 505px\" \/><figcaption class=\"wp-element-caption\">Component stock and backtest period<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_Pipeline_Function\"><\/span><strong>Creating Pipeline Function<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_Custom_Factor\"><\/span><strong>Creating Custom Factor<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>CustomFactor allows users to design custom factors as needed. In this case, we will use it to handle:<\/p>\n\n\n\n<p>Average True Range (ATR): Used to calculate trailing stop levels. Pipeline allows users to process quantitative indicators and price-volume data for multiple assets quickly. In this case, we will use it to handle:<\/p>\n\n\n\n<p>Conversion Line (tenkan_sen) Base Line (kijun_sen) Leading Span A \/ B (<code>senkou_span_a\/b<\/code>) Cloud area or cloud band (<code>cloud_red<\/code>) Lagging Span (<code>chikou_span<\/code>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from zipline.pipeline import Pipeline\nfrom zipline.TQresearch.tej_pipeline import run_pipeline\ndef make_pipeline():\n    \n    Ich = IchimokuKinkoHyo(\n        inputs = &#91;TWEquityPricing.high, TWEquityPricing.low, TWEquityPricing.close],\n        window_length = 52,\n    )\n    atr = AverageTrueRange(inputs = &#91;TWEquityPricing.high, TWEquityPricing.low, TWEquityPricing.close],\n        window_length = 52,\n    )\n    \n    return Pipeline(\n        columns = {\n            'curr_price': TWEquityPricing.close.latest,\n            \"tenkan_sen\": Ich.tenkan_sen,\n            \"kijun_sen\": Ich.kijun_sen,\n            \"senkou_span_a\": Ich.senkou_span_a,\n            \"senkou_span_b\": Ich.senkou_span_b,\n            'cloud_red': Ich.senkou_span_a &lt; Ich.senkou_span_b,\n            \"chikou_span\": Ich.chikou_span,\n            'stop_loss': atr.ATR,\n    },\n        # screen = ~StaticAssets(&#91;benchmark_asset])\n        screen = ~StaticAssets(&#91;benchmark_asset]) &amp; (Ich.senkou_span_a &gt; 0) &amp; (Ich.senkou_span_b &gt; 0)\n    )\nmy_pipeline = run_pipeline(make_pipeline(), start_dt, end_dt)\nmy_pipeline<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" width=\"1595\" height=\"562\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.21.14.png\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-22916\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.21.14.png 1595w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.21.14-300x106.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.21.14-1024x361.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.21.14-150x53.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.21.14-768x271.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.21.14-1536x541.png 1536w\" sizes=\"(max-width: 1595px) 100vw, 1595px\" \/><figcaption class=\"wp-element-caption\">Pipeline partial data<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_Initialize_Function\"><\/span><strong>Creating Initialize Function<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The<code> <strong>initialize()<\/strong><\/code> function defines the daily trading environment before trading begins. In this example, we set:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Slippage costs<\/li>\n\n\n\n<li>Transaction costs model for the Taiwan stock market<\/li>\n\n\n\n<li>Weighted return index (<em>IR0001<\/em>) as the benchmark<\/li>\n\n\n\n<li>Incorporating the Ichimoku Kinko Hyo indicators designed in Pipeline into the trading process<\/li>\n\n\n\n<li>Setting the <code>context.stop_loss<\/code> variable to record stop-loss points during backtesting<\/li>\n\n\n\n<li>Setting the <code>context.holding<\/code> variable to record whether a position in a particular stock is held<\/li>\n\n\n\n<li>Setting the <code>context.trailing_stop<\/code> variable to record whether&nbsp;the trailing&nbsp;stop is being applied<\/li>\n\n\n\n<li>Setting the <code>context.last_buy_price<\/code> variable to record the last purchase price<\/li>\n\n\n\n<li>Setting the <code>context.trailing_count<\/code> variable to record the number of trailing stop instances<\/li>\n\n\n\n<li>Setting the <code>context.buy_count<\/code> variable to limit the maximum number of trades per stock<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from zipline.finance import slippage, commission\nfrom zipline.api import *\n\ndef initialize(context):\n    set_slippage(slippage.VolumeShareSlippage())\n    set_commission(commission.Custom_TW_Commission(min_trade_cost = 20, discount = 1.0, tax = 0.003))\n    attach_pipeline(make_pipeline(), 'mystrats')\n    set_benchmark(symbol('IR0001'))\n    context.stop_loss = {}\n    context.trailing_stop = {}\n    context.last_buy_price = {}\n    context.trailing_count = {}\n    context.holding = {}\n    context.buy_count = {}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_Handle_data_Function\"><\/span><strong>Creating Handle_data Function<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The <strong><code>handle_data()<\/code><\/strong> function is important for constructing the Ichimoku Kinko Hyo strategy. It is called every day after the start of backtesting, and its main tasks include setting trading strategies, placing orders, and recording trading information.<\/p>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;To avoid the possibility of erroneous entry signals by the Ichimoku Kinko Hyo during periods of price consolidation, this article uses an additional *1.01 condition on <code>tenkan_sen<\/code> &gt; <code>kijun_sen<\/code>. This is done in the hope of entering the market only when the upward trend is sufficiently explicit, thereby achieving a certain degree of avoidance of consolidation periods.<\/p>\n\n\n\n<p>For detailed trading rules regarding this strategy, please refer to <a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Quant\/blob\/11779ccbbad36e1856824faec200257b0c668c21\/%E4%B8%80%E7%9B%AE%E5%9D%87%E8%A1%A1%E8%A1%A8.ipynb\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Ichimoku Kinko Hyo.ipynb<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        # \u4e09\u5f79\u597d\u8f49 (tenkan_sen &gt; kijun_sen*1.015 : avoid the Darvas Box Theory)\n        if (curr_price &gt; senkou_span_b) and (cloud_red == True) and (tenkan_sen &gt; kijun_sen*1.01) and (context.buy_count&#91;f'{i}'] &lt;= 5):\n            order_percent(i, 0.01)\n            buy = True\n            context.stop_loss&#91;f'{i}'] = curr_price - (1.25 * stop_loss)\n            context.last_buy_price&#91;f'{i}'] = curr_price\n            record(\n                **{\n                    f'buy_{sym}':buy\n                }\n            )\n            context.holding&#91;f'{i}'] = True\n            context.buy_count&#91;f'{i}'] += 1\n\n        # reset stop loss point\n        if (curr_price &gt;= (1.3**context.trailing_count&#91;f'{i}'])*context.last_buy_price&#91;f'{i}']) and (context.holding&#91;f'{i}'] == True) and (context.trailing_stop&#91;f'{i}'] == False):\n            context.stop_loss&#91;f'{i}'] = 1.3*context.stop_loss&#91;f'{i}']\n            context.trailing_stop&#91;f'{i}'] = True\n            context.trailing_count&#91;f'{i}'] += 1\n        elif (curr_price &gt;= (1.3**context.trailing_count&#91;f'{i}'])*context.last_buy_price&#91;f'{i}']) and (context.holding&#91;f'{i}'] == True) and (context.trailing_stop&#91;f'{i}'] == True):\n            context.stop_loss&#91;f'{i}'] = 1.3*context.stop_loss&#91;f'{i}']\n            context.trailing_count&#91;f'{i}'] += 1\n        \n        if (curr_price &lt;= context.stop_loss&#91;f'{i}']) and (context.holding&#91;f'{i}'] == True):\n            order_target(i, 0)\n            sell = True\n            context.stop_loss&#91;f'{i}'] = None\n            context.trailing_stop&#91;f'{i}'] = None\n            context.trailing_count&#91;f'{i}'] = None\n            record(\n                **{\n                    f'sell_{sym}':sell\n                }\n            )\n            context.holding&#91;f'{i}'] = None\n            context.buy_count&#91;f'{i}'] = None<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Executing_Trading_Strategy\"><\/span><strong>Executing Trading Strategy<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Use the <code><strong>run_algorithm()<\/strong><\/code> function to execute the Ichimoku Kinko Hyo strategy as defined above. Set the trading period from start_dt (2019-04-01) to end_dt (2024-04-01), using the dataset tquant, with an initial capital of 20 million dollars. The output results represent the daily performance and trade details.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import matplotlib.pyplot as plt\nfrom zipline import run_algorithm\n\nresults = run_algorithm(\n    start = start_dt,\n    end = end_dt,\n    initialize = initialize,\n    bundle = 'tquant',\n    analyze = analyze,\n    capital_base = 2e7,\n    handle_data = handle_data\n)\n\nresults<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" width=\"1378\" height=\"830\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.01.36.png\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-23037\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.01.36.png 1378w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.01.36-300x181.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.01.36-1024x617.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.01.36-150x90.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.01.36-768x463.png 768w\" sizes=\"(max-width: 1378px) 100vw, 1378px\" \/><figcaption class=\"wp-element-caption\">Changes in returns&nbsp;and entry\/exit performance based on the Ichimoku Kinko Hyo strategy for individual stocks (red marks indicate buy signals, green marks indicate sell signals).<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized caption-align-center\"><img loading=\"lazy\" decoding=\"async\" width=\"1215\" height=\"848\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.46.47.png\" alt=\"\u4e00\u76ee\u5747\u8861\u8868\u7b56\u7565\" class=\"wp-image-22920\" style=\"width:840px;height:auto\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.46.47.png 1215w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.46.47-300x209.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.46.47-1024x715.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.46.47-150x105.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-26-\u4e0b\u53482.46.47-768x536.png 768w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><figcaption class=\"wp-element-caption\">Backtest Details<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Evaluating_performance_using_Pyfolio\"><\/span>Evaluating performance using&nbsp;Pyfolio<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import pyfolio as pf \nreturns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(results)\nbenchmark_rets = results&#91;'benchmark_return']\npf.tears.create_full_tear_sheet(returns=returns,\n                                positions=positions,\n                                transactions=transactions,\n                                benchmark_rets=benchmark_rets\n                                )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized caption-align-center\"><img loading=\"lazy\" decoding=\"async\" width=\"1928\" height=\"1000\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u5408\u4f75\u5716\u50cf.png\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-23024\" style=\"width:841px;height:auto\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u5408\u4f75\u5716\u50cf.png 1928w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u5408\u4f75\u5716\u50cf-300x156.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u5408\u4f75\u5716\u50cf-1024x531.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u5408\u4f75\u5716\u50cf-150x78.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u5408\u4f75\u5716\u50cf-768x398.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u5408\u4f75\u5716\u50cf-1536x797.png 1536w\" sizes=\"(max-width: 1928px) 100vw, 1928px\" \/><figcaption class=\"wp-element-caption\">Backtest Performance &amp; Benchmark Comparison Chart<\/figcaption><\/figure>\n\n\n\n<p>We can observe that the Ichimoku Kinko Hyo strategy has provided excellent performance over the 58 months, with an annualized return of 23.554% and a cumulative return of 178.194%. The profit performance is quite impressive. The Sharpe ratio 1.38 indicates a relatively high return compared to the risk. Additionally, the \u03b2 value of 0.66 suggests that the strategy&#8217;s volatility is relatively insensitive to overall market volatility, reflecting the core concept of the Ichimoku Kinko Hyo system in detaching from the market.<\/p>\n\n\n\n<p>Regarding maximum drawdown, we can see a significant downturn during the systemic risk increase due to the epidemic between the 22nd and 23rd years. Stable growth trends have characterized other periods. Utilizing the entry signals provided by the Ichimoku Kinko Hyo, along with a strategy incorporating ATR trailing stops, is a robust approach for achieving consistent returns surpassing the market over the long term.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" width=\"1602\" height=\"500\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.40.14.png\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-23042\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.40.14.png 1602w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.40.14-300x94.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.40.14-1024x320.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.40.14-150x47.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.40.14-768x240.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53482.40.14-1536x479.png 1536w\" sizes=\"(max-width: 1602px) 100vw, 1602px\" \/><figcaption class=\"wp-element-caption\">Monthly Returns Variation Chart<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" width=\"1632\" height=\"608\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.05.png\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-23028\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.05.png 1632w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.05-300x112.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.05-1024x381.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.05-150x56.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.05-768x286.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.05-1536x572.png 1536w\" sizes=\"(max-width: 1632px) 100vw, 1632px\" \/><figcaption class=\"wp-element-caption\">Portfolio Holdings Variation Chart (Top Ten)<\/figcaption><\/figure>\n\n\n\n<p>It can be seen that the holding period for each stock is quite consistent, with little bias towards any particular stock.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Viewing_the_performance_of_a_specific_stock_under_the_Ichimoku_Kinko_Hyo_strategy\"><\/span>Viewing the performance of a specific stock under the Ichimoku Kinko Hyo strategy<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>graph(2330, True)<\/code><\/pre>\n\n\n\n<p>Since this strategy involves backtesting on a selection of stocks rather than individual stock backtesting, it&#8217;s impossible to quickly ascertain&nbsp;the&nbsp;actual entry and exit points&nbsp;for each stock&nbsp;within the Ichimoku Kinko Hyo system.&nbsp;Therefore, I have additionally written a function to facilitate the examination of individual stock trading situations. For more details, please refer to the&nbsp;<strong><a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Quant\/blob\/11779ccbbad36e1856824faec200257b0c668c21\/%E4%B8%80%E7%9B%AE%E5%9D%87%E8%A1%A1%E8%A1%A8.ipynb\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">source code<\/a><\/strong>&nbsp;on GitHub.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" width=\"1744\" height=\"487\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.59.png\" alt=\"Ichimoku Kinko Hyo\" class=\"wp-image-23030\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.59.png 1744w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.59-300x84.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.59-1024x286.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.59-150x42.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.59-768x214.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/\u622a\u5716-2024-04-30-\u4e0b\u53481.19.59-1536x429.png 1536w\" sizes=\"(max-width: 1744px) 100vw, 1744px\" \/><figcaption class=\"wp-element-caption\">The individual Ichimoku Kinko Hyo entry and exit performance for each stock (Red marks indicate buy signals, while green marks indicate sell signals)<\/figcaption><\/figure>\n\n\n\n<p>A notable point is that the entry method based on Ichimoku Kinko Hyo&#8217;s three signals&nbsp;does not&nbsp;include exit criteria.&nbsp;In practical testing, exiting based on the reversal of the three signals would result in losing many profitable trends. Therefore, this strategy employs a trailing stop-loss method for exits. For instance, in the chart above, you can see that the strategy had a sell order triggered by a stop-loss signal on TSMC (2330) at the beginning of 2021, capturing a trend lasting over half a year. However, apart from trailing stop-loss, one could incorporate profit-taking mechanisms such as setting profit targets or other means of securing gains. Additionally, strategies involving both long and short positions could be explored.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This strategy uses the Ichimoku Kinko Hyo for backtesting simulations, leveraging its signals of three conversions for entry and complementing it with trailing stop-loss for profit-taking, yielding promising backtest results. Investors are welcome to consider this approach.<\/p>\n\n\n\n<p>In the future, I will continue to introduce various indicators constructed using the TEJ database and backtest their performance. Therefore, readers interested in trading backtests are encouraged to explore <a href=\"https:\/\/tquant.tejwin.com\/\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\"><strong>TQuant Lab<\/strong><\/a>&#8216;s related solutions, utilizing high-quality databases to build their trading strategies.<\/p>\n\n\n\n<p><strong>A friendly reminder:<\/strong>&nbsp;This strategy is for reference only and does not constitute any recommendation for commodities or investments.<\/p>\n\n\n\n<div style=\"border: 1px black; border-style: solid none; text-align: center; border-color: #296580; padding: 24px; margin-top: 24px; margin-bottom: 24px;\">\n<p style=\"margin: 0px; font-size: 24px; font-weight: bold; line-height: 1.5;\">[TQuant Lab] Solving Your Quantitative Finance Pain Points<\/p>\n<p style=\"margin: 0px; font-size: 24px; font-weight: bold; line-height: 1.5;\">Comprehensively providing all the tools needed for trading backtesting.<\/p>\n<div style=\"margin-top: 32px;\"><a style=\"border: none; border-radius: 4px; background-color: #296580; color: white; font-size: 20px; width: fit-content; text-decoration: none; padding: 12px 30px 12px 30px;\" href=\"https:\/\/tquant.tejwin.com\/\" target=\"_blank\" rel=\"noopener\">Register and Start Your Trial<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Source_Code\"><\/span>Source Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Quant\/blob\/11779ccbbad36e1856824faec200257b0c668c21\/%E4%B8%80%E7%9B%AE%E5%9D%87%E8%A1%A1%E8%A1%A8.ipynb\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Click Here to Github<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extended_Reading\"><\/span>Extended Reading<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.tejwin.com\/insight\/esg-etf\/\" class=\"ek-link\"><\/a><a href=\"https:\/\/www.tejwin.com\/wp-admin\/post.php?post=22962&amp;action=edit&amp;lang=en&amp;update_needed=1&amp;trid=328125&amp;language_code=en\">TQuant Lab Should ESG ETF Be a Buy? Backtest Performance of ESG ETF<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.tejwin.com\/insight\/tquant-lab-kd-%e6%8c%87%e6%a8%99%e7%ad%96%e7%95%a5\/\" class=\"ek-link\"><\/a><a href=\"https:\/\/www.tejwin.com\/wp-admin\/post.php?post=22519&amp;action=edit&amp;lang=en&amp;update_needed=1&amp;trid=328047&amp;language_code=en\">TQuant Lab KD Indicator Strategy: Exploring Stock Price Reversal Timing?<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"About\"><\/span>About<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/tejtw\/TQuant-Lab\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">TQuant Lab Github<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/tquant.tejwin.com\/\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">TQuant Lab Home Page<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The Ichimoku Kinko Hyo strategy employed in this simulation utilizes the concept of the three-line conversion in the Ichimoku Cloud chart for backtesting, coupled with trailing stop-loss testing for profitability. Under the pen name Ichimoku Sanjin (\u3044\u3061\u3082\u304f\u3055\u3093\u3058\u3093 \/ Ichimoku Sanjin), Goichi Hosoda authored seven series of works detailing the philosophy behind this indicator and its trading system.<\/p>\n","protected":false},"featured_media":22910,"template":"","tags":[3063,3176,2990,3166,2537],"insight-category":[690,50,1356],"class_list":["post-23183","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-backtesting-2","tag-python-2","tag-quantitive-trading","tag-tquant-lab-2","tag-2537","insight-category-data-analysis","insight-category-fintech","insight-category-tquant-lab-en"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/23183","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":7,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/23183\/revisions"}],"predecessor-version":[{"id":24098,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/23183\/revisions\/24098"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/22910"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=23183"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=23183"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=23183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}