/TradingAlgorithms

Financial trading Algorithms 1. Moving Average 2. Bollinger Bands

Primary LanguagePython

TradingAlgorithms

This project repository describes and implementation of below Financial trading Algorithms

  1. Moving Average
  2. Bollinger Bands

Moving Average Algorithms

In statistics a moving average is an algorithm that calculates the unweighted mean of the last n samples.

Types: Simple Moving Average (SMA) Exponential Moving Average (EMA)

Simple Moving Average Algorithm(SMA)

  • The SMA is a technical indicator for determining if an asset price will continue or reverse a bull or bear trend.
  • The SMA is calculated as the arithmetic average of an asset's price over some period.
  • The SMA can be enhanced as an exponential moving average (EMA) that more heavily weights recent price action.

Popular Trading Patterns

Death Cross A short-term moving average breaks below a long-term moving average Golden Cross A short-term moving average breaks above a long-term moving average

Where Short-term moving average: 50 days Long-term moving average: 200 days

Exponential Moving Average(EMA)

  • The EMA is a moving average that places a greater weight and significance on the most recent data points.
  • Like all moving averages, this technical indicator is used to produce buy and sell signals based on crossovers and divergences from the historical average.
  • Traders often use several different EMA days, for instance, 20-day, 30-day, 90-day, and 200-day moving averages.

Steps to calculate EMA

  1. Find the Initial EMA Value E.g., 14 + 13 + 14 + 12 + 13 = 66; 66 ÷ 5 = 13.2 So the SMA, which becomes your initial EMA value, is 13.2.
  2. Calculate the Weighting Multiplier (Smoothing Constant) 2 ÷ (number of time periods + 1) 2 ÷ (5 + 1) = 2 ÷ 6 = 0.3333
  3. Input That Information in the EMA Formula EMA = (closing price - previous day's EMA) × smoothing constant as a decimal + previous day's EMA EMA = (12 - 13.2) × 0.3333 + 13.2 EMA = 12.80 So the EMA value for day six is 12.80.
  4. If the closing value on day seven was $11, you'd repeat the process, using day six's value of 12.80 as the new "previous day's EMA." So the calculation for day seven is as follows: EMA = (11 - 12.8) × 0.3333 + 12.8 EMA = 12.20

Bollinger Bands Algorithm

  • A Bollinger Band® is a technical analysis tool defined by a set of lines plotted two standard deviations (positively and negatively) away from a SMA of the security's price, but can be adjusted to user preferences.
  • There are three lines that compose Bollinger Bands: A simple moving average (middle band) and an upper and lower band.
  • The upper and lower bands are typically 2 standard deviations +/- from a 20-day simple moving average, but can be modified.

Project Setup

Download or clone the project into the local machine and edit the configuration file (config.json) by follow:

  1. Change the tradeURL with the your trading data provider URL.
  2. change the algorithm band period as per your need.

How to Run the Project?

Once projct set up is done, running this project is much easier as like running python projects.

  1. Open the command prompt and navigate to the project location.
  2. type the below command to run this project. python movingAverage.py

This command will run the project http://localhost:5000

URLs

  1. Simple Moving Average (SMA) - http://localhost:5000
  2. Exponential Moving Average (EMA) - http://localhost:5000/ema
  3. Bollinger Bands - http://localhost:5000/bollingerbands

Author: Shivakumar Ravichandran