I have created a simple breakout strategy based on my last pinescript code in python. For those who are new to python I strongly suggest you to have your basics brushed up. You can learn basics from my book "Python for Non-Programmers".
Basics of Python
Python have many modules that you may install and use. One of them allows to work on data like you are working on spreadsheet while other allows you to store data like a spread sheet. These useful modules are :
1. pandas : Allows storage as if it is a spread sheet and retrival of data from this virtual spread sheet known as Dataframe.
2. numpy : useful for manupulation of dataframe data
Installing the above two modules in your Python Environment
Installation of modules in python is simple, it can be installed from your command prompt or power shell. Below is an example wherein a module named “pandas” is installed on the system.
For installation of any module just type “pip installed” followed by the name of the module.
pip install [name of module]
You can do practice by installing the the other module “numpy”. In case you copy a code from somewhere, it gives an error like some function is not available. It is most likely that a module is missing and you have not installed it.
If a module is not included, assuming you people are using pycharm IDE, it will highlight missing functions with a red underline.
Downloading Data For BackTesting
I am using API provided by my broker (5Paisa in India) for live feed and historical data. The data feed should be reliable with no breaks.Here in this example either you can download data from yahoo through python or can use already downloaded file for analysis.
In case you want to learn How to download Data from Yahoo, I will explain in separate blog post.
Here in this example, I am using a csv file already available with me. It looks like :