Why Algo Trading?
The Algo Trading system is designed to help traders avoid impulsive decisions driven by emotions like greed and fear.
By following a structured approach, it aims to improve trading discipline and potentially enhance trading results.
Introduction
Algo Trading with Zerodha Kite is a Python-based algorithmic trading system that helps traders make informed decisions while trading options on the NSE (National Stock Exchange) platform. This system aims to eliminate emotional trading and provide a structured approach to option trading.
Repository Contents
This GitHub repository, named "Algo_Trading" contains the following Python files:
- Intraday_Option_trading.py:
This file likely contains the core logic for intraday option trading.
- kite_trade.py:
This file is responsible for interacting with the Zerodha Kite API to execute trades.
- TESTing.py:
This file acts as the main interface for users to input their trading parameters and execute option trades.
How to use
To use this algorithmic trading system, follow these steps:
-
Clone the Repository:
Clone the GitHub repository "Algo_Trading" to your local machine.
-
Set Up API Credentials:
You do not need to provide the Zerodha Kite API Key; provide only the enctoken. Here's how to obtain it:
-
Log in to your Zerodha Kite account.
-
Right-click anywhere on the page and select "Inspect" to open the browser's developer tools.
-
Go to the "Network" tab.
-
Press Ctrl+R to reload the page.
-
Click on the "position" request in the network traffic list.
-
In the "Headers" section, locate the "Authorization" header. The enctoken will be found here.
-
Run TESTING.py:
After placing all three Python files in the same directory and providing the enctoken, run the TESTing.py file.
-
Follow the Prompts:
The script will prompt you to make several choices:
-
Choose the instrument (NSE:NIFTY FIN SERVICE, NSE:NIFTY BANK, NSE:NIFTY 50, NSE:NIFTY MID SELECT) by selecting 0, 1, 2, or 3.
-
Choose Call (CE) or Put (PE) options by entering 0 or 1.
-
elect At The Money (ATM), In The Money (ITM), or Out of The Money (OTM) options in the same way.
-
Decide whether you want to Buy or Sell the selected option.
-
Set a Stop Loss (sl) and a Target. If you select 0 as the target, the system will trail the stop loss.
-
If you put a target other than 0, the system will trail the stop loss as explained in the description.
-
If you want to do virtual trade coose 0 otherwise choose 1.
-
Execute the Trade:
The system will execute the chosen option trade based on your inputs and continuously manage the trade according to your specified stop loss and target parameters.
Let's walk through an example of how trailing stop loss works in your Algo Trading system using the parameters you provided:
Suppose you decide to sell a NIFTY23SEP19700CE option for 50 rupees. You set a Stop Loss (sl) of 5 rupees and a Target of 0 (indicating you want to trail the stop loss).
Here's how the trailing stop loss would work:
-
Initial Setup:
-
You sell the NIFTY23SEP19700CE option for 50 rupees.
-
Your initial stop loss is set at 5 rupees. That is initial exit price is 55 rupees.
-
Your initial target is set to 0 (indicating trailing stop loss).
-
Price Movements:
-
If the Last Traded Price (LTP) increases to 55 rupees, your exit price remains at 55 rupees, and you book a loss (since your stop loss is 5 rupees above the entry price).
-
If the LTP decreases to 45 rupees, your exit price is adjusted to 50 rupees (the original entry price), and you still in the position.
-
If the LTP decreases further to 40 rupees, your exit price is adjusted to 45 rupees. At this point, if the price increases to 45 rupees, you book a profit of 5 rupees.
-
If the LTP decreases to 35 rupees, your exit price is adjusted to 40 rupees, and so on. The stop loss is constantly adjusted as the LTP moves in your favor.
-
railing Stop Loss Activation:
-
As long as the LTP keeps decreasing and your exit price is adjusted downwards, the trailing stop loss remains in effect.
-
Profit Booking:
-
If the LTP increases and hits your exit price, you exit the trade. For example, if the LTP reaches 55 rupees, you book a loss of 5 rupees.
-
If corrent time is more than 3:20pm then it will close the trade.
-
If you provide target as 2, then if LTP hit your target , it will book the profit and close the position.
The key idea is that the trailing stop loss adapts to market conditions. It moves in your favor as the price goes in your favor but remains static when the price goes against your favor, allowing you to potentially capture more profit while protecting yourself from significant losses.
Remember that trailing stop loss can be a useful strategy, but it doesn't guarantee profits, and it's essential to carefully consider your risk tolerance and overall trading plan. It will only stop your loss what you decided before taking a trade.