{"id":2612,"date":"2021-09-22T02:21:32","date_gmt":"2021-09-22T02:21:32","guid":{"rendered":"https:\/\/www.tejwin.com\/en\/insights\/martingale-strategy\/"},"modified":"2021-09-22T02:21:32","modified_gmt":"2021-09-22T02:21:32","slug":"martingale-strategy","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insights\/martingale-strategy\/","title":{"rendered":"Martingale Strategy"},"content":{"rendered":"<p class=\"wp-block-paragraph\">The gambling trading strategy.<\/p>\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/1_1wABPWOVg1mw6pX0Fc0QNrA.jpg\"\/><figcaption class=\"wp-element-caption\">Photo Creds:\u00a0<a href=\"https:\/\/unsplash.com\/\" rel=\"noreferrer noopener\" target=\"_blank\">Unsplash<\/a><\/figcaption><\/figure>\n<h2 class=\"wp-block-heading\" id=\"f3b6\"><strong>Highlights<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li>Difficulty\uff1a\u2605\u2606\u2606\u2606\u2606<\/li>\n<li>Introduce commonly used trading strategy in the foreign exchange market.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"141e\"><strong>Preface<\/strong><\/h2>\n<p class=\"wp-block-paragraph\" id=\"1fb5\">\u300cMartingale Strategy\u300dis a popular way of gambling since 18th century. The main method is to double the next bet when we lose this time. By this strategy, if we win the next bet, not only recover previous losses, but also get rewards for the first bet. It sound like a unbeatable strategy, but it has a tremendous risk behind.<\/p>\n<h2 class=\"wp-block-heading\" id=\"10c9\"><strong>The Editing Environment and Modules Required<\/strong><\/h2>\n<p class=\"wp-block-paragraph\" id=\"b49b\">Mac OS and Jupyter Notebook<\/p>\n<pre class=\"wp-block-preformatted\">import tejapi<br\/>import pandas as pd<br\/>import numpy as np<\/pre>\n<p class=\"wp-block-paragraph\" id=\"3679\"><em>Note: To install module tejapi :\u00a0<\/em><code><em>pip install tejapi<\/em><\/code><\/p>\n<pre class=\"wp-block-preformatted\">tejapi.ApiConfig.api_key = 'Your Key'<br\/>tejapi.ApiConfig.ignoretz = True<\/pre>\n<h2 class=\"wp-block-heading\" id=\"b5e2\"><strong>Database Used<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/api.tej.com.tw\/datatables.html?db=GLOBAL&amp;t=%E8%B7%A8%E5%9C%8B%E8%B3%87%E6%96%99%E5%BA%AB\" rel=\"noreferrer noopener\" target=\"_blank\">Multinational Database<\/a>: The code of database is \u2018GLOBAL\/GCURR\u2019. To obtain quotations in the New York and Asian markets exchange rate. The time range is from 2019 to 2020.<\/li>\n<\/ul>\n<pre class=\"wp-block-preformatted\">fx = tejapi.get('GLOBAL\/GCURR',<br\/>                coid = 'EUR',<br\/>                mdate={'gte': '2019-01-01', 'lte':'2020-12-31'},<br\/>                opts = {'columns':['mdate','tuse2']},<br\/>                chinese_column_name = True,<br\/>                paginate = True)<\/pre>\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/1_1-NJkk-7MvQD9IrC4R8Dhew.png\"\/><\/figure>\n<h2 class=\"wp-block-heading\" id=\"05e9\"><strong>Foreign Exchange Margin &amp; Profit<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li>Standard Hand : EUR\/USD is 100,000EUR ( If leverage ratio is 1:500, then the margin is 100000\/500 = 200EUR)<\/li>\n<li>Reference :\u00a0<a href=\"https:\/\/www.investopedia.com\/terms\/f\/foreign-exchange.asp\" rel=\"noreferrer noopener\" target=\"_blank\">https:\/\/www.investopedia.com\/terms\/f\/foreign-exchange.asp<\/a><\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"2b62\"><strong>Strategy<\/strong><\/h2>\n<p class=\"wp-block-paragraph\" id=\"8af8\">When the profit is positive, execute liquidation and buy 0.01 lots; if it is negative, continue to increase (2 times the lot) to buy.<\/p>\n<h4 class=\"wp-block-heading\" id=\"b2b3\"><strong>Step 1.\u00a0Initial Value<\/strong><\/h4>\n<pre class=\"wp-block-preformatted\">account  = 100000   # 100k USD<br\/>lot = 0.01            <br\/>lev = 1\/500           <br\/>lot_record = [].      <br\/>account_record = [] <br\/>cum_profit = 0<\/pre>\n<h4 class=\"wp-block-heading\" id=\"bb15\"><strong>Step 2.\u00a0Execute Strategy<\/strong><\/h4>\n<pre class=\"wp-block-preformatted\">for i in range(len(fx)):<br\/>    <br\/>    # \u7b2c\u4e00\u7b46\u8cb7\u5165<br\/>    if i &lt; 1:<br\/>        cum_profit -= (100000*lot*lev*fx.loc[i, '\u539f\u5e63\u514c\u7f8e\u5143 (\u7f8e\u5143)'])  <br\/>        # \u521d\u59cb\u8cb70.01\u624b\u9700\u8981\u7684\u4fdd\u8b49\u91d1\u70ba\u6b50\u5143\uff0c\u6240\u4ee5\u6309\u7167\u7576\u6642\u532f\u7387\u63db\u6210\u7f8e\u5143<br\/>        account += cum_profit                                       <br\/>        account_record.append(account)<br\/>        lot_record.append(lot)<br\/>    else:<br\/>        # \u7d2f\u8a08\u640d\u76ca\uff0c\u4e58\u4ee5100000\u662f\u70ba\u4e86\u63db\u6210\u5e03\u6578<br\/>        cum_profit += (fx.loc[i, '\u539f\u5e63\u514c\u7f8e\u5143 (\u7f8e\u5143)'] - fx.loc[i-1, <br\/>        '\u539f\u5e63\u514c\u7f8e\u5143 (\u7f8e\u5143)'])*100000*lot    # \u5e33\u6236\u9918\u984d<br\/>        account += (fx.loc[i, '\u539f\u5e63\u514c\u7f8e\u5143 (\u7f8e\u5143)'] - fx.loc[i-1, '\u539f\u5e63<br\/>        \u514c\u7f8e\u5143 (\u7f8e\u5143)'])*100000*lot    # \u5982\u679c\u7d2f\u8a08\u640d\u76ca\u7372\u5229,\u5e73\u5009\u5f8c\u8cb7\u51650.01\u624b<br\/>        if cum_profit &gt;= 0:       <br\/>            #\u8cb7\u51650.01\u624b\uff0c\u6545\u91cd\u7f6elot &amp; cum_profit<br\/>            lot = 0.01<br\/>            cum_profit = -(100000*lot*lev*fx.loc[i, '\u539f\u5e63\u514c\u7f8e\u5143 (\u7f8e<br\/>            \u5143)']) <br\/>            account += cum_profit<br\/>            account_record.append(account)<br\/>            lot_record.append(lot)    # \u82e5\u7d2f\u8a08\u640d\u76ca\u70ba\u8ca0\uff0c\u5247\u52a0\u78bc\u8cb7\u9032<br\/>        else:<br\/>            lot = lot *2 <br\/>            cum_profit -= (100000*(lot-lot\/2)*lev*fx.loc[i, '\u539f\u5e63\u514c\u7f8e<br\/>            \u5143 (\u7f8e\u5143)'])  <br\/>            account -= (100000*(lot-lot\/2)*lev*fx.loc[i, '\u539f\u5e63\u514c\u7f8e\u5143 <br\/>            (\u7f8e\u5143)'])<br\/>            account_record.append(account)              <br\/>            lot_record.append(lot)<\/pre>\n<h4 class=\"wp-block-heading\" id=\"cfd2\"><strong>Step 3.\u00a0Review<\/strong><\/h4>\n<pre class=\"wp-block-preformatted\">fx['\u50f9\u503c'] = account_record<\/pre>\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/1rI6qwm43O4httt3CAXFKdg.gif\"\/><\/figure>\n<h2 class=\"wp-block-heading\" id=\"78cf\"><strong>Conclusion<\/strong><\/h2>\n<p class=\"wp-block-paragraph\" id=\"58d0\">Here we can see the big drawdown in the middle of our profit line. That is because when we face loss, we will increase our position. But if the price did not go up, we would double the loss. The biggest problem of this strategy is the risk could eat all the profit we earned. Therefore, the risk control is the Martingale users continually dedicate to improve.<\/p>\n<p class=\"wp-block-paragraph\" id=\"508e\">If readers are interested in certain databases, welcome to\u00a0<a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_intro\" rel=\"noreferrer noopener\" target=\"_blank\">E-shop<\/a>\u00a0to choose the optimal plan for yourself !<\/p>\n<p class=\"wp-block-paragraph\" id=\"b253\">The content of this webpage is not an investment device and does not constitute any offer or solicitation to offer or recommendation of any investment product. It is for learning purposes only and does not take into account your individual needs, investment objectives and specific financial circumstances. Investment involves risk. Past performance is not indicative of future performance. Readers are requested to use their personal independent thinking skills to make investment decisions on their own. If losses are incurred due to relevant suggestions, it will not be involved with author.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Source code<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><a class=\"ek-link\" href=\"https:\/\/gist.github.com\/tej87681088\/855eac6900fbbbc7cd979d10d969b6db#file-tejapi_medium_-ipynb\" rel=\"noopener\" target=\"_blank\">Click here to go Github<\/a><\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"8456\"><strong>Extended Reading<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><a class=\"ek-link\" href=\"\/en\/insight\/warren-e-buffetts-value-investing\/\">Warren E. Buffett\u2019s Value Investing<\/a><\/li>\n<li><a class=\"ek-link\" href=\"\/en\/insight\/efficient-frontier\/\">Efficient Frontier<\/a><\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"47b9\"><strong>Related Link<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/api.tej.com.tw\/index.html\" rel=\"noreferrer noopener\" target=\"_blank\">TEJ API<\/a><\/li>\n<li><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_intro\" rel=\"noreferrer noopener\" target=\"_blank\">TEJ E-Shop<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The gambling trading strategy. Highlights Preface \u300cMartingale Strategy\u300dis a popular way of gambling since 18th century. The main method is to double the next bet when we lose this time. By this strategy, if we win the next bet, not only recover previous losses, but also get rewards for the first bet. It sound like [\u2026]<\/p>\n","protected":false},"featured_media":2609,"template":"","tags":[50,65],"insight_category":[13],"class_list":["post-2612","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-market-data","tag-python","insight_category-quant-research"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/2612","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"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/2609"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=2612"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=2612"},{"taxonomy":"insight_category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight_category?post=2612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}