{"id":228523,"date":"2025-08-07T11:40:20","date_gmt":"2025-08-07T15:40:20","guid":{"rendered":"https:\/\/ibkrcampus.com\/campus\/?p=228523"},"modified":"2025-08-07T11:42:05","modified_gmt":"2025-08-07T15:42:05","slug":"using-technical-indicators-with-tws-api","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/","title":{"rendered":"Using Technical Indicators with TWS API"},"content":{"rendered":"\n<p>Technical analysis is a very important concept for traders who look to make short-term trades or for full-time day traders seeking to identify potential entry and exit positions in the market. The TWS API provides a powerful way to implement these tools programmatically. While TWS charts offer a wide range of built-in indicators, in this article, I&#8217;ll walk you through implementing one of these indicators using the Python TWS API.<\/p>\n\n\n\n<p>The Relative Strength Index (RSI) is one of the most widely used indicators in technical analysis. RSI helps traders identify potential overbought or oversold conditions in the market for a financial instrument. It&#8217;s calculated using average gains and losses over a specified period, usually 14 days, but this can vary depending on the timeframe of the position the trader is looking to take.<\/p>\n\n\n\n<p>Before diving into the code, please make sure that you have TWS or IB Gateway running and a good understanding of Python programming and pandas libraries. Optionally, a basic understanding of technical indicators will help you better understand the code we&#8217;re about to write.<\/p>\n\n\n\n<p>The implementation of RSI consists of 3 main parts: a custom wrapper class that handles API callbacks, a function that calculates the RSI, and a main application that retrieves data and processes it. Let&#8217;s start by importing the necessary libraries:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from ibapi.client import EClient\nfrom ibapi.wrapper import EWrapper\nfrom ibapi.contract import Contract\nimport pandas as pd\nimport time\nfrom threading import Thread\nimport datetime<\/pre>\n\n\n\n<p>Next, we create a custom class that inherits from EClient and EWrapper, which handles the requests and responses from the TWS Server. We override the historicalData method which processes historical data bars. The historicalData method returns a bar object with \u00ad\u00adattributes like TIME, OPEN, HIGH, LOW, CLOSE, and VOLUME. For our RSI calculation, we only need TIME and CLOSE. The bar object&#8217;s TIME attribute is formatted as YYYYMMDD, but we convert it to a datetime object for better readability.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class IBapi(EWrapper, EClient):\n    def __init__(self):\n        EClient.__init__(self, self)\n        self.data = []\n        \n    def historicalData(self, reqId, bar):\n        # Format the date properly (IB returns dates in a strange format)\n        date_str = bar.date\n        \n        # Handle different date formats from IB\n         # YYYYMMDD format\n        formatted_date = datetime.datetime.strptime(date_str, \"%Y%m%d\")\n        \n        # Append data\n        self.data.append([formatted_date, bar.close])\n        print(f\"Received bar: Date={formatted_date}, Close={bar.close}\")\n<\/pre>\n\n\n\n<p>For the next step, we create a function that calculates the RSI. For better readability and convenience, we use the pandas library. Our function takes a pandas dataframe as a parameter, and the second parameter is the time period for the RSI calculation (defaulting to 14 days). We calculate the difference in closing prices and assign that to a new column &#8220;change&#8221;. Then we create two new columns &#8220;gain&#8221; and &#8220;loss&#8221; which contain the positive and negative price changes respectively. Finally, we calculate the mean of gains and losses over the specified time period and calculate RSI using the standard formula.\u00ad\u00ad\u00ad<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def calculate_rsi(df, periods=14):\n    # Calculate price changes\n    df['change'] = df['close'].diff()\n    \n    # Create gains and losses series\n    df['gain'] = df['change'].clip(lower=0)\n    df['loss'] = -1 * df['change'].clip(upper=0)\n    print(df.head())\n    # Calculate average gain and loss over the specified period\n    avg_gain = df['gain'].rolling(window=periods).mean()\n    avg_loss = df['loss'].rolling(window=periods).mean()\n    \n    # Calculate RS and RSI\n    rs = avg_gain \/ avg_loss\n    df['rsi'] = 100 - (100 \/ (1 + rs))\n    \n    \n    return df\n<\/pre>\n\n\n\n<p>The main application connects to TWS\/IB Gateway, retrieves historical data, and calculates the RSI. This function manages the connection to TWS, retrieves historical data, calculates the RSI, and interprets the result. We run the socket connection in a separate thread to prevent blocking, which is a common pattern when working with the TWS API.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def run_app():\n    # Connect to TWS\n    app = IBapi()\n    app.connect('127.0.0.1', 7497, 0)  # Use 7496 for TWS, 7497 for IB Gateway\n    \n    # Start the socket in a thread\n    api_thread = Thread(target=app.run)\n    api_thread.start()\n    time.sleep(0.5)  # Give time for connection to establish\n    \n    # Define the contract for the stock\n    contract = Contract()\n    contract.symbol = \"PLTR\"  # Change to your stock symbol\n    contract.secType = \"STK\"\n    contract.exchange = \"SMART\"\n    contract.currency = \"USD\"\n    \n    # Request historical data\n    app.reqHistoricalData(1, contract, \"\", \"15 D\", \"1 day\", \"TRADES\", 0, 1, False, [])\n    time.sleep(0.5)  # Wait for data to be received\n    \n    # Process the data\n    df = pd.DataFrame(app.data, columns=['date', 'close'])\n    df = df.sort_values('date')\n    df = calculate_rsi(df)\n    \n    # Display results\n    valid_rsi = df.dropna(subset=['rsi'])\n    print(f\"Recent RSI for {contract.symbol}: {valid_rsi['rsi'].iloc[-1]:.2f}\")\n    \n    \n    app.disconnect()\n\nif __name__ == \"__main__\":\n    run_app()\n<\/pre>\n\n\n\n<p>This is a straightforward implementation of RSI using the TWS API. We&#8217;ve utilized different libraries to make our code concise and readable. You could enhance this by using other technical analysis libraries like TA-Lib, incorporating this into a trading class to make trades based on RSI signals, changing the time period to fit your trading strategy, or combining RSI with other indicators like moving averages, Bollinger bands, or volume indicators.<\/p>\n\n\n\n<p>Remember that RSI is just one indicator among many that traders utilize to make decisions, and it&#8217;s often used in conjunction with other technical tools. Feel free to include print statements in different parts of the code to observe how the dataframe changes during the execution process. This implementation provides a solid foundation for exploring technical analysis with the TWS API, allowing you to build more sophisticated trading tools and strategies.<\/p>\n\n\n\n<p>The complete code should appear as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from ibapi.client import EClient\nfrom ibapi.wrapper import EWrapper\nfrom ibapi.contract import Contract\nimport pandas as pd\nimport time\nfrom threading import Thread\nimport datetime\n\nclass IBapi(EWrapper, EClient):\n    def __init__(self):\n        EClient.__init__(self, self)\n        self.data = []\n        \n    def historicalData(self, reqId, bar):\n        # Format the date properly (IB returns dates in a strange format)\n        date_str = bar.date\n        \n        # Handle different date formats from IB\n         # YYYYMMDD format\n        formatted_date = datetime.datetime.strptime(date_str, \"%Y%m%d\")\n        \n        # Append data\n        self.data.append([formatted_date, bar.close])\n        print(f\"Received bar: Date={formatted_date}, Close={bar.close}\")\n\ndef calculate_rsi(df, periods=14):\n    # Calculate price changes\n    df['change'] = df['close'].diff()\n    \n    # Create gains and losses series\n    df['gain'] = df['change'].clip(lower=0)\n    df['loss'] = -1 * df['change'].clip(upper=0)\n    print(df.head())\n    # Calculate average gain and loss over the specified period\n    avg_gain = df['gain'].rolling(window=periods).mean()\n    avg_loss = df['loss'].rolling(window=periods).mean()\n    \n    # Calculate RS and RSI\n    rs = avg_gain \/ avg_loss\n    df['rsi'] = 100 - (100 \/ (1 + rs))\n    \n    return df\n\ndef run_app():\n    # Connect to TWS\n    app = IBapi()\n    app.connect('127.0.0.1', 7496, 0)  # Use 7496 for TWS, 7497 for IB Gateway\n    \n    # Start the socket in a thread\n    api_thread = Thread(target=app.run)\n    api_thread.start()\n    time.sleep(0.5)  # Give time for connection to establish\n    \n    # Define the contract for the stock\n    contract = Contract()\n    contract.symbol = \"PLTR\"  # Change to your stock symbol\n    contract.secType = \"STK\"\n    contract.exchange = \"SMART\"\n    contract.currency = \"USD\"\n    \n    # Request historical data\n    app.reqHistoricalData(1, contract, \"\", \"15 D\", \"1 day\", \"TRADES\", 0, 1, False, [])\n    time.sleep(0.5)  # Wait for data to be received\n    \n    # Process the data\n    df = pd.DataFrame(app.data, columns=['date', 'close'])\n    df = df.sort_values('date')\n    df = calculate_rsi(df)\n    \n    # Display results\n    valid_rsi = df.dropna(subset=['rsi'])\n    print(f\"Recent RSI for {contract.symbol}: {valid_rsi['rsi'].iloc[-1]:.2f}\")\n    \n    app.disconnect()\n\nif __name__ == \"__main__\":\n    run_app()\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Relative Strength Index (RSI) is one of the most widely used indicators in technical analysis.<\/p>\n","protected":false},"author":186,"featured_media":228534,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":true,"footnotes":""},"categories":[339,340,343,349,338,341],"tags":[851,806,1014,1015,575,1224,595,16878,1545],"contributors-categories":[13576],"class_list":{"0":"post-228523","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-api-development","9":"category-programing-languages","10":"category-python-development","11":"category-ibkr-quant-news","12":"category-quant-development","13":"tag-algo-trading","14":"tag-data-science","15":"tag-eclient","16":"tag-ewrapper","17":"tag-ibkr-api","18":"tag-pandas","19":"tag-python","20":"tag-relative-strength-index-rsi","21":"tag-technical-indicators","22":"contributors-categories-interactive-brokers"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Using Technical Indicators with TWS API | IBKR Quant<\/title>\n<meta name=\"description\" content=\"The Relative Strength Index (RSI) is one of the most widely used indicators in technical analysis.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/228523\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Technical Indicators with TWS API\" \/>\n<meta property=\"og:description\" content=\"The Relative Strength Index (RSI) is one of the most widely used indicators in technical analysis.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-07T15:40:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-07T15:42:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2025\/08\/rsi-api.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Contributor Author\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Contributor Author\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Contributor Author\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/e823e46b42ca381080387e794318a485\"\n\t            },\n\t            \"headline\": \"Using Technical Indicators with TWS API\",\n\t            \"datePublished\": \"2025-08-07T15:40:20+00:00\",\n\t            \"dateModified\": \"2025-08-07T15:42:05+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/\"\n\t            },\n\t            \"wordCount\": 610,\n\t            \"commentCount\": 3,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2025\\\/08\\\/rsi-api.jpg\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"Data Science\",\n\t                \"EClient\",\n\t                \"EWrapper\",\n\t                \"IBKR API\",\n\t                \"Pandas\",\n\t                \"Python\",\n\t                \"Relative Strength Index (RSI)\",\n\t                \"technical indicators\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"IBKR API Development\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/\",\n\t            \"name\": \"Using Technical Indicators with TWS API | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2025\\\/08\\\/rsi-api.jpg\",\n\t            \"datePublished\": \"2025-08-07T15:40:20+00:00\",\n\t            \"dateModified\": \"2025-08-07T15:42:05+00:00\",\n\t            \"description\": \"The Relative Strength Index (RSI) is one of the most widely used indicators in technical analysis.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-technical-indicators-with-tws-api\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2025\\\/08\\\/rsi-api.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2025\\\/08\\\/rsi-api.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"RSI API\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/e823e46b42ca381080387e794318a485\",\n\t            \"name\": \"Contributor Author\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/contributor-author\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using Technical Indicators with TWS API | IBKR Quant","description":"The Relative Strength Index (RSI) is one of the most widely used indicators in technical analysis.","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:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/228523\/","og_locale":"en_US","og_type":"article","og_title":"Using Technical Indicators with TWS API","og_description":"The Relative Strength Index (RSI) is one of the most widely used indicators in technical analysis.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/","og_site_name":"IBKR Campus US","article_published_time":"2025-08-07T15:40:20+00:00","article_modified_time":"2025-08-07T15:42:05+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2025\/08\/rsi-api.jpg","type":"image\/jpeg"}],"author":"Contributor Author","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Contributor Author","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/"},"author":{"name":"Contributor Author","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/e823e46b42ca381080387e794318a485"},"headline":"Using Technical Indicators with TWS API","datePublished":"2025-08-07T15:40:20+00:00","dateModified":"2025-08-07T15:42:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/"},"wordCount":610,"commentCount":3,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2025\/08\/rsi-api.jpg","keywords":["Algo Trading","Data Science","EClient","EWrapper","IBKR API","Pandas","Python","Relative Strength Index (RSI)","technical indicators"],"articleSection":["Data Science","IBKR API Development","Programming Languages","Python Development","Quant","Quant Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/","name":"Using Technical Indicators with TWS API | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2025\/08\/rsi-api.jpg","datePublished":"2025-08-07T15:40:20+00:00","dateModified":"2025-08-07T15:42:05+00:00","description":"The Relative Strength Index (RSI) is one of the most widely used indicators in technical analysis.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-technical-indicators-with-tws-api\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2025\/08\/rsi-api.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2025\/08\/rsi-api.jpg","width":1000,"height":563,"caption":"RSI API"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/e823e46b42ca381080387e794318a485","name":"Contributor Author","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/contributor-author\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2025\/08\/rsi-api.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/228523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/186"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=228523"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/228523\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/228534"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=228523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=228523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=228523"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=228523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}