Introduction to Algorithmic Trading at Indian Stock Markets using Python

Pushpak Dagade (~pushpak)




For what audience is this talk intended?

For those interested in using the power of Python to book profits and save time by automating their trading strategies at Indian Stock Markets.

What is Algorithmic Trading?

Imagine if you can write a Python script which can, for example, automatically BUY 100 shares of company 'X' when its price hits 52 week low and SELL it when it rises by 2% of the purchase price or based on some other different strategy which suits you. Sounds cool, right?

Algorithmic Trading is the process of using computer programs, based on a predefined algorithm, for placing trades in order to generate profits at a speed and frequency that is impossible for a human trader.

(The above example is very basic. You can code very complex strategies!)

Tell me the advantages of Algorithmic Trading over Conventional Trading

Here are a few reasons why algorithmic trading can lead to high chances of success -

  • Ability to take into account large number of factors for decision making, which can be practically impossible for a human
  • Trades can be timed correctly. Manually placing trade involves delay which may result in significant price change by the time trade is placed
  • Human error eliminated while placing trades
  • Human emotions (greed/fear) taken out of execution, which otherwise may result in big losses

And lastly, you can use your precious time for something else! Just let your computer monitor the stock markets 24x7 and place trade orders for you.

Ok. Now that you have got me interested, tell me quickly what this TALK will cover.

For implementing Algorithmic Trading in Python, you need the following -

  1. Ability to query real time data (current stock price)
  2. Ability to query historical data
  3. A strategy (ie the Algorithm), which gives out predictions whether to BUY, SELL or HOLD.
  4. Backtesting framework to test the strategy
  5. Ability to place BUY/SELL trade order at Indian Stock Exchanges (NSE/BSE)

This TALK will demonstrate all the above mentioned points for the below strategy.

Strategy (Algorithm):

  1. Crossover(EMA(3), EMA(15)) --> Place Buy Order
  2. Crossover(EMA(15), EMA(3)) --> Place Sell Order
  3. Every Buy and Sell order is placed with 1% Stop Loss and 0.3% Target Price

This strategy generated an average profit of ~6% per month (~72% annually) on real data of TATASTEEL (NSE) during backtesting for the period 16th June - 14th August, 2017.

Click below to see the video of this backtesting strategy in action.

Click here to watch video of a backtesting strategy in action on TATSTEEL(NSE) data


  • Basics of Python
  • [Optional] Basics of Trading is a plus. (I will introduce the relevant trading terms in the beginning of the TALK for those not familiar)

Content URLs:

If you are interested in more information about this, please drop me a mail at with your purpose for accessing other resources. Thanks.

Speaker Info:

I hold 3 degrees from IIT Delhi - Electronics, Computer Science & Physics. I first started using Python in 2009 and have been using ever since, everywhere possible - academics, work, hobby. I currently work at NVIDIA.

Sometime back, I worked for a startup, TapDiscover, where we created 2 fully functional Android apps. I was responsible for complete backend development using Django REST Framework. I have also worked with Numpy, Matplotlib, PyQt4. I read Python books in my free time. I heavily use Python for scripting in my current job.

PS: Python is my passion. I am a Hardware Engineer by profession.

Speaker Links:

Open Source contributions -

Other Links -

Section: Others
Type: Talks
Target Audience: Beginner
Last Updated:

This is interesting topic. Glad someone is interested for sharing HowTo on it.

Praxal Shah (~praxal)

Thank you Praxal.

Pushpak Dagade (~pushpak)

Hi can you please upload the slides for the talk so that your proposal can be reviewed.

Pradhvan Bisht (~cyber_freak)

Hi Pradhvan, I am still working on the content, as 31st Aug is the mentioned deadline. I would need a couple of more days to finish them. Would that be fine?

Pushpak Dagade (~pushpak)

That would be fine , it's just a gentle reminder to finish the slides before the deadline so the proposal can be efficiently evaluated.

Pradhvan Bisht (~cyber_freak)

Sure, will submit before deadline. Thanks.

Pushpak Dagade (~pushpak)
The comment is marked as spam.

Souvik Kundu (~souvik)

Sounds Interesting !!!

pratik misal (~pratik41)

Quite a challenging task. There are lot of factors : 1. Capital 2. Risk ratio 3. Stock price and its market standing 4. Stop loss 5. Stocks to monitor - gives user selectivity Also, it would be great if you can somehow do web crawling for particular company site for news and then invest ( it will give user idea of downfall ). Moreover, it not always 1 year high low, user should be able to set time frame. I know, you want fully automated code but stock is something user wants to get involved and analysis of the stock "price" is small fraction to book profit.

Great you thinking for it! Hope to see framework soon !

Yash Jain (~yash456)

Thanks for commenting Yash. Yes, agreed this is quite a challenging task. I have developed the framework, pyalgotrading, keeping scalability in mind and currently it supports most of the points you have mentioned. (You may want to read the proposal once again, as I have added my content links. And please do watch the video mentioned above.)

With the current framework, one can easily code up a strategy and backtest it with support for the following features -

  1. Analyze returns for any share
  2. Analyze returns for any timeline (intraday, non-intraday)
  3. Support for backtesting analysis using animation
  4. Support for STOP LOSS and TARGET price
  5. Get statistics (for ex: total trades executed, # profitable trades, # loss making trades).

.. and these features can be easily plugged into current framework -

  • Risk ratios like Sharpe Ratio, Sortino Ratio, Sterling Ratio.
  • Capital restriction (My example strategy,, (which I have mentioned above) ensures there is no more than 1 trade is open at any given time, thus indirectly restricting capital usage)

Please note I have kept the target audience as "Beginner" as I would like to larger audience to take interest in this hot topic. The topic of web crawling, though extremely powerful, may get out of scope as it would involve Machine Learning. Having said that, the framework should be easily expandable to plug in this feature for advanced users with minimal effort.

Pushpak Dagade (~pushpak)

Hi Pradhvan, I am almost done with my presentation slides and jupyter notebook. I will upload them tomorrow. I'll comment here again once its done.

Pushpak Dagade (~pushpak)

Hi Pradhvan, I have uploaded my presentation slides and jupyter notebook. Thanks.

Pushpak Dagade (~pushpak)

Does it take care of losses in terms of brokerage in the final 72% analysis. Wondering if I can use this approach as a real-life investor/trader ;-)

Anand B Pillai (~pythonhacker)

Target price and stop loss numbers have been set based on real scenario, so YES you can use this in real life and still make profits :-) I have not included broker charges in the proposal to keep things simple.

Pushpak Dagade (~pushpak)

Target price and stop loss numbers have been set based on real scenario, so YES you can use this in real life and still make profits :-) I have not included broker charges in the proposal to keep things simple.

Pushpak Dagade (~pushpak)

Hi, Would be interested in learning how you managed such a feat! and ofcourse learn in the process. I am a newbie at Python, but do want to learn it earnestly for real world application and automation.

Best Regards.

Manish Rathee (~manish07)

Hey , are You still persuing this. Is there anyway i can help. I was looking at doing similar project on my own.

Kaushal Hasmukh Shah (~kaushal50)

Hey , are You still pursuing this. Is there anyway i can help. I was looking at doing similar project on my own.

Kaushal Hasmukh Shah (~kaushal50)

I am using Wisdom Capital platform and my broker not cheated me at all, so thank to Mr Kamoth who give me advice for joining to Wisdom Capital. If you want to go with Wisdom Capital then click Best Stock broker in India


You can also exercise search on stock market volatility so as to meet the great aspects to implement the wise method with the help of right measuring tools. Read more for Online Zero Brokerage Trading Account


Login to add a new comment.