Você está na página 1de 49

AutoTrader 2.2.

Copyright © 2017 by stocksdeveloper.com All Rights Reserved.


AutoTrader 2.2.0

Table of contents

Introduction ...................................................................................................... 3
What's new .................................................................................................... 3
Design .......................................................................................................... 4
Installation ........................................................................................................ 5
Amibroker ..................................................................................................... 5
Realtime Data (RTD) ...................................................................................... 6
Getting Started ................................................................................................. 10
Start/Stop Application ................................................................................... 10
Registration ................................................................................................. 11
Automated Trading ...................................................................................... 12
Test ............................................................................................................ 14
Bulk Upload ................................................................................................. 15
Home Screen ............................................................................................... 16
Symbol Mapping .......................................................................................... 17
Orders ........................................................................................................ 18
Alerts .......................................................................................................... 19
Settings ....................................................................................................... 20
Realtime Data (RTD) ......................................................................................... 21
Configure Instruments .................................................................................. 21
Backfill ........................................................................................................ 23
Start/Stop RTD ............................................................................................ 23
Issues ......................................................................................................... 24
Integration ...................................................................................................... 25
Amibroker ................................................................................................... 25
Workflow ................................................................................................ 26
How to place orders? ................................................................................ 27
Parameters .............................................................................................. 29
Functions ................................................................................................ 31
Logs ....................................................................................................... 36
Examples ................................................................................................ 37
Place order for stock ............................................................................. 38
Place order for future ............................................................................ 40
Place order for option ........................................................................... 42
Place a bracket order ............................................................................ 43
Place a cover order ............................................................................... 44
How to cancel an order? ....................................................................... 45
Excel ........................................................................................................... 46
Function Variables ........................................................................................ 48
Support ........................................................................................................... 49

2 / 49
AutoTrader 2.2.0

Introduction

This is a software for trading automatically on KITE, NEST (client & dealer), NOW & ODIN
terminals. This software also provides live data for all exchanges for KITE users.

It provides you a set of functions that can be used to place orders, read order & portfolio
status.

Created with the Personal Edition of HelpNDoc: Easy EPub and documentation editor

What's new
· Fully & Semi Automated Execution
· Support for NEST, NOW, ODIN & Zerodha KITE platforms
· Real Time Data with backfill option for all exchanges (NSE, BSE, MCX) - Only for KITE
users
· Bulk Order Utility for Brokers & Portfolio Managers (Place order for multiple clients)
· No need to buy API from brokers (No additional expenses for you)
· More support for KITE, we have provided more functions in algotrader-util.afl for the
following:
o Bracket & Cover order support added
o Order cancellation support added
o Fetch order details (status, pending & filled quantity, status message etc.)
o Fetch position details (net quantity, buy & sell quantity, M2M, PnL, buy value, sell
value, net value etc.)
· Sound alerts on order placement
· Support for all market segments
o Cash segment
o Currency, Index & Stock derivatives
o Commodity (This has not been tested, contact support if you face any issues)
· Free to use & free support
o There are no charges for the software as well as the support
· Easy integration with any charting or analysis software
o AutoTrader reads orders from a shared file
o To connect it with any software, the charting/analysis software simply need to
write orders to a file
o AMI Broker support is built-in with examples
o To connect it to any other software, contact support
· Demo strategies provided which show usage of automation functions
· Supports all order types (Limit/Market/StopLoss)
· Many other order attributes as well, have a look at sample file here
· New features & changes
o If you need any new enhancements or changes in the software, we will try to
build it after analyzing your requirement
· Help
o We have put up a user guide to get you started
o You can also contact us for any queries or support

3 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Write EPub books for the iPad

Design
All applications that need to place orders, will write the orders into a file. The orders are
written into a comma separated format. These orders are picked up by AutoTrader and then
placed into trading platform.

4 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Create cross-platform Qt Help files

Installation

· Download setup from here.


· Run setup file (Right Click -> Run as Administrator) & wait for installation to complete,
it takes some time so please be patient.
· Software will be installed in C:\autotrader folder
· You will have shortcuts created on Desktop now for starting and stopping the server.
· Go to your desktop, right click on Start-AT shortcut & select properties.
· On properties window, go to Shortcut tab & click Advanced button.
· Tick Run as Administrator -> Press OK -> Press Apply

Created with the Personal Edition of HelpNDoc: Easy to use tool to create HTML Help files and Help web sites

Amibroker

Amibroker Integration

If you do not have Amibroker software installed then you can install Amibroker free version
from here.

· Go to folder (C:\autotrader\scripts\amibroker)
· Copy all folders inside this folder into your Amibroker installation folder (Example: C:
\Program Files\AmiBroker)
o Select all folders & copy
o Go to Amibroker installation folder & paste
o If system asks "Do you want to replace?" then Click YES (Replace All)

5 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Produce online help for Qt applications

Realtime Data (RTD)

Realtime Data Video Tutorial is available here.

This section explains the setup process of realtime data.

1. Make sure you have done Amibroker setup steps given in previous page.
2. Amibroker Run as Administrator
1. Right click on your Amibroker shortcut, click Properties
2. Click Advanced
3. Tick (select) Run as Administrator.
3. Create new database
1. Start Amibroker
2. Click on menu (File -> New -> Database)
3. Select database folder by clicking Browse
1. Select folder (C:\autotrader\rtd\amibroker\autotrader)
2. Tick (select) Load this database at startup
3. Click Create
4. Apply database settings as per the screenshot 1 below
1. Enable local data storage
2. Set number of bars to 30000
3. Set Base time interval as (Tick)
5. Click on Intraday Settings and apply settings as per the screenshot 2 below
1. Tick Show Day Session Only
2. Set market timings as per the exchange you trade
1. Screenshot shows NSE market timings
2. If you trade commodity market, then enter appropriate time
6. Mark as default database (see screenshot 3 below)
1. Go to Tools -> Preferences
2. Go to Data tab
3. Click on Current

Important: You MUST start Amibroker first & then AutoTrader.

6 / 49
AutoTrader 2.2.0

Screenshot 1

7 / 49
AutoTrader 2.2.0

Screenshot 2

8 / 49
AutoTrader 2.2.0

Screenshot 3

If you face any difficulty in installation then please contact us:


· Phone: +91 9503569907
· Email: help@stocksdeveloper.com

9 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Full-featured multi-format Help generator

Getting Started

Once you have completed all the steps in the installation procedure, you can now get
started.
Created with the Personal Edition of HelpNDoc: Full-featured Help generator

Start/Stop Application

Start
· To start an application, double click on the Start-AT shortcut on your desktop.
· It must always be run as administrator.
· It takes around 60 seconds for the application to start
· The system will automatically open a browser & go to address localhost:8080. If it
doesn't then open a browser & enter url localhost:8080.
o If you are on a network (Wi-Fi), you can access the application from any
computer. Just open a browser & enter name of computer on which our
AutoTrader is running (Example: your_computer_name:8080 or
your_computer_ip_address:8080)
· You will see the home screen similar to the one below

Stop
· To stop an application, double click on the Stop-AT shortcut on your desktop.

10 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Free iPhone documentation generator

Registration
On first time login you will be taken to a registration page. You must register here (this is one
time process). You need to enter following details:

· Your email address


· Your name
· Contact number
· NOW/NEST/KITE Client id (This is the client id that you use for logging into NOW/NEST
terminal. It is required for placing order. It can be changed later through settings)
· Platform Version (This is version number of your NOW/NEST terminal, it is available on title
bar. Example: 3.11.4). This is not applicable for KITE platform.

By default, you will get a 90-days trial license. We will extend it on case to case basis,
contact us when your license expires.

11 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Free Web Help generator

Automated Trading

Run Procedure
Steps involved in starting your automated trading.

1. Login to your trading platform (NOW/NEST/KITE)


2. Start your analysis application
1. Example, start Amibroker with your strategies running live (or using Bar Reply when
testing)
3. Start our service by double clicking Start-AT shortcut on desktop
4. Login to AutoTrader in your browser localhost:8080
5. Click on Start AutoTrader button
6. Click on Start Live Prices (if you are using realtime data from AutoTrader)
7. Run your strategies on live data in Amibroker or Excel
8. Once you have started strategies in Amibroker, just make sure that NEST/NOW is
open in FRONT. The NEST/NOW window must be in foreground (in front) for orders
to be placed.
9. Whenever an order is placed from strategy, you will hear an alarm.
10. AutoTrader will then immediately place on order onto NOW/NEST/KITE.

12 / 49
AutoTrader 2.2.0

Basic Start/Stop

Fully Automated Mode

· On the Home screen, you should see that the system is in a READY state.

· Press Start AutoTrader button to start automated trading. You can see the system is in
RUNNING state.
o The system will now wait for orders to come. As soon as the orders come system
will place it in your trading platform.

Semi Automated Mode

· To run in semi automated mode, press Stop/Manual


o When the system is stopped, it will still read orders but it will not place them
· To hold/pause automated order placement, press Pause
o When the system is on hold; all the orders that are received while the system is
on hold will be placed when the system is started again

13 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Generate EPub eBooks with ease

Test
Before you start live trading, it is important to do some tests.

Good Practice
· If possible, do testing after market hours
· During testing, if possible keep zero balance in your trading account (so all orders will be
rejected)
· Otherwise use small quantity limit orders, and use price which is outside circuit limits
(Example: price = 1.5, it will make sure that all your orders are rejected)
· If you follow above rules, then there is no risk accidentally placing an order

Test Procedure
Here I am giving all the steps that you would take to get automated order placement
running.

1. Login to your trading platform (NOW/NEST/KITE)


1. For KITE, only Chrome Browser is supported
2. Start our service by double clicking shortcut on desktop
3. Login to our system, open browser and enter url localhost:8080
4. Click on Start button
5. Start your analysis application
1. Example, start AMI Broker with your strategies
2. Make sure you called placeOrder functions from your strategy's AFL
3. Use Bar Reply feature of AMI Broker
6. Once you have started strategies in AMI Broker, just make sure that NEST/NOW is
open in FRONT. The NEST/NOW window must be in foreground (in front) for orders
to be placed.
7. Whenever an order is placed from strategy, you will hear an alarm.
8. AutoTrader will then immediately place on order onto NOW/NEST/KITE.

14 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Full-featured Kindle eBooks generator

Bulk Upload

Bulk Order Upload


This feature is useful for brokers & portfolio managers. Using this feature you can place
orders for multiple clients in a single click.

Note: You must have a nest dealer terminal or rights to place orders on behalf of multiple
clients.

1. Please open bulk orders excel file from (C:\autotrader\scripts\excel)


1. BulkOrders-OneOrderMultiClient : Single order for multiple clients (dealer
terminal)
2. BulkOrders-MultipleOrders : Multiple bulk orders for a single client
2. If you get a warning, then click "Enable Macro".
3. There are 2 sheets where you need to fill data:
1. clients: Enter your client codes here & their respective quantities
2. order: Fill your order details here
4. Click "Place Bulk Order" button.
5. The system by default will wait for 6 seconds (See column S on order sheet). This will
give you time to bring NEST/NOW in front. You can modify this value.
6. Bring your NEST/NOW platform to front.
7. AutoTrader will enter same order for all of your clients.

Please contact us if you have any custom requirement to place orders.

15 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Easily create iPhone documentation

Home Screen
· On top you have (Start/Pause/Manual) buttons.
· After that you see the current system status
· Refresh Button is used for reloading alerts & orders on the home screen
· Alerts table displays last 10 alerts generated by the system
· Orders tables displays all orders received by the system in current day

16 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Qt Help documentation made easy

Symbol Mapping
Symbol mapping is a feature that is very useful, as it saves you a lot of time. A mapping
basically maps a key to a security (stock, future etc). Once you have mapped a key, then
you need not pass the parameters that are specified in mapping.

You can simply place order for a mapped symbol as if you are placing order for a plain stock.

Please look at an example below:

Here we have create a mapping for key "NIFTY-I". Now we will pass this key in place of
symbol.

Once you have a mapping in place, you can then call function like the one below in AMI
Broker:

placeOrderMappedSymbol("NIFTY-I", "SELL", "NORMAL", "LIMIT", 10, 9900.5,


defaultTriggerPrice(), defaultDisclosedQuantity());
or
placeOrderMappedSymbol("NIFTY-I", "SELL", "NORMAL", "LIMIT", 10, 9900.5, 0, 0);

Without the mapping you would have to call a function like this (additional fields in pink):

placeOrderFuture("NFO", "FUTIDX", "NIFTY", "SELL", "NORMAL", "LIMIT", 75, 9900.5,


defaultTriggerPrice(), "26-OCT-2017", defaultStrategyId(),
defaultComments());

17 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Full-featured Documentation generator

Orders
Orders received by the system are displayed here:

· To view an order, click on the link of first column (Instrument) of the order row
· Remember orders are displayed in descending order of time (i.e. latest orders are
displayed first)

18 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Easily create Web Help sites

Alerts
Alerts generated by the system are displayed here:

· To view an alert, click on the link of first column (Instrument) of the order row
· The Name of an alert explains the alert purpose
· Remember alerts are displayed in descending order of time (i.e. latest alerts are displayed
first)

19 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Easily create CHM Help documents

Settings

All system settings are present here, they can be viewed & modified from here.

20 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Create iPhone web-based documentation

Realtime Data (RTD)

Realtime Data Video Tutorial is available here.

· Only available for KITE users


· Live & backfill data for all exchanges
· Reliable data (we simply redirect the data that you get in your kite [chrome browser]
window to Amibroker)
· You can configure instruments for realtime download from AutoTrader

Make sure that you have performed one time setup required for RTD, see details here.

Important: You MUST start Amibroker first & then AutoTrader.


Created with the Personal Edition of HelpNDoc: News and information about help authoring tools and
software

Configure Instruments

Configure Instruments

· Click on RTD link on the menu


· Click on "Download All Instruments", it takes some time 1-2 minutes
o This is one time activity
o There is no need to do it again & again
o Only do it once in a month so that you get all latest derivative instruments
· Refresh the page in 1-2 minutes
· Select exchange, segment & instrument type from the dropdown
· Enter symbol of the instrument & click search
· You will get the search results
· Select the instruments you want to add to RTD & click Add to RTD
· Table at the bottom shows all configured instruments
· You can also remove instruments from RTD by using Delete from RTD button

Note: There is NO NEED to have these instruments added to your marketwatch in KITE.

21 / 49
AutoTrader 2.2.0

22 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Full-featured Kindle eBooks generator

Backfill

Backfill

· Make sure you start Amibroker (Run as Administrator)


· Click on RTD link on the menu
· Look for the table RTD INSTRUMENTS
· Select the instruments you want to backfill
· Click on Backfill
· You will get alerts on your home screen once the backfill is complete

Created with the Personal Edition of HelpNDoc: Qt Help documentation made easy

Start/Stop RTD

Start/Stop RTD

· Make sure you start Amibroker (Run as Administrator)


· To start, click Start Live Prices
o All configured symbols' live data will be feed to amibroker
o Make sure you have selected Amibroker database as (C:
\autotrader\rtd\amibroker\autotrader)
· To stop, click Stop Live Prices

Note: If you want to change certain settings on chart, stop live prices -> change settings -
> start live prices.

23 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Easily create PDF Help documents

Issues

Issues

All known issues & their solution is documented on support page.

24 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Easily create iPhone documentation

Integration

Created with the Personal Edition of HelpNDoc: Easily create PDF Help documents

Amibroker

Integration with Amibroker

To see how to integrate Amibroker, please see these installation steps here.

Sample strategies

· algotrader-util.afl - This file provides various AFL functions that can be used for placing
an order. You must include this file in your strategy, so that all functions become
available to your strategy AFL.
o #include <algotrader-util.afl>
· at-ema-crossover-simple.afl - This file contains a simple Moving Average Crossover
strategy, which shows how to place orders.
· at-ema-crossover.afl - This file contains a simple Moving Average Crossover strategy,
which shows how to place orders & square-off feature.
· at-order-place-cancel-profit-stoploss.afl - This file contains a simple Moving Average
Crossover strategy, which shows how to place orders & cancel order, place profit &
stoploss orders.
· at-bracket-order.afl - This demonstrates the use of bracket orders.
· at-cover-order.afl - This demonstrates the use of cover orders.

25 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Free help authoring tool

Workflow
Let us understand how AMIBroker works with AutoTrader.

1. You write strategy in amibroker.


1. A strategy is basically a set of instructions to tell computer when to buy
or sell
2. You use the functions we have provided to place orders
2. You start AutoTrader
3. You login into your trading pltatform (NOW/NEST/ODIN/KITE)
4. You start with a new blank chart
5. You feed live data to amibroker (Start Live Prices)
6. Amibroker runs your strategy every time a new price is received
7. As per logic in your strategy, every time a buy or sell signal is generated the
functions that you have written will be invoked to place an order

26 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Generate EPub eBooks with ease

How to place orders?

Demo strategies are available in C:\autotrader\scripts\afl

How to place order from strategy?

1. Include autotrader-util.afl at the beginning of your fiile.


2. Use place order functions when your Buy, Sell, Cover, Short conditions are
true.

Lets look at a typical strategy:


· Code required for automation using AutoTrader is written in gray background
· Your strategy code is written in yellow background. You can replace the code in
yellow background with your own strategy code.

#include <algotrader-util.afl>

// Moving Average
SHORT_MA_PERIOD = Param("Short term moving average period", 20, 1, 200, 2);
LONG_MA_PERIOD = Param("Long term moving average period", 40, 1, 200, 2);

_SECTION_BEGIN("AutoTrader Demo 1 - Moving Average Crossover");

/* Exponential Moving averages */


EMA1 = EMA( C, SHORT_MA_PERIOD);
EMA2 = EMA( C, LONG_MA_PERIOD);

/* Buy and Sell Condition */


Buy = Cross(EMA1,EMA2);
Sell = Cross(EMA2,EMA1);

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = Sell;
Cover = Buy;

buyPrice = ValueWhen(Buy,C);
sellPrice = ValueWhen(Sell,C);
shortPrice = ValueWhen(Short,C);
coverPrice = ValueWhen(Cover,C);

/* Plot Buy and Sell Signal Arrows */


shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
GraphXSpace = 5;

/* Plot EMA lines and Candles */


Plot(EMA1,"EMA",colorRed);

27 / 49
AutoTrader 2.2.0

Plot(EMA2,"EMA2",colorGreen);
Plot(C,"Close",colorRed,styleCandle);

if ( LastValue(Buy) == True )
{
placeOrderUsingParams("BUY", AT_ORDER_TYPE, AT_QUANTITY, buyPrice,
defaultTriggerPrice(), 1);
}

if ( LastValue(Sell) == True )
{
placeOrderUsingParams("SELL", AT_ORDER_TYPE, AT_QUANTITY, sellPrice,
defaultTriggerPrice(), 1);
}

_SECTION_END();

Examples:

// NEST/KITE/NOW Examples

placeOrderFuture("NFO", "FUTIDX", "NIFTY", "SELL", "NORMAL", "LIMIT", 75, 9900.5,


defaultTriggerPrice(), "26-OCT-2017", defaultStrategyId(),
defaultComments());

placeOrderStock("NSE", "EQ", "SBIN", "SELL", "INTRADAY", "LIMIT", 10, price,


0, 0, 1, "Demo sell order managed by strategy 1");

// ODIN Examples

placeOrderFuture("NSE", "FUTIDX", "NIFTY", "SELL", "NORMAL", "LIMIT", 75, 12000,


defaultTriggerPrice(), "25-JAN-2018", defaultStrategyId(), defaultComments());

placeOrderStock("NSE", "EQUITIES", "SBIN", "SELL", "INTRADAY", "LIMIT", 10, price,


0, 0, 1, "Demo sell order managed by strategy 1");

28 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Generate Kindle eBooks with ease

Parameters

Variables available from algotrader-util afl

Every time you include algotrader-util.afl into your strategy code; you will automatically
get following parameters added to your chart. These parameters help you to easily configure
strategy settings.

You can use these variables in your strategy code to get the parameter values configured on
chart. Look at the sample strategies provided to understand how it is done.

/*******************************************************************
* Please read algotrader-util.afl file to understand all functions
* provided by AutoTrader. But DO NOT modify the file, if you are
* not familiar with AFL coding.
*
* NOTE: It is recommended to start with a blank chart.
********************************************************************
* Following variables are declared for strategy parameters in
* algotrader-util.afl.
********************************************************************
*
* AT_SYMBOL : Order symbol
* AT_QUANTITY : Order quantity (lot size)
* AT_EXCHANGE : Order exchange
* AT_INSTRUMENT : Order instrument
* AT_PRODUCT_TYPE: Order product type
* AT_ORDER_TYPE : Order order type
* AT_EXPIRY : Order expiry (expiry date (Example: 28-DEC-2017), pass NA if not
applicable)
* AT_OPTION_TYPE : Order option type
* AT_STRIKE_PRICE : Order strike price
* AT_SQUARE_OFF_FLAG: Intraday Auto Square-off (on|off)
* AT_SQUARE_OFF_TIME: Intraday Square-off Time
*
********************************************************************/

29 / 49
AutoTrader 2.2.0

How to enter values for these parameters?

Right click on amibroker chart & select parameters.

30 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Full-featured EBook editor

Functions

Functions for Placing orders

There are many functions for placing order, you can use any of them as per your need. The
names are self explanatory. The description of each parameter that the function takes are
given on following pages.

/*
* Places an order using parameters defined on the chart.
* See documentation above for parameter values.
*/
placeOrderUsingParams(tradeType, orderType, quantity, price, triggerPrice, validate);

/*
* Places an order.
* See documentation below for parameter values.
*/
placeOrder(exchange, instrument, symbol, tradeType, productType, orderType,
quantity, price, triggerPrice, optionType, strikePrice, expiry);

/*
* Places an order using mapping.
* See documentation below for parameter values.
*/
placeOrderMappedSymbol(symbol, tradeType, productType, orderType,
quantity, price, triggerPrice, disclosedQuantity);

/*
* Places an order for a stock.
* See documentation below for parameter values.
*/
placeOrderStock(exchange, instrument, symbol, tradeType, productType, orderType,
quantity, price, triggerPrice, disclosedQuantity, strategyId, comments);

/*
* Places an order for a future contract.
* See documentation below for parameter values.
*/
placeOrderFuture(exchange, instrument, symbol, tradeType, productType, orderType,
quantity, price, triggerPrice, expiry, strategyId, comments);

/*
* Places an order for a option contract.
* See documentation below for parameter values.
*/
placeOrderOption(exchange, instrument, symbol, tradeType, productType, orderType,
quantity, price, triggerPrice, optionType, strikePrice, expiry, strategyId, comments);

/*
* Place an order, this function allows you provide many parameters. And it can be used to
place any kind of order.

31 / 49
AutoTrader 2.2.0

* It will check whether symbol has a mapping in the system.


* If a mapping is found, parameters from the mapping are used; otherwise default parameters
are used.
*/
placeOrderAdvanced(exchange, instrument, symbol, tradeType, productType, orderType,
quantity, price, triggerPrice, disclosedQuantity, optionType, strikePrice, expiry,
clientId, validity, traderType, marketProtectionPct, strategyId, comments);

/*
* Places a bracket order using parameters defined on the chart.
* See documentation above for parameter values.
*/
placeBracketOrder(tradeType, quantity, price, target, stoploss, trailingStoploss, validate);

/*
* Places a cover order using parameters defined on the chart.
* See documentation above for parameter values.
*/
placeCoverOrder(tradeType, quantity, triggerPrice, validate);

Examples:

// NEST/KITE/NOW Examples

placeOrderFuture("NFO", "FUTIDX", "NIFTY", "SELL", "NORMAL", "LIMIT", 75, 9900.5,


defaultTriggerPrice(), "26-OCT-2017", defaultStrategyId(),
defaultComments());

placeOrderStock("NSE", "EQ", "SBIN", "SELL", "INTRADAY", "LIMIT", 10, price,


0, 0, 1, "Demo sell order managed by strategy 1");

// ODIN Examples

placeOrderFuture("NSE", "FUTIDX", "NIFTY", "SELL", "NORMAL", "LIMIT", 75, 12000,


defaultTriggerPrice(), "25-JAN-2018", defaultStrategyId(), defaultComments());

placeOrderStock("NSE", "EQUITIES", "SBIN", "SELL", "INTRADAY", "LIMIT", 10, price,


0, 0, 1, "Demo sell order managed by strategy 1");

Other order related functions (Works with KITE only)

To use these extra order related features; Go to settings:


Set PLATFORM_SYNC property value to true.

/*
* Cancels the order. Pass the order id that you receive from placeOrder function.
*/
cancelOrder(id);

/*
* Get order status.
* id - should be the id returned by placeOrder when you place an order.
*/
getOrderStatus(id);

32 / 49
AutoTrader 2.2.0

/*
* Get order quantity.
* id - should be the id returned by placeOrder when you place an order.
*/
getOrderQty(id);

/*
* Get order pending quantity.
* id - should be the id returned by placeOrder when you place an order.
*/
getOrderPendingQty(id);

/*
* Get order filled quantity.
* id - should be the id returned by placeOrder when you place an order.
*/
getOrderFilledQty(id);

/*
* Get order average price.
* id - should be the id returned by placeOrder when you place an order.
*/
getOrderAveragePrice(id);

/*
* Get order timestamp.
* id - should be the id returned by placeOrder when you place an order.
*/
getOrderTimestamp(id);

/*
* Get order platform (NEST, NOW, KITE, ODIN) id.
* id - should be the id returned by placeOrder when you place an order.
*/
getOrderPlatformId(id);

/*
* Checks whether order is open.
* id - should be the id returned by placeOrder when you place an order.
*/
isOrderOpen(id);

/*
* Checks whether order is complete.
* id - should be the id returned by placeOrder when you place an order.
*/
isOrderComplete(id);

Position related functions

To use these extra position related features; Go to settings:


Set PLATFORM_SYNC property value to true.
/*
* Get position net quantity.
* id - symbol which uniquely identifies a position
*/
getPositionNetQty(id);

33 / 49
AutoTrader 2.2.0

/*
* Get position BUY quantity.
* id - symbol which uniquely identifies a position
*/
getPositionBuyQty(id);

/*
* Get position SELL quantity.
* id - symbol which uniquely identifies a position
*/
getPositionSellQty(id);

/*
* Get position M2M.
* id - symbol which uniquely identifies a position
*/
getPositionM2M(id);

/*
* Get position P&L.
* id - symbol which uniquely identifies a position
*/
getPositionPNL(id);

/*
* Get position buy price.
* id - symbol which uniquely identifies a position
*/
getPositionBuyPrice(id);

/*
* Get position sell price.
* id - symbol which uniquely identifies a position
*/
getPositionSellPrice(id);

/*
* Get position buy value.
* id - symbol which uniquely identifies a position
*/
getPositionBuyValue(id);

/*
* Get position sell value.
* id - symbol which uniquely identifies a position
*/
getPositionSellValue(id);

/*
* Get position net value.
* id - symbol which uniquely identifies a position
*/
getPositionNetValue(id);

Square-off functions

/*
* Square off position as per chart parameters.

34 / 49
AutoTrader 2.2.0

*/
squareOffPosition();

/*
* Square off position.
*/
squareOffPositionForSymbol(exchange, instrument, symbol, productType,
optionType, strikePrice, expiry);

Utility functions

/*
* Calculates profit order price.
*/
calculateProfitTarget(entryTradeType, entryPrice, profitPct);

/*
* Calculates stoploss order price.
*/
calculateStoplossTarget(entryTradeType, entryPrice, stoplossPct);

Functions for Default Values

There are many other functions in algotrader-util.afl which provide default values for various
parameters. These are useful if there are parameters which are not applicable in your case,
then simply call it's respective default value function.

defaultTraderType()

defaultValidity()

defaultOptionType()

defaultExpiry()

defaultClientId()

defaultExchange()

defaultInstrument()

defaultStrikePrice()

defaultDisclosedQuantity()

defaultTriggerPrice()

defaultMarketProtectionPct()

defaultStrategyId()

defaultComments()

35 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Free EBook and documentation generator

Logs
Amibroker logs will help you to see what autotrader functions are doing, it is very
useful to debug problems.

How to see strategy logs in AMIBroker?


1. Enable log window from amibroker menu (Window -> Log)
2. You will see log window at the bottom.
3. Go to "Trace" tab (all strategy logs are printed here).

36 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Create iPhone web-based documentation

Examples
There are many functions provided by AutoTrader, now let us see some examples of how to
use them.

To see a list of available functions, click here.

To see a list of all variables, click here.

To see a list of all chart parameters, click here.

Demo strategies should be available in your Amibroker (see screenshot below).

37 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Qt Help documentation made easy

Place order for stock


Example 1. Place buy market order with 21 quantity for SBIN stock.

// placeOrderUsingParams(tradeType, orderType, quantity, price, triggerPrice, validate)

orderId = placeOrderUsingParams("BUY", AT_ORDER_TYPE, AT_QUANTITY, 0,


defaultTriggerPrice(), 1);

Above function will place an intraday buy market order for symbol = SBIN, quantity = 21,
you can see that we are passing variables configured on chart parameters to the function.

Parameters

38 / 49
AutoTrader 2.2.0

Example 2. Place sell stoploss order with 100 quantity for RELIANCE stock, with trigger price
1100.5

Solution 1: We place orders using parameters

// placeOrderUsingParams(tradeType, orderType, quantity, price, triggerPrice, validate)

stoplossPrice = 1100.5; // You can calculate stoploss price using your own formula
sellPrice = stoplossPrice - 1; // Sell price a little less than stoploss price
placeOrderUsingParams("SELL", "STOP_LOSS", AT_QUANTITY, sellPrice, stoplossPrice, 1);

Solution 2: We place order by passing our own values calculated from code

// placeOrderStock(exchange, instrument, symbol, tradeType, productType, orderType,


// quantity, price, triggerPrice, disclosedQuantity, strategyId, comments);

stoplossPrice = 1100.5; // You can calculate stoploss price using your own formula
sellPrice = stoplossPrice - 1; // Sell price is a little less than stoploss price

orderId = placeOrderStock(AT_EXCHANGE, AT_INSTRUMENT, AT_SYMBOL, "SELL",


"INTRADAY", "STOP_LOSS",
100, sellPrice, stoplossPrice, defaultDisclosedQuantity(), defaultStrategyId(), "My
stoploss order");

39 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Free help authoring environment

Place order for future


Example 1. Place a sell order NIFTY future 1 lot (lot size = 75).

Solution 1:

// placeOrderUsingParams(tradeType, orderType, quantity, price, triggerPrice, validate)

orderId = placeOrderUsingParams("SELL", AT_ORDER_TYPE, AT_QUANTITY, 0,


defaultTriggerPrice(), 1);

Above function will place an intraday sell market order for NIFTY JAN 2018 future,
quantity = 75 (i.e. 1 lot), you can see that we are passing variables configured on chart
parameters to the function.

40 / 49
AutoTrader 2.2.0

Solution 2: For KITE users, you can keep the default symbol & other values (only
change quantity)

If you are using KITE symbol, then there is no need to enter expiry, exchange, instrument
etc. Just keep default values as shown in the screenshot below.

Solution 3: If you need to pass additional parameters then you can do it following way.

// placeOrderFuture(exchange, instrument, symbol, tradeType, productType, orderType,


// quantity, price, triggerPrice, expiry, strategyId, comments)

sellPrice = ValueWhen(Sell,C);

orderId = placeOrderFuture("NFO", "FUTIDX", "NIFTY", "SELL", "NORMAL", "LIMIT",


75, sellPrice, defaultTriggerPrice(), "25-JAN-2018", defaultStrategyId(), "My derivative
order");

Above function will place an intraday sell market order for NIFTY JAN 2018 future,
quantity = 75 (i.e. 1 lot), you can see that we are passing variables configured on chart
parameters to the function.

41 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Easily create Qt Help files

Place order for option


Example 1. Place a sell market order NIFTY call option at strike 10000, quantity 1 lot (lot
size = 75).

Solution 1:

// placeOrderUsingParams(tradeType, orderType, quantity, price, triggerPrice, validate)

orderId = placeOrderUsingParams("SELL", AT_ORDER_TYPE, AT_QUANTITY, 0,


defaultTriggerPrice(), 1);

Above function will place an intraday sell market order for NIFTY JAN 2018 Call option
with strike 10000, quantity = 75 (i.e. 1 lot), you can see that we are passing variables
configured on chart parameters to the function.

42 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Benefits of a Help Authoring Tool

Place a bracket order


Bracket orders are only supported on Zerodha KITE.

Example 1. Place buy bracket order for NIFTY FUTURE.

// placeBracketOrder(tradeType, quantity, price, target, stoploss, trailingStoploss, validate)

// Assume NIFTY future is trading at 10000, then our target is 10050 and stoploss is 9980.
We set trailingStoploss to 2.
buyPrice = ValueWhen(Buy,C);
target = 50;
stoploss = 20;
trailingStoploss = 2;
orderId = placeBracketOrder("BUY", AT_QUANTITY, buyPrice, target, stoploss,
trailingStoploss, 1);

Above function will place a buy bracket order for NIFTY JAN 2018 Future, quantity = 75
(i.e. 1 lot), you can see that we are passing variables configured on chart parameters to the
function.

Parameters

43 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Free help authoring tool

Place a cover order


Cover orders are only supported on Zerodha KITE.

Example 1. Place buy cover order for NIFTY FUTURE.

// placeCoverOrder(tradeType, quantity, triggerPrice, validate)

// Assume NIFTY future is trading at 10000, then we set our stoploss at 9980.
livePrice = 10000;
stoploss = livePrice - 20;
orderId = placeCoverOrder("BUY", AT_QUANTITY, stoploss, 1);

Above function will place a buy bracket order for NIFTY JAN 2018 Future, quantity = 75
(i.e. 1 lot), you can see that we are passing variables configured on chart parameters to the
function.

Parameters

44 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: What is a Help Authoring tool?

How to cancel an order?


In order to cancel an order, you need to have the order_id. So first you need to save order
id.

Save order id

Every place order function returns an order_id of the order that was placed. We will store
this order id in a static variable, so that we can use it later when we want to cancel the
order.

We will place a limit order here & save the order id in a variable orderId.

The function we use for saving order id is atStaticVarSetText(key, value). This function
saves the value in a static variable, and makes sure that the key is unique so that it is not
affected by strategies running in other charts.

orderId = placeOrderUsingParams("BUY", "LIMIT", AT_QUANTITY, buyPrice,


defaultTriggerPrice(), 1);

/* Save entry order id for later use */


atStaticVarSetText("ENTRY_ORDER_ID", orderId);

Cancel order

Now we use function atStaticVarGetText(key) to get order_id that we saved earlier & use it
to cancel order.

/* We assume your order is open & you will have some logic based on which you may want to
cancel an order */

if (some_condition) {
// Now we want to cancel open order
orderId = atStaticVarGetText("ENTRY_ORDER_ID");
if(isOrderOpen(orderId) == 1) {
cancelOrder(orderId);
}
}

45 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Free help authoring environment

Excel
Here we discuss about how to place orders from Microsoft Excel.

Readymade Files

You will find sample files under C:\autotrader\scripts\excel folder. These files can be used
to place orders automatically.

BulkOrders-MultipleOrders - It is used for sending multiple orders to your trading platform.


BulkOrders-OneOrderMultiClient - It is used by dealers to place a single order for multiple
clients.
autotrader-options-buy-call-put - It is an excel sheet which receives signal (from user-
defined formula) and based on that buys call or put option

If you have any custom requirement to build trade automation in excel then you can
contact us.

Using automation with your own excel files

To make autotrader functions available to your own excel, you will have to install autotrader
addin.

Steps:
1. The addin is available at C:\autotrader\scripts\excel\autotrader.xlam
2. Copy the file to C:\Users\UserName\AppData\Roaming\Microsoft\AddIns. See this link for
more information on how to install addins.

Once you have addins install, then you can see all place order functions available in the User
Defined category (see below).

Double-click on placeOrder functions to see list of parameters to pass. Alternatively you can
type a function in excel cell:
=placeOrderStock
And press Ctrl + A to see help.

46 / 49
AutoTrader 2.2.0

47 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Write eBooks for the Kindle

Function Variables

VARIABLE_NAME DATA_TYPE DESCRIPTION


symbol TEXT It could be a stock symbol or a key which can be
mapped to a stock/future/option contract in
Mapping menu on AutoTrader
tradeType TEXT BUY, SELL
productType TEXT INTRADAY, DELIVERY, NORMAL
orderType TEXT LIMIT, MARKET, STOP_LOSS
quantity NUMBER quantity
disclosedQuantity NUMBER disclosed quantity, pass zero 0 if not applicable
price DECIMAL order price
triggerPrice DECIMAL trigger price
(used for stop loss order, in other cases pass zero 0)
exchange TEXT NSE, NFO, BSE
(maps to exchange column on NEST terminal)
instrument TEXT EQ, FUTIDX, FUTSTK, OPTIDX,
OPTSTK, FUTCUR, OPTCUR, FUTCOM
(maps to instrument column on NEST terminal)
optionType TEXT CE, PE (Option type, pass NA if not applicable)
strikePrice DECIMAL strike price, pass zero 0 if not applicable
expiry TEXT expiry date (Example: 28-DEC-2017),
pass NA if not applicable
clientId TEXT NEST/NOW client id, pass NA if not applicable
validity TEXT DAY, GTD, GTC, IOC (pass DAY if not applicable)
traderType TEXT PRO, CLI (pass CLI if not applicable)
marketProtectionPct DECIMAL market protection percentage
(Only applicable for Market orders, example 3.0
(which means 3% protection)), pass 0 if not applicable
strategyId NUMBER Id of the strategy which should manage this order,
pass -1 if not applicable
comments TEXT Comments for this order, pass NA if not applicable
validate NUMBER Pass 1 to validate the order, pass 0 to skip validation
variety TEXT Order variety (Regular Order, Bracket Order, Cover
Order). Valid values: (regular,bo,co)
target DECIMAL Target for bracket order (pass 0 if not applicable)
stoploss DECIMAL Stoploss for bracket order (pass 0 if not applicable)
trailingStoploss DECIMAL Trailing Stoploss for bracket order (pass 0 if not
applicable)

48 / 49
AutoTrader 2.2.0

Created with the Personal Edition of HelpNDoc: Full-featured EPub generator

Support

We provide free support in best possible way. For support related queries, we recommend
look at known problems & their solutions here.

If you cannot find a solution to your issue, then send a mail to us at


help@stocksdeveloper.com

On-call support: Monday to Friday (9 am to 9 pm)


Helpdesk Number: +91 9503569907
Created with the Personal Edition of HelpNDoc: Free HTML Help documentation generator

49 / 49

Você também pode gostar