KiteSwing
A light standalone autonomous trading module which takes positional trades.
Background
KiteSwing 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 trend following positional strategy. Here is how it works: underlying's closing above or below a set of moving averages is traded to take a long or short position respectively.
In the interest of keeping full control in the hands of the trader, an ABORT method has been implement to exit the strategy, at the user's discretion, while keeping the positions active. Check workflow below for more.
Download
Visit the Download section to get the setup script. Chose(3) KiteBase & KiteSwing
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
KiteSwing has been built to require minimum commands to get going. KiteSwing uses KiteBase as a dependency. Simply follow the steps below:-
Import modules
>> from Instance import Instance
>> from Swing import MultiSwing
-
Generate an Instance
>> I = Instance()
-
Initiate the strategy
>> MS = MultiSwing(I,setups=[('NIFTY BANK')])
With these steps, your positional strategy is up and running. At the finish of the first candle, it will match you position with the theoritical position. Then it will check for signals when each new candle is generated. It will trade signals a few moments after the candle is generated. Right before Closing Bell, it'll try to anticipate signals, and will premptively trade if it concludes there might be one.
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
-
MultiSwing Module: The strategy is run by this.
-
Range Object: For set of input parameters, like instrument, create an object with default arguements. Pass setups as a list of tuples.
Append
'_F'
to the scrip's tradingsymbol if you intend to generate signals on the underlying and trade future instrument, this is not required for index futures.MS = MultiSwing(I, setups=[('NIFTY 50'), ('SBIN_F')])
-
Interval: The candle duration
MS = MultiSwing(I, setups=[('SBIN', '15minute')])
-
Averages: a string of EMAs, 'C' for close,'L' for low, 'L' for high followed by a number for the number of candles to take average for.
MS = MultiSwing(I, setups=[('SBIN', '15minute', 'C10,H20,L20')])
-
Signals only: pass
True
to just get signals, an to trade on signals, else pass False.MS = MultiSwing(I, setups=[('SBIN', '15minute', 'C10,H20,L20', False)])
-
Quantity: pass the number of lots to trade.
MS = MultiSwing(I, setups=[('SBIN', '15minute', 'C10,H20,L20', False, 300)])
-
Previous Position: pass the actual position when initiating the strategy. Pass False if you are starting afresh, and if for some reason you a running the code while a position has already been taken, pass the position in terms on no. of lots.
MS = MultiSwing(I, setups=[('SBIN', '15minute', 'C10,H20,L20', False, 300, 50)])
-
Rollover: on expiry day pass
False
if rollover is already done, so the module doesn't seek to rollover again when the strategy is initiated, else pass TrueMS = MultiSwing(I, setups=[('SBIN', '15minute', 'C10,H20,L20', False, 300, 50, True)])
-
Hours: Input Opening and Closing bell, (for special days):
-
start_time
: Opening Bell -
end_time
: Closing Bell
MS = MultiSwing(I, setups=[('SBIN', '15minute', 'C10,H20,L20', False, 300,50, True)], hours= ('09:15','15:30'))
-
-
Setups: The
setups
attribute stores a dictionary of active setups with the setup number.
>> MS.setups
might return
{0: ('NIFTY BANK', '15minute', 'C10,H20,L20', False, 1, False, True),
1: ('SBIN_F', '60minute', 'C25,C100,C200', False, 3, False, True)} - Restarting: In case for some unforeseen reason, if a session crashes, then pass the correct Previous Position and Rollover as discussed above when restarting the strategy.
-
Abort: To exit strategy, while no touching positions, call
abort
>> MS.abort()
-
Range Object: For set of input parameters, like instrument, create an object with default arguements. Pass setups as a list of tuples.
Append