I've been a discretionary trader for past 4 years. I'm seriously considering to get some strategy live. I'm currently using python and zerodha to get my strategy live. I could not see a discussion on sharing one's experience in auto trading. I'm not looking for any specific details on strategy. No one will share that. I want to know about the learnings, what to look for, do's/dont's, slippages, and ideas to diversify strategy on different market conditions, how to wisely make use of spread in execution strategy, backup systems in case of primary system failover, etc.
This would help new traders to gain insight and some direction.
1. Infrastructure - A good server with decent specifications. It can be a windows/unix/any other.
2. Data feed - Again this should go along your server. I see lot of RT datafeed clients in india are windows based as most people use Amibroker. But when we go for standard provider we would get platform independent datafeed. We should choose a lightweight software for this. I have used multiple datafeeds which are primarily windows based but they will literally freeze the server. I found zerodha websocket to be platform independent and lightweight. Though back filling looks slow.
3. Technical analysis library - I see most traders use Metastock, Amibroker, NinjaTrader softwares which are really great trading platforms. But I personally not comfortable with the programming which they use. You would definitely need a good AFL/Metsstock programmer to review your strategy. This case you will lose your edge on your own strategy. Most AFL programmers are traders themselves. If you go for other standard libraries - TALIB is a good choice and has wide range of indicators and patterns built in and widely used. Getting TALib install-able is little difficult in latest systems as it requires many dependencies.
4. Strategy: This is the tough part. It requires lot of knowledge and understanding of indicators and other aspects. I will leave this part as everyone comes here with something in mind.
5. Backtest: This has to go hand in hand with strategy and fine tuning. Build your own backtest platform or utilize existing features from amibroker/backtest libraries.
6. Execution: He comes kite API. Whatever strategy you create and backtest which gives amazing returns may not perform in the same way in live markets. Especially in Indian markets where volumes are thin(in stocks) and spread is more, you should have a good execution strategy so as to reduce slippages or any other unforeseen situations.
Thanks for info bro
During this phase you need to focus on improving performance, methods of programming and analysing & improving decisions.
now time comes when you can take it live with minimum qty of trades and monitor each and every action. make sure you take output of all decision points so that you can analyse your trades.
you need to analyse your bad trades to find out how you can remove them from system. this activity takes patience and time. now your system is ready for real trading. once you get enough money its better to deploy your code into cloud(AWS)...
in any of above phases if you see that your system is not working properly then don't hesitate to start over again...
is there significant profit in algo trading? have you been successful in it already?
1. Which one to buy/sell
2. When to enter
3. When to exit
4. What is support/resistance level (you may set a stoploss depending on that, when applicable)
But with Ninja Trader and Kite API i tried couple of times and made profit , yes there was loss as well as i said the strategy did not work on all market condition , you need to tune it time to time until you may reach the end !, but over all the trade was in profit and now i am trying to make a solid strategy by doing test trades by Ninja without going live
9850073217 .We have achieved all crutial point mentioned in the above chain.
with auto averaging, mass buying, mass selling, alert message to my mobile with pushbullet,
remote execution of various functions using google drive... lot more to do...
Now my environment is ready and all i have to do login before every trading section and configure some parameter as per my requirement.
Then, feed all those (20) stocks through a self developed Technical Analysis library, it spits out Buy/Sell signals based on the analysis.
Then, I place the orders with the target.
Running it for past few days and found it profitable.
The analysis and order placing system is deployed on a server in cloud.
2. Datafeed: Its a big issue. With websocket, there is no backfill in case of disconnection or system breakdown. So, you don't want to rely exclusively on it. Historical datafeed is costly, buggy (as seems from so many posts), and is poor on handling of corporate actions. So, event thats out. Now, you have vendors like GDFL and TrueData which have started API services, but they are also expensive and restrict you to number of symbols you can use. All in all, a perfect data-feeds solution, which also handles corporate actions, is missing right now. Because of this, I am still using the Amibroker based providers (like GDFL) where data is realtime along with automatic backfill. It also implies, I am having to run my strategies and generate signals on these platforms. In want of a great datafeed, I am running an automated system where signals are generated on Amibroker and executed on Python (which uses websocket as datafeed for execution related data needs).
While it sounds stone ages vintage and too rookie, the motivation is to get the work done by application which can do it best. So far this combination has not given me any reasons to switch the entire thing to Python (considering the development time and effort required for a system to handle historical data in python and my desire of not polling historical data every second to run my strategies). Might as well use the saved time on strategy development.
I am very interested in experiences of those who are completely dependent on Websockets for data needs. Especially how they handle missed data.
3 Strategy: One has to invest time in going about building a strategy. This topic is worthy of a book in itself but I would request users to read literature on how to design strategies. Ernie Chan and Paul Kaufman are two good authors. One can also look at quantstart.com . The recommendation is that one should first understand how to build strategies and take it live as advised by practitioners like above, before finding strategies online and trying to implement them. A large part, infact, the most important part of strategy design lies in psychology. A trader has to first figure out his mental makeup and decide how he wants to make money and what is his risk appetite. He wants to play shorterm and make small money over large number of trades, or he wants to find winners or any combination in between. He should also be aware that as he moves towards shorter time horizons, expected profit per trade will decline, execution will start becoming more important, and slippage plus trading costs like brokerage, and taxes will be huge burden. Execution issues and inadequate provision for trading costs usually destroy an otherwise excellent sounding short term strategy.
Always remember, Systems and indicators dont make money. Traders make money.
@vishalgvora seems to have ticked all the right boxes. Making money on scalp trading over internet connectivity is as tough as it gets. I would seriously urge him to consider sharing his experiences with all of us.
QuantStart looks great. I was having my own execution engine written which carries out simulation and live trades in parallel. I thought this can give me good picture of slippages. However I have not gone live. But I consider moving to an event driven backtester and executor as it will be more faster.
I'm totally relying on Kite as of now. But I dont just trust any datafeed. I have used multiple datafeeds for discretionary trading like kite, ValueRT, GDFL, etc and everything has failed at some point of time. My current setup is I use RTFeed from Websocket and a thread of last 1/2 days backfill into my database. My strategy runs on that at intervals - mostly 30s/1m. This is not a very good setup however it can scale well for indian markets and my strategies. I'm planning to subscribe to a fallback datafeed and datastore from totally different vendor and my algo will just switch on any delays.
However, I think an efficient and reliable way, in your case, would be to form order objects (as in Object oriented programming) which will manage orders. So you will create a new orderobject per new order. In you main program you can form a dictionary which will have key as the symbol and value as the orderobject itself. Whenever a new order of this nature needs to created, this orderobject will be initialized and added to the dictionary mentioned above. Thereon, any new bar, this dictionary will be checked and if the ticker is present as one of keys, then it will call a special method, say on_new_bar method of that object like:
orders_dict[ticker].on_new_bar(bar.open, bar.high, bar.low, bar.close, bar.volume)
Inside this method on_new_bar, you can set your conditions on upscaling and downscaling. If certain price hurdles have to crossed, they can be added as an attribute of this orderobject (at the time of initialization) and can be compared inside this method, so that when a certain level is breached, additional position is built. If positions have to build over time rather on price barriers, you could implement some timing devices like threading.Timer etc. Or simply using time.sleep. If you think along these lines, you can do fairly complicated stuff. The object model allows to encapsulate everything inside the object, so you are not worried about its impact on remaining application. This will work wonderfully well in event-driven framework. This concept will work even better if you think orders in term of positions i.e. the orderobject will take care of both entry and exit of that position. This is essentially what I do and it works.
Using this, I am placing SL entry into Bracket Orders which is not offered by Zerodha. The orderobejct monitors price of that ticker and when SL level is breached it fires a Barcker Order to Zerodha immediately. This is similar to your requirement, where after the decision to place order is made, I still watch out for a price level before I enter the order. I am seeking additional trend confirmation after trading signal is generated but before actually entering. As a side note, it helps a lot because of a lot of trades which would go wrong directly at the time of entering are avoided completely.
I hope this is making sense.
If this is complicated or impractical, it will depend upon architecture of your system. How do you relay data to you algo, how positions are being entered and exited. How does you algo process incoming new data?
A broker object -> Holds Position book object -> holds Trade objects. I call Broker for all updates/modifications for trades. Broker handles SL, TSL, etc. Provides me list of trades by stock, open positions, risk, etc.
This help me to switch to Zerodha broker later easily is it is how it happens in real life.
I read from my local datastore in frequest intervals the last dataframe(2-3 days) and do a run on all the dataframe rows till last tick and all my broker, position book have the latest trades and they keep updated for new ticks every 30s/60s. I find this to be ineffective. Will check QSTrader how it does this.
But I can start multiple strategies on my datastore as separate process and each strategy has multiple threads for different stock.
I need to have an interface to check last tick once broker receives a signal from strategy. I will be running simulation once I refactor my setup a little better.
1. Reached destination. Profits is there. System monitors , generate signal and place order. wow. For all lonely soul trying hard out there my loud yell from here. It works
2. Soul: System is there to enforce discipline and execute the though process. The core strategy of buying low and selling high we have to come up . preparing same is most crucial part. This is less to do with speed and more with understanding fundamentals.
3. Understand compatibility of our own though process, Is it principle driven or creative one ? Hope that help.
In a nutshell, short term trading is all about leverage and that will determine the kind of profits one has observed on a good day as well as losses one has made on a bad day.
To illustrate, a bracket order on TATASTEEL futures requires Rs 17K margin for 1 lot of 1061 shares at roughly Rs 540 per share. Now, if get the trade right on a day, when it moves 5%, say from 540 to 565, you make >Rs 25k on this one trade alone. More than 150% return on capital on that trade. But if you have Rs 5 Stop Loss on this trade and you hit a lean phase, (which you will), you will lose all your capital in 5 days straight.
I do run a purely intraday strategy with a very high leverage. Plenty of wild ride here.
I was hoping someone with experience and larger capital would be able to diversify and make up for loss in one stock by profit in another. I know that is also going to be very market dependent but still some hedging would work in intraday also? wouldn't it.
another question when I used to place order from web browser it would at times of market volatility show that, market orders have been stopped/restricted and ask to place a order above market price which then will be identical to market order as it will be executed at the highest offer.
Does this happens with the orders through api's also, and in you setup do you sell and buy at market price or at bit higher than that ?
Thanks for the detailed response.
a. You may try to enter into multiple positions on a single day in hope that a few of them will turn out good with others getting stopped out, making the strategy overall profitable. You may long and short equal amounts, say go long TATASTEEL for 1 lot and short 1 lot ACC simultaneously to run a market neutral portfolio. A lot of fine tuning is required to make these strategies effective, something you will have to figure out during back-testing. Per se, it is achievable, but to run an intraday momentum strategy using these is going to be extremely difficult.
There is no point of taking a position and then hedging it. It is same as taking a smaller sized position. Generally, you will hedge for a time period smaller than your overall holding period, when you assess that market is going to remain unfavorable in that smaller period. For example, a guy who holds is positions for a week may hedge on the day when RBI rate decision is to be announced.
b. In a runaway markets, for limit orders, I have seen that orders are placed but not executed. I haven't seen orders getting rejected. For market orders, orders are not rejected in this manner. When you placed a market order, it gets filled.
I have a query on kite automatic trading based upon coded strategies. Is it possible ?
I came to know that it is possible through amibroker integration with Kite. Please suggest if any oher software can work.
The idea is that there should be automatic buy & Sell trades.
My requirements are as below -
1.Can we code strategies with defined %age stop losses.For example- if also buy at 100..it should either sell at 0.5% stop loss or 1.0% gain whichever comes first
2.Can I also code that if I already have one buy position in "X" stock and if it again gives buy signal on "X" stock based upon my algo then it should not buy again as I already have one position in "X"
3. Can I also code that system should buy stock if it crosses "last 15 candles high" on 10 minute or 5 minute chart
4. Can I also tell system to execute orders only between 10 AM to 1:30 PM and should square off all orders at 03:15 PM
5. Can I backtest strategies
6.Can I backtest for last 24 months on 5 minute chart in Amibroker. Do I have to buy data for backtesting or data from Kite Zerodha can work .
7. Does integration happens through Kite connect API ? What are charges for this API.
8. What system configuration I need to have to run this smoothly
The base Kite Connect subscription will cost you Rs 2000.
Kite Connect offers an optional add-on historical data subscription which will cost Rs2000 with the base subscription.
You can use this for backtesting but for live stratergies, we suggest generating candles at your using the live market data provided with Websockets API.
As of now, we don't have a sandbox environment. As of now, for testing, you can place orders post market hours.
Kite Connect is REST-like APIs which doesn't really need a powerful machine. It depends on your implementation.
If you use multithreading then it can run fine on an average personal computer.
You can get started from here.