This python script gets the stocks scanned by Mean Reversion scanner from Vishal Mehta. Once the stocks are available, it places AMO (After Market Order) in Zerodha Trading account using kiteconnect
APIs.
The scanner can be located on chartink https://chartink.com/screener/vishal-mehta-mean-reversion
If available stocks are more than 10 then the stocks are sorted according to latest close price ascending and only 10 orders are placed.
- Download the repository as zip
- Unzip / extract it in a folder preferably on
D:\trading
Avoid extracting on Desktop
- Install Python 3.9.4 latest version as of today (25th April 2021)
- It can work on python 3.6 and above but it is not tested
-
python -m pip install virtualenv
on Windows orpython3 -m pip install --user virtualenv
on Linux -
Go to the folder
D:\trading
and then create virtualenv asvenv
using command aspython -m virtualenv venv
on Windows orpython3 -m virtualenv -p py3 venv
on Linux -
Activate the virtual environment using
.\venv\Scripts\activate
on Windows orsource ./venv/bin/activate
on Linux/Mac. -
Upgrade packages using command
python -m pip install -U pip wheel setuptools
-
pip install .\Twisted-21.2.0-py3-none-any.whl
(MANDATORY on Windows, to install kiteconnect successfully.) -
pip install .\TA_Lib-0.4.19-cp39-cp39-win_amd64.whl
(OPTIONAL on Windows) -
pip install -r requirements.txt
(NOTE : There is issue while installing pandas on python 3.6.9 downgrade pandas version to 1.1.5)
- Before running the script, it is very important to generate the
enctoken.txt
file which is used inconfig.py
file - There are 2 ways to do this
- Copy Paste the enctoken from Zerodha Web Session using Chrome DevTools, check images in useful snapshots
- Another way to do this is to run the
login_and_generate_enctoken.py
script, this must be done once. May have to run again if you invalidate the session. Run this again if you face any issues. This step will invalidate your web session if you have logged in through browser.
- Before running the actual script
chartink_kite.py
you must create .env file same folder - Copy the .env.example file or rename it to create a new .env file in the same folder
- Change the values for USERNAME, PASSWORD and PIN with your own credentials
- Finally you can run the script using
python chartink.py
orpython3 chartink.py
- Some lines are commented since this code is not tested in Live Market
- Stop Loss for the Strategy is not implemented in the script, 3% Stop Loss recommended by Vishal Mehta, people have posted that 4% works better but some people keep Stop Loss based on their own Risk e.g. 2% to 2.5%
- Similarly, Target or Profit must be kept accordingly to your own Risk Management. Vishal Mehta recommends 6% while some keep it at 4.5%
- Also, some people exit when the overall MTM / PnL reaches approximately 5% or 6% of invested capital.
- More images will be added in future. Please check existing images.
- Coding is still in progress, for any suggestions please open discussions here.
-
Cloning repository, creating virutalenv and installing packages
-
Activating Virtual environment venv
-
Installing all requirements from
requirements.txt
using pip -
Below images there is an error which occurred because the session was expired. New enctoken was added to
enctoken.txt
file -
Getting the enctoken from the kite dashboard using Chrome DevTool. Copy paste it to enctoken.txt This will help to keep both web session running and script execution will not invalidate web session
-
Kite dashboard orders page before placing AMO orders.