Using Technical Indicators In Python

Victor Sim
Analytics Vidhya
Published in
4 min readAug 15, 2020

--

Introduction:

After making a machine learning algorithm that attempts to predict the future price of forex securities, I thought about trying to automate trading, using theories that originate from technical analysis.

Theory:

The main theory that I tried to recreate was the MA cross concept, basically gathering insights when two moving averages intersect. The two moving averages would be of various ranges. The strategy in question works because, it shows how the current trend is relative to past trends. If the current uptrend is higher than the long term average, it is likely that the price will tend to increase.

Code Run-through:

Step 1| Dependencies:

import requests
import numpy as np
from matplotlib import pyplot as plt
import datetime
API_KEY = 'XXXXX'
from_symbol = 'EUR'
to_symbol = 'USD'

These dependencies are necessary to make calculations and plot results. Fill in the API_KEY variable with your own api key from alpha vantage.

Step 2 | Creating the SMA:

def SMA(prices,value):
means = []
count = 0
while value+count <= len(prices):
pre_val = prices[count:value+count]
count +=1…

--

--

Victor Sim
Analytics Vidhya

Interested in Machine Learning. Open to internships and opportunities. Connect at https://linktr.ee/victorsi.