Blog

Latest articles about MachineTrader™
Back

Trade IWB on News Sentiment

April 29, 2024

Trade IWB on News Sentiment

Intro

This strategy creates a portfolio of IWB (iShares Russell 1000 ETF) that is bought based on recent news sentiment. The state of the news being reported has an incredible effect on the stock market, as popular reporting agencies can directly increase/decrease people’s optimism about the economy, leading to a snowball effect, of sorts. After all, a positive article can make anyone from a day trader to an amateur trader buy shares in a company. More on this here.

A major challenge to trading based on consumer optimism is the impossibility of assigning a unit of measure to people’s opinions about the economy. While optimism cannot be measured in any real units, we have a different method of measuring consumer sentiment about the economy: when a news article is published, it is given a ranking of -1, 0, or 1 corresponding directly to negative, neutral, or positive in feelings about the economy. To gauge total sentiment in a recent period, these values are averaged. In this way, positive sentiment value indicates consumer optimism whereas a negative sentiment value indicates consumer pessimism.

While we cannot guarantee any particular return on investment due to news, consider this portfolio for an easily managed recurring algorithmic trading strategy. For more information on the stock holdings within IWB, see here.

Strategy

The following image is an example of our prewritten Trade IWB on News Sentiment algorithm.

At start, we run the first flow at the top of the page which defines all of the necessary trading values and tables, to be run once each time an overnight trade algo is created. At the beginning of the flow we see the following two nodes.

 

The inject node titled “GO” is used to begin the flow. Within the first function node titled “Define Trading Values” we see the following block of code, where we define all of the initial parameters of the trade.

On line 6, we define the ticker we would like to trade on.

On line 10, we define the name of the algorithm, to be reported on the front end.

On line 11, we define the initial size of the portfolio, to be reported on the front end.

On line 12, we define whether we would like to use the live or paper Alpaca account.

On line 13, we define the desired number of shares to trade with.

On line 14, we define whether we are trading stocks or crypto.

On line 15, we define whether the algorithm is currently running or not, to be reported on the front end.

On line 16, we define whether the algo is interday or intraday, to be reported on the front end.

On line 17, we define the benchmark for the trade.

Changing any of these values will result in a different trade (i.e. different ticker or size) or a change in front end reporting. For consistency, ensure all values are correct before running. 

These are all of the necessary values that we as algorithmic traders must specify before running a trade. The rest of the nodes in this flow (from the first delay node to the last postgres node) function to store information from the algorithm into tables in postgres in order to update the front end. These nodes need not be altered. 

Moving on to the flows that executes the actual trades, we look at the following buy and sell orders.

To begin with the buy order, we see an inject node followed by a switch node, as shown below.

By default, this algorithm is set to buy IWB five minutes after the market opens, every business day. This timeframe can be altered by double clicking the inject node, and editing the inject time at the bottom of the window. To unlock the gate node (that is, switch it from the “closed” to the “open” position), the “Start News Algo” node must be injected from the home menu. It should be noted that injecting this node will also cause the algo to run; that is, the node titled “9:35 am” need not be injected once the gate is open.

Moving on, we see the following three nodes. The function node titled “trade long or short” contains all of the necessary logic to trade on the aforementioned news sentiment. If it is necessary to change this logic—for example, only execute a trade when the sentiment is above a certain threshold value—it is possible to edit the two “if” statements within the function node. For the most part, it is recommended to use the included logic: that is, trade long when the sentiment is positive and trade short when the sentiment is negative.

Next, we have the sell order flow as shown below.

Similar to the buy order, the sell order is set to run every business day at 3:55pm, just before the market closes. This timeframe can be altered by double clicking the inject node, and editing the inject time at the bottom of the window. At this point, the gate node should already be unlocked, as the “Start News Algo” button from the home page is set to unlock both the buy and sell order.

After the gate node we see a function node titled “prepare Positions query” and an Alpaca node with the purpose of attaining the current holdings of IWB. Depending on whether we are holding a long or short position during the day, the algorithm will respectively sell or buy these positions at the end of the day in order to close all positions. All of this logic is taken care of in the function node titled “close positions (single ticker),” and executed with the Alpaca node. 

With this, we now have an algorithm that trades IWB intraday based on the recent news sentiments.

Other Features

The Trade IWB on News Sentiment flow contains one more feature worth mentioning. By injecting the following flow, we are able to see a summary of the trading values defined above in the node titled “Define Trading Values,” printed in the debug window.

If we are interested in seeing the current news sentiment value, we inject the following flow to display the number in the debug window.

NOTE: ALL STRATEGIES ARE PROVIDED FOR ILLUSTRATIVE PURPOSES ONLY AND SHOULD NEVER BE IMPLEMENTED IN LIVE TRADING ACCOUNTS WITHOUT CAREFUL REVIEW. MACHINETRADER IS NOT RESPONSIBLE FOR TRADING LOSES INCURRED AS A RESULT OF CODING ERRORS.

BY
Dan Savage

January 18, 2024

Interest in Bitcoin ETFs Falls Fast on the 3rd Day of Trading

Trading activity in the new Bitcoin ETFs fell rapidly yesterday. While several of the ETFs made it into the top 5 most heavily traded ETFs on Friday, interest on Tuesday, when trading resumed after the MLK holiday, the bloom was off the rose.

>Read More

January 15, 2024

Bitcoin ETFs Debut with a Splash

The long-awaited Bitcoin ETFs debuted in yesterday's trading, making quite a splash. Three Bitcoin ETFs were among the five most actively traded ETFs: GBTC, IBIT, and FBTC, all trading more than 10 million shares.

>Read More

January 15, 2024

Day Trading

Day trading is a trading strategy where traders buy and sell securities within the same trading day taking advantage of short-term price fluctuations in various assets to make quick profits. Day traders aim to capitalize on small price movements by entering and exiting positions multiple times throughout the day.

>Read More

January 15, 2024

Day Trading Strategies

Day traders employ a variety of strategies in the quest to make profitable trades. This is a list of the more common ones:

>Read More

January 15, 2024

Quantitative Trading

Quantitative trading, also known as algorithmic trading or algo trading, is a method of trading financial assets using advanced mathematical and statistical models. It involves the use of computer algorithms to execute trades based on predefined rules and strategies. This approach to trading has gained significant popularity in recent years, with many institutional investors and hedge funds adopting it as an integral part of their investment strategies.

>Read More

January 15, 2024

Swing Trading

Swing trading is a popular trading strategy that involves taking advantage of short-term price movements or "swings" within a larger trend. Swing traders aim to capture gains by entering and exiting positions over a period of days or weeks, rather than holding positions for months or years like long-term investors.

>Read More

January 15, 2024

Algorithmic Trading

The main objective of algorithmic trading is to maximize profits by taking advantage of short-term market inefficiencies. It aims to exploit price discrepancies, liquidity imbalances, and other temporary market conditions that might arise within fractions of a second. By automating the trading process, algorithmic trading eliminates human emotions and biases, enabling faster and more efficient execution of trades.

>Read More

January 15, 2024

Trade on MACD-QQQ

This strategy creates a portfolio of QQQ (Invesco Trust Series 1) that is traded in correspondence with logic defined by the Moving Average Convergence/Divergence (MACD) lagging indicator. The MACD strategy is a commonly employed algorithmic trading strategy, and can be calculated using Exponential Moving Averages (EMAs) by hand using the following formulas.

>Read More

April 29, 2024

Trade IWB on News Sentiment

This strategy creates a portfolio of IWB (iShares Russell 1000 ETF) that is bought based on the recent news sentiments. The state of the news being reported has an incredible effect on the stock market, as popular reporting agencies can directly increase/decrease people’s optimism about the economy, leading to a snowball effect, of sorts.

>Read More

January 17, 2024

Build a Crypto ETF in MachineTrader™

Building custom ETFs using MachineTrader™ visual programming toolkit is easy to do and often an effective way to enhance your portfolio. While technically these aren’t algorithmic trading strategies, you can easily add flows that will optimize the ETF based on performance of the individual assets.

>Read More

January 17, 2024

Introducing - Independent Trading Platforms

The latest significant change in the investment world is the rise of what we call, "independent trading platforms" (ITPs). These are software platforms whose user-friendly web and mobile applications provide all of the functionality of trading platforms, but pass the actual trade executions off, through an API, to the registered broker-dealer of the user's choice.

>Read More

January 17, 2024

Why MachineTrader™?

Monitoring minute-by-minute (or second-by-second) changes in time series charts of prices is a pretty tedious task. While a number of trading platforms offer off-the-shelf algorithms or bots for automating strategies, we've found that it's hard to make money using an algo that other traders are employing, or worse, other traders have programmed to work against.

>Read More

January 17, 2024

Trading Stocks, Cryptos and Pattern Day Trading

You're a newbie to trading and you open your Robinhood account and begin to actively trade fractional shares of Tesla (TSLA). Your first dozen trades of the day work great as you pick the best moments to buy and sell. All of a sudden your account is flagged with a 'pattern day trader' warning.

>Read More