17 February 2017

Automation of the Windows Terminal of NSE NOW

Disclaimer:
  1. Try this at your own risk.
  1. If you do decide to use this, Test  it thoroughly before you do so.
  2. At the time of writing, the NSE NOW version is : 1.13.3.5
  1. This has been tested by me  only for the above mentioned version for the NSE NOW software provided by my broker Finvasia.
  1. This has been tested on  Win 10 64 bit OS
  1. The automation script is designed for day trading on the NSE CASH segment

Acknowledgement:
This brilliant article from Stocksonfire set me thinking. Its perfectly suited for those of us who like to trade on the FnO segment  for a fixed lot size.  Although limited in its functionality, X-Mouse Button Control is a good choice for this.
But what if I need to trade on the NSE Cash segment with a clear cut position sizing and a dynamic Stop Loss ? Therein lay the origin of this script written in AutoIt.  Some of the other tools that I have explored for this automation are SikuliX, Selenium and AutoHotkey


Purpose of this Automation:
  1. Create a Hotkey for placing a Buy/Sell order. Here (Shift + B) is used for placing a Buy Order. And (Shift + S) is used to place a Sell Order
  2. Automatically place a SL (either SL-Limit Order or a SL-Market Order) along with each Buy/Sell Order.  The default is  SL-Limit Order.
  3. For a Long position, the Low of the day is taken as Stop Loss . For a Short position, the High of the day is taken as SL.
  1. A rudimentary Position Sizing .  For the input trading capital , the number of shares to Buy/Sell are determined by the formulae: (ltp - stoploss)*noofshares = risk per trade. For finer details on position sizing, check with the writings of GuruJi Van Tharp


Settings of NSE NOW:
The  NSE NOW terminal  has to be setup as per the screen shots shown below.  The first step is to address the Preferences -> User Settings in NSE NOW.


Setup of NSE NOW:
    • Ensure that the market watch is named as  MW1-NSE
    • Ensured that the Market Watch Window (MW1-NSE) is Not Maximised
    • The following 7 Columns are Mandatory and have to necessarily in the Order as shown in the figure below
      1. Symbol
      1. Last Traded Price
      1. Percentage Change
      1. Open
      1. High Price
      1. Low Price
      2. Prev Close Price


    This is how my final setup looks for day trading.


    Installing AutoIt:
    AutoIt is used for the development of the script that does the automation. It can be downloaded from the website here
    The screenshots below give the required guidance for installation.

    Running the Script:
      • Check out the required script which has been uploaded to github
      • Open the SciTE editor provided with the AutoIt installation and copy the source code  from github
      • Save it and name it as "automating_nse_now" . You are free to choose any name as you so desire.
      • When u are ready to run the script, right click on it and then  select "Run Script (x86)"

      • The AutoIt script will now show up in the System Tray. Ensure that the taskbar setting in Win 10 are enabled such that the icon shows up in the taskbar.

      • Place the selection key on the symbol in Market Watch and press  (Shift + B) for a Long Position and (Shift + S) for a Short  position
      Safety Features
      • First run the NSE NOW application and then start the Script. When the setup is done correctly, and when the Active Window is NSE NOW,  then Only will the script popup the screen for Input Data. The % Risk per trade is defaulted to 1% and can be changed.  The trading capital needs to be entered.
      • Once the data is input,  you ready and all set to Trade.  
      • If for any reason, there is any mismatch in the selected symbol on the market watch list and the symbol on the buy/sell order window or the SL windows, the program will popup a message and then terminate the script
      • Whenever you click the escape button, the script is automatically terminated
      Before you Run the script:

      • This is a critical Point .  It is important to capture the exact title  when NSE NOW is setup correctly.  This is the way to capture the Title:
      • During the installation of AutoIt,  a tool is also installed , called "AutoIt Window Info (x86)". Open this
      • Click on the "finder tool"




      • Drag the finder tool to the MW1-NSE 
      • Double click on the Title in the Window Tab

      Copy and paste that on the script for the variable Global $title_of_nse_now . Make sure that what is pasted is within the  quotes




      Wrapping it All:
      1. Once you  are done with all the steps mentioned above, right click the script and run it.
      2. Hotkey (Shift + B). Place the cursor on the marketwatch of NSE NOW  and press this hotkey to trigger a Buy Order with a SL placed at the Low of the Day
      3. Hotkey (Shift + S). Place the cursor on the marketwatch of NSE NOW  and press this hotkey to trigger a Sell Order with a SL placed at the High of the Day
      4. From the time you press one of the above two hotkeys,  just don't fiddle with the mouse or the keyboard for abt 4 seconds 

      All Set.  Run the Script. 
      Happy Trading Maadi.

      3 comments:

      1. Hi i have developing a more advanced trading system based on your idea with autoit and Nest trader but i am stuck in selecting a Cover order type in nest I am not able to select the Market option . If you could help me. I would like to contact you my rick113in@gmail.com

        ReplyDelete
        Replies
        1. Nest Trader is different from NSE Now. Although some controls could be the same

          Delete
      2. Excellent Innovations by both of you

        ReplyDelete