top of page

Automated TEMA Trading Bot

Automated bot.jpg

Data Scraping

In order to acquire the stock data, trading bot opens the browser and searches for given link. In this case, it goes to investing.com to get the XU100 data. We are using selenium library to automate and get to the webside, on the other hand, BeautifulSoup was used when scraping the data. For the forecasting algorithm that is used, only necessary column would be the price column. Data is acquired from the investing.com, and was written in a csv file that will be read later using pandas library.

Triple Exponential Moving Average(TEMA)

In technical analysis, more renowned forecasting algorithms like moving averages and exponential moving averages seem remain slow at generating signals. Even double exponential moving averages which are much better at recognizing trends but still can be outperformed using triple exponential moving averages. In order to understand the TEMA, exponential moving averages(EMA) have to be understood first.

 

 

EMAToday ​= ​(ValueToday​ ∗ (1 + DaysSmoothing​)) +

EMAYesterday ​∗ (1 − (1 + DaysSmoothing​))​

 

(source: Exponential Moving Average(EMA) by Adam Hayes, Investopedia.com)

EMA at first was invented to be more accurate and, in the case of stock market, to be faster than traditional moving averages(MA). In the formula, DaysSmoothing stands for the period for the forecast and EMAYesterday obviously stands for the EMA value of the previous day. However, it is not possible to calculate an EMA value without having a previous value since it requires an EMAYesterday value. Thereof, first period's EMA value is calculated using traditional MAs. EMA values are calculated because TEMA calculation, in fact, requires three different EMA values.

 

TEMA = (3 ∗ EMA1​) − (3 ∗ EMA2​) + EMA3​

EMA1 = EMA (First EMA value)

EMA2 = EMA of EMA1

EMA3 = EMA of EMA2

(source: Triple Exponential Moving Average by Cory Mitchell, Investopedia.com)

After the calculation of first EMA value(EMA1) equation remains simple. But how does this actually used to get better result compared to other technical analysis tools? Normally a shorter period EMA value moves faster than a longer period EMA value. Likewise, EMA values move faster than MA values of the same period length. For example, a seven days EMA is faster than 15 days EMA and also seven days MA. 

tema gr.png

Technical traders use faster and slower moving forecasted values to define whether there will be an uptrend or downtrend on the graph. For example, when seven days EMA value gets over the 15 days EMA value, it generates a buy signal. In the same way, when 15 days EMA value gets over the seven days EMA value, it generates a sell signal.

Here, same logic is applied for the short and long term TEMA values. If TEMA7 crosses above the TEMA15, TEMA trading bot generates a buy signal and vice versa. In order to be informed by the analysis, trading bot is integrated to the cloud using a server and python's schedule library is used to apply the analysis at certain times of the day.

  • LinkedIn

©2020 by Ufuk Altan | Artificial Intelligence Engineer

bottom of page