KiteRange
A light standalone autonomous trading module which trades intraday range breakouts.
Background
KiteRange is a simple yet robust module that allows users who have minimal knowledge about programming, Python or the KiteConnect API to get started with system trading.The module implements a proven intraday range breakout strategy. Here is how it works: during a trading day, first the stock range is established, then a breakout of the said range is traded in the breakout's direction with trailing stop loss.
In the interest of keeping full control in the hands of the trader, an ABORT method has been implement to exit the trade and all orders associated with it at the user's discretion. Also, a part-squareoff method to discretionarily exit part of a position prematurely. The system automatically exits at a user-prescribed time. Check workflow below for more.
Download
Visit the Download section to get the setup script. Chose(2) KiteBase & KiteRange
during installation. You will need a secret code to install
the package onto your system. Please contact me @harshnisar on Twitter or Telegram for the code.
Workflow
KiteRange has been built to require minimum commands to get going. KiteRange uses KiteBase as a dependency. Simply follow the steps below:-
Import modules
>> from Instance import Instance
>> from Range import Range
-
Generate an Instance
>> I = Instance()
-
Start the strategy using Range
>> infy = Range(I,'INFY')
With these steps, once every day, your strategy is up and running. It will wait till the intraday range is defined. Then it will fire orders to enter trades in the direction of breakout in both direction (long/short). Once an order is traded, a subsequent square-off trailing stop loss order will be fired. The stop loss will be trailed throught the day till the strategy is live. Before the day close, any active positions will be squared off and any open orders will be cancelled.
If you are a new KiteConnect user, please start with the
headless
flag set to False
so as to manually authorize KiteConnect to link to Kite.
See the Information section for more details.
Information
-
Range Module: The strategy is run by this.
-
Range Object: For set of input parameters, like instrument, quantity etc. create an object with default arguements.
infy = Range(I, 'INFY', Q=100)
sbin = Range(I, 'SBIN', Q=400)
-
Quantity
Q
: The number of shares to be traded. -
Ticker: this is an area of future developement. For now pass null.
infy = Range(I, 'INFY', Q=100, ticker=None)
-
Restart: use the
fresh
attribute to restart the module in case if it was exit unexpectedly.infy = Range(I, 'INFY', Q=100, ticker=None, fresh=False)
-
Signals only: The
no_trade
attribute will be used in conjunction withTicker
for future developement. For now passFalse
infy = Range(I, 'INFY', Q=100, ticker=None, fresh=False, no_trade=False)
-
Time: Setup various times of interest:
-
start_time
: Opening Bell -
end_time
: Closing Bell -
define_time
: Time when the instrument's range is defined -
square_time
: Time when everything is exit.
infy = Range(I, 'INFY' ,Q=100 ,ticker=None ,fresh=True, no_trade=False, define_time='09:25', square_time='15:17', start_time='09:15', end_time='15:30', verbose=False)
-
-
Verbosity: Print verbose updates to console with
verbose=True
-
Orders: The
orders
attributre stores a dictionary of active orders and the time when they were traded (if they were traded)
>> infy.orders
might return
{'long': ['123456789123456', '11:25:02'],
'short': ['123456789123457', '14:25:07'],
'sqlong': ['123456789123458', '14:20:19'],
'sqshort': ['123456789123459', '']} -
Restarting: In case for some unforeseen reason, if a session crashes, then to fetch the state prior to crashing back again, pass
fresh=True
as discussed above. This goes through the order books and finds relevant orders and populates theorders
attribute. Once you approve orders, it restarts the strategy. -
Abort: To prematurely close all open orders and exit positions, call
abort
>> infy.abort()
-
Part Square-off: To prematurely exit part of an existing position call
part_sqoff
Say the strategy has bought 100INFY
. If the user decides to square off 50 of those, run>> infy.part_sqoff(50)
The order in the other direction will stay open with the initally called quantity. - MIS Assumption: The system defaults to ordering stock underlying using the MIS product. This is the ideal application for MIS where the leverage is usually greater than that for derivative products.
-
Range Object: For set of input parameters, like instrument, quantity etc. create an object with default arguements.