Basics Manual

April 23, 2013

Basics

Following are the indicators that you can use in algoZ to not just study and analyze price data, but also act on them:

  • Accumulative Swing Index
  • Aroon
  • Aroon Oscillator
  • Bollinger Bands
  • Chaikin Money Flow
  • Chaikin Volatility
  • Chande Momentum Oscillator
  • Commodity Channel Index
  • Comparative RSI
  • Detrended Price Oscillator
  • Directional Movement System
  • Ease of Movement
  • Exponential Moving Average
  • Fractal Chaos Bands
  • Fractal Chaos Oscillator
  • High Minus Low
  • High/ Low Bands
  • Historical Volatility
  • Linear Regression Forecast
  • Linear Regression Intercept
  • Linear Regression R-Squared
  • Linear Regression Slope
  • MACD
  • MACD Histogram
  • Mass Index
  • Median Price
  • Momentum Oscillator
  • Money Flow Index
  • Moving Average Envelope
  • Negative Volume Index
  • On Balance Volume
  • Parabolic SAR
  • Performance Index
  • Positive Volume Index
  • Price Oscillator
  • Price ROC
  • Price Volume Trend
  • Prime Number Bands
  • Prime Number Oscillator
  • Rainbow Oscillator
  • Relative Strength Index
  • Simple Moving Average
  • Standard Deviation
  • Stochastic Momentum Index
  • Stochastic Oscillator
  • Swing Index
  • Time Series Moving Average
  • Trade Volume Index
  • Triangular Moving Average
  • TRIX
  • True Range
  • Typical Price
  • Ultimate Oscillator
  • Variable Moving Average
  • Vertical Horizontal Filter
  • VIDYA Moving Average
  • Volume Oscillator
  • Volume ROC
  • Weighted Close
  • Weighted Moving Average
  • Welles Wilder Smoothing
  • Williams %R
  • Williams Accumulation Distribution

Write your own Strategy (Scripts)

Using algoZ, you can create your own strategies using technical indicators discussed above, for buying/selling an instrument. To write your own strategy, Right-click on any chart →  Select “Scripts” → Select  “Add New Script.

The algoZ screen inside the NEST terminal

 

A strategy can be written with four expressions:

  1. Buy Script Expression – to define when a long (buy) position should be taken for a scrip.
  2. Sell Script Expression – to define when a short (sell) position should be taken for a scrip.
  3. Buy Exit Script Expression – to define when to exit a long (buy) position by selling that position.
  4. Sell Exit Script Expression – to define when to exit a short (sell) position by buying that position.

Writing and editing strategy expressions

 

This can be done either by entering the strategy using the edit boxes provided or by using the “Make Expression” function.

Creating expressions with built in vectors and functions

 

Select the required parameters for Vector/Period/Indicator and click on “Update LHS” to update the left-hand side of the final equation. Select a math function and the desired parameters to complete the expression by clicking on Update RHS.

In case you do not wish to set a condition for all expressions, you would have to type in 0 in the edit boxes for those expressions. Only the expression for which you set any condition would generate orders, provided that condition is met. Save your template by entering any name in the Saved Templates option and click on Save. You’re now ready to backtest, go live or edit your strategy.

Back-testing

Back-testing helps you to analyze his strategy and test it out by applying it on historical data before going live with it. If you are not satisfied with the outcome as indicated by the backtest for a particular strategy, you can modify the expression for that strategy and backtest it again until the results appear satisfactory.

To back-test a strategy, right-clickon the chart, click on Scripts, select the script name that you want to back-test and click on Backtest.

Backtesting a strategy

 

It will indicate buy/ sell signals generated (if any) for that script in the chart window. An upward green arrow indicates a Buy signal, while a downward red arrow indicates a Sell signal.

Backtesting results visualized

 

The user can also view comprehensive details of the Back Test, by right-clicking on the Intraday Chart and selecting ‘Back Test Details’. The Back Test Details window, as illustrated below, provides details with respect to the outcome of the strategy entered, evaluated on historical data. Corresponding to the user’s parameters getting triggered the action is taken and profit/ loss calculated, which the user can use as a reference to check whether the back-test was successful, or he would like to use a different methodology.

Backtest analysis results

 

The Backtest Analysis Info section provides details such as the Total number of trades, number of profitable and loss-making trades, largest profit/ loss, net profit/ loss and so on to better help in analysing the applicability of a strategy.

Going Live with your Strategy (Live Script)

“Going live with your strategy” means that whenever your condition as set in the Buy, Sell, Buy Exit, Sell Exit expressions is met, corresponding orders will start getting placed in the Live Market.

In case you’re using algoZ with an Investor Client login, you will be prompted to confirm the order, every time a condition is triggered. Unless you confirm the order to get placed, it will not.

In case you’re using ZT Dealer with a Dealer login, you have the option to select whether the orders are to be placed automatically, or you should be prompted to confirm the order before placing. This is explained further below.

To take your strategy to the live market, right-click on the chart, click on Scripts, select the scrip which you want to go live with, and click on Live.

Taking a Strategy Live

 

You then need to fill in your order details and set order preferences.

Setting Alert Preferences

 

Execution Period can be set to define the Start Time and End Time during which the orders should get placed. Product Type would help to select the product type that has been enabled, similar to placing of normal buy/ sell orders (F1/ F2).

‘Begin With’ field has three options: Any, Buy and Sell. If ‘Any’ is selected, the algo will simply place a buy or sell order, depending on whichever condition gets satisfied first. If ‘Buy’ is selected, the first order that the algo places will by a buy order. That means even if the sell condition gets satisfied, the system will not generate an order until the buy condition gets satisfied. The reverse is for sell.

Product Type field is the same as the normal buy/ sell order entry window. You can select MIS for Intraday or NRML for carry-forward positions in Derivatives or CNC for Delivery-based trades in Equity (in this case, care should be taken to avoid short sell).

Set Interval tells the system at what chart interval the strategy should be evaluated and orders placed. This is configurable, with a base interval of 1 minute.

You need to define the quantity to be placed per opportunity that is whenever a condition is met.

Order Type can be set as Limit/ Market/ Stop Loss as per preference. In case of selecting a Limit order, you can decide a pre-defined limit or let the limit price be determined based on the signal price, which is when the buy/ sell signal was given.

For placing limit orders based on signal price, tick on the check-box  “Place from Signal Price”. Select whether the price should be picked as the ‘Close’, ‘Open’, ‘High’ or ‘Low’ for the interval during which signal was given by selecting the option from the ‘Pick’ drop-down option.

You can also provide an offset that needs to be added to (in case of buy orders) or subtracted from (in case of sell orders) the signal price.

Evaluate as tick is used in conjunction with Set Interval. If the check box for evaluate as tick is checked, the strategy will be evaluated at every tick with the calculation based on the interval entered in Set Interval field. In effect, evaluate as tick tells the system to place orders, even in between the candle based on the strategy, instead of at the close of the candle.

Stop Loss Order trigger price allows the user to enter a trigger percentage for a stop loss order to be sent with the Buy or Sell orders generated by the strategy. This works similar to a cover order.

The dealer can also place orders for the strategy, with the same parameters, for multiple accounts mapped to him. In case of trading for multiple accounts, you can save an account list, by clicking on ‘Save’ and Load this list anytime while going live with any strategy.

Once you click on ‘Submit’, signals will be generated with an alert to act on them whenever the condition specified in the Script is met with.

Controlling a Live Script

You can view details for all scripts that you have gone live with, by clicking on Pulse Running Scripts under the Nest Plus menu. Alternatively, you can right-click on the chart and select ‘Show Running Scripts’. All the scripts that are in ‘Live’ mode will appear as illustrated below:

Viewing the scripts you’ve gone live with your strategy

 

From this window, you can pause/ resume a script, place manual buy/ sell/ square off orders, view reports for all orders placed along with total number of trades, largest profit/ loss, net profit/ loss and so on.

To stop a script, right-click on the ‘Running Scripts’ window, and click on ‘Maximized Mode’ to exit maximized mode. You will be able to view an option to stop the strategy. Click on it to pause an active script, and to resume a paused script.

Stopping a live sript

 

You can also place orders manually overriding the script, by clicking on the Buy or Sell options provided next to the Stop option. In case, you click on Buy, it will get replaced by the Exit option. Similarly, if you click on Sell, it will get replaced by the Exit option to exit any positions taken manually.

Placing orders manually

 

To view details of action taken, right-click on the Running Scripts window and click on ‘Open Report’.

Viewing action report

 

All orders placed in this manner will be visible in the Order Book (F3 window).

Viewing orders in the orderbook

 

You can distinguish orders placed through algoZ from other orders from the ‘Remarks’ column in the Order Book. All Order Book features such as modification, cancellation, order history and so on are applicable to orders placed through algoZ as well.

Zerodha

Your friendly neighborhood discount brokerage

80 comments

  1. drsuhask says:

    Dear Sir/Madam,
    I want to write strategy, but I am not able to fit my startegy in this algo. Anybody please let me know how to write this.
    1) I want to buy when closing of the candle is higher than highes of previous 9 candles & sell when closing of candle is lower than lows of previous 9 candles. This will be in hourly TF.
    2) Secondly buy will be only when the trend is uptrend confirmed by cross-over of 8 & 34 EMA in hourly TF. Sell will be vice-versa.
    3) In this system , exit from buy will be when candle closes below the lows of previous 9 candles with closing price below 8 EMA and exit from sell will be when candle closes above highes of previous 9 candles with closing price below 8 EMA.
    Please let me know how to write this strategy?

    Suhas Kothavale

    • Nithin Kamath says:

      Suhas, Will answer this in the blog where I am taking queries on strategies.

      Cheers.

    • Nithin Kamath says:

      Suhas,

      Your strategy:

      Buy expression: CLOSE > MAXOF(MAX(HIGH,8), REF(HIGH,9)) AND EMA(CLOSE,8) > EMA (CLOSE,34)

      Sell expression: CLOSE MINOF(MIN(LOW,8), REF(LOW,9)) AND EMA (CLOSE,8) < EMA (CLOSE,34)

      Buy Exit: CLOSE < MINOF(MIN(LOW,8), REF(LOW,9))AND CLOSE < EMA (CLOSE,8)

      Sell Exit:CLOSE > MAXOF(MAX(HIGH,8), REF(HIGH,9)) AND CLOSE > EMA (CLOSE,8)

  2. tks61 says:

    is back testing is required every time before selecting the code live?

    • Nithin Kamath says:

      Backtesting is not mandatory, but it will make sense to check out if the strategy would have made you money on backtested data.

  3. Siva says:

    Hi one small suggestion it would be nice if you could put all this in a audio and video format bcoz as beginner its difficult for me to understand all this I feel it would be easy to understand if its in a audio and video format.

  4. balamurugan says:

    hi Nithin Kamath,

    i have my own strategy that is

    i will enter the stock Price is 100

    whenever 101 will come one buy order will be placed automatically
    whenever 99 will come one sell order will be placed automatically

    whenever 105 will come, system should book the loss for that selling order ( 99 sell ) ,
    if the selling order is exist

    whenever 95 will come, system should book the loss for that buying order ( 101 buy ) ,
    if the buying order is exist

    please help me to write the code on AlgoZ for above strategy

  5. vishal says:

    hi Nithin ,
    Could u please help me to code this strategy.
    I need to get alert when price reaches overbought=80 and oversold=20 region in stochastic oscillator.
    stochastic oscillator settings
    %k period :8
    %k slow :4
    %D period:3
    Time frame 5 min.

    • Hanan says:

      Buy:
      SOPK(9, 3, 9, SIMPLE) > 80)

      Sell:

      SOPD(9, 3, 9, SIMPLE) < 20 Another way to interpret the Stochastic Oscillator is to buy when %K rises above %D, and conversely, sell when %K falls below %D. Interval: - My strategy -> go live -> interval -> 5 mins.
      – Please backtest before going live to assess.

  6. vkeappen says:

    I want to buy when price closes above Bollinger Band and Stochastics above 80 (and %K above %D).
    Also how to code stochastic crossover.

    • Hanan says:

      Here’s the code for your strategy. 🙂

      (CLOSE > BBT(CLOSE, 20, 2, EXPONENTIAL)) and (SOPK(9, 3, 9, SIMPLE) > 80) and (SOPD(9, 3, 9, SIMPLE) > 80) and (SOPK(9, 3, 9, SIMPLE) > SOPD(9, 3, 9, SIMPLE))

  7. Sachin says:

    Hi,

    I am very much new to this automated stuff. So kindly bare with me if the question is way too basic.

    1. I am not able to add the Nifty to watchlist in the ZT

    The Strategy I want to implement:

    On day chart on MACD Crossover: whenever a buy signal is generated I want to buy/sell Nifty options strike which is nearest to the current Nifty. Then have 10 rupees trailing SL on previous days OPEN/CLOSE.

    I want this scrip to run everyday.

    Apart from this I observed there are few more options in the trade window such as bracket, trailing ticks etc etc.

    Any more information about that will be very helpful

    Regards,
    Sachin.

    • Sachin,

      1. Nifty the index can’t be added on the marketwatch presently, you can add the futures though.

      2. You can change the time period buy the expression would be this:

      Buy: MACD(26,12,9,EXPONENTIAL)>MACDSIGNAL(26,12,9,EXPONENTIAL)
      Sell: MACD(26,12,9,EXPONENTIAL)blog.

      4. Presently brackets are still not live on ZT, we will keep you informed about this.

  8. palani kumar says:

    Hi Nithin,

    Please code me for my strategy and this is for 30 min candle chart
    consider 10.30 to 11 clock candle stick
    range = High – low (10.30 to 11 candle)
    buy= High of the 10.30 to 11 candle
    sell = Low of the 10.30 to 11 candle
    Buy Exit(target) = buy + range
    Sell exit(target) = sell – range

  9. Dilip says:

    Hi,
    How to draw Previous day CLOSE,HIGH,LOW lines each day automatically.
    regards
    Dilip

  10. Charles says:

    Hi, When i write a code having 2 conditions, trade gets executed only by the 1st condition.
    Eg. Buy : Crossover (SMA(Close,5),(Close,20)) AND Crossover (SOPK(14,3,3),SOPD(14,3,3))

    Backtest results show trade done only for the 1st condition. whatever code i use for the 2nd part, it just gets ignored.

    Plz help. I simply need SMA Crossover with Stochastic confirmations. Thanks

    • agsuresh says:

      It is strange that this query was not replied. I only got this working and also found the same issue. I had also posted the same question in one of the blogs. So far no one from zerodha has answered it. Perhaps it is due to the Navaratri holidays. But I find that recently lot many queries on these forums / blog are unanswered by zerodha team.

      I think this is basic utility provided by Omnesys to get the traders buy their advanced custom made scripts. Those are the ones they build internally with all the function capabilities.

      The present utility is crude and half baked. The concept of separate script for Buy and Sell itself may not be a not a very good idea. This means you have identify which script you want activate for a given scrip probably based on its trend (up or down). Which means if the scrip reverses the trend on a single day you will have to change the script.

      In any case, unless the multiple conditions are considered, there is no point in wasting any time on this.

  11. Chandan says:

    Sir ,
    I want to know about how to add audio alarm to entry and exit signals. So that i can avoid continues watching screen for signals.
    Chandan

  12. Nikhil says:

    Hi,

    Can you tell me how can I add several positions to one strategy, instead of doing that individually. It is very time consuming to do one by one.

  13. Lijoo says:

    Hello Sir,

    I had some problem with my Chart and Strategy back testing etc. I have called your office and the person attended (one Mr. Sunil ) has made it working very well. Thanks for the support. Keep it up. Lijoo

  14. Sukesh says:

    Hello,

    My friend and I both trade together on the same account, basically we manage the same strategy and trades together, when I am busy he works on it and when he is busy i do it. Totally we manage to monitor our trades throughout the day.

    Issue is that he logs in from his home and i have to log in from my home to the same account at the same time which gives an error message now if one person has already logged in. Is there a way we both can login to the same account at the same time?

    Thanks

  15. Dhawal says:

    Hello Sir,
    As it is mentioned above that,
    “You can also provide an offset that needs to be added to (in case of buy orders) or subtracted from (in case of sell orders) the signal price.”]

    This offset works for “buy” and “sell” ,but this offset doesnt work for “buy exit” and “sell exit”.
    Is their any solution for this???

  16. J.R.Julius says:

    Sir, Can i get donchian Channel/Turtle trading codes to back test in 30mins/1hr chart?

  17. J.R.Julius says:

    BUY Rule : Highest Price of Last 20 Candles
    SELL Rule : Lowest Price of Last 20 Candles
    Buy Exit : Lowest Price of Last 10 Candles
    Sell Exit : Highest Price of Last 10 candles

  18. S K Kataria says:

    I have been trading on zerodha for two years on my android mobile phone on NOW

    I also have IPad Air which I. Intend to use for trading

    I come across platforms such as Ztrader/NestPlus and Pi

    Can you suggest differences in their features and their adaptability to iPad and android smartphone

  19. Thankachan Y Josemon says:

    Dear Sir

    Plz make a stategy for algoz

    my stategy is

    Exponential MA (3,13,39)
    ADX

    For long

    If EMA39 is Trending UP, EMA (3 &13) crossing up to the EMA 39 and adx above 22 buy signal
    IF EMA (3& 13) crossing down Exit

    For Short

    If EMA39 is trend Down, EMA (3 &13) crossing down the EMA 39 and adx above 22 Sell signal
    IF EMA (3& 13) crossing up Exit

    Sir , Iam waiting for your reply

    Thankachan Y Josemon

  20. Sandeep says:

    Hi, I don’t see the option to add or back test strategies when I right click on a chart. I am using the new version of ZT. Attaching screen shot of the same. Pls advise.

  21. Nurith says:

    Hi Nithin

    Is it possible to apply a coustomised Indicator.

  22. ajay says:

    Hi Sir ,
    I just want to know that currently the back testing of strategy is available for only past 60 days data? and if not, then , what i should do if i want to back test my strategy for more than 60 days , and also i want to see the back test result on charts also.

  23. Nilesh says:

    Hello Nithin, How can I as a user be sure about user confidentiality? How can I rest assured that my winning strategies when executed on your platform will not be sold by Zerodha to any of Hedge Funds etc for monetary compensation?

    Also kindly provide contractural details in your customer on-boarding form which mention the customer confidentiality

  24. nanda says:

    Dear Sir/Madam,
    I would like to code break-out strategy based on Fractal Chaos Band.

    Please help to me to code the following rules for back test in PI
    1) When high of the candle touches upper band then buy on next Candle if it crosses previous high & Sell exit if there is open sell order
    2) When low of the candle touches lower band then sell on next Candle if it crosses previous low & Buy exit if there is open buy order

  25. vikas says:

    Hi Sir,
    Is it possible to scan / identify a list of scrips that have a positive or negative EMA slope for x period candle bars on a 1 minute
    chart?

  26. Raam says:

    I haven’t used Z-Connect yet. I’m going to open an account soon. I’m interested in this Algorithmic trading product. I want to know what are the metrics available?

    To be precise, can the following metrics be used in devising our own strategies?

    1) Previous Close
    2) Days’ Open Price
    3) Day High
    4) Day Low
    5) Last traded price
    6) Total traded volume
    7) Offer/Bid Price/Qty

    … Moving weekly / monthly average …

    What more? Can you give a comprehensive list?

    Is there any online documentation for the scripting language/format that you use?

  27. Amitabh Bhasi says:

    Sir, Can you help me code the following strategy;
    Buy: close > ema 50 and close crosses above ema 5.
    sell: close <ema 50 and close crosses below ema5.

    Thanks

  28. MARTIN says:

    Sir,

    I am unable to edit the trend or horizontal vertical lines for their values. I am unable to find a solution. Kindly help me out

    • siva says:

      Make sure the version you are using is latest by selecting About Zerodha Pi under Help menu, it should be dated 18/11/2016, If not uninstall this version and install again from back office Q.
      One can double click on any drawing to edit it, if still facing any issue one can write to [email protected].

  29. kamlesh soni says:

    not able to edit value in awesome oscillator in kite
    and
    please add awesome oscillator in PI

  30. Dipak says:

    I want to write code for stock trading value( price*traded qty) on 5 min or 30 min chart in Pi.
    trading value>50000000
    stock price*traded qty> 5 crore
    suggest code for this

  31. Vijay says:

    Hi,
    I need a script on stochastic momentum index that is when %K value crosses 30 on a 10 minute chart.

    Thanks

  32. Vijay says:

    Before scanning the above criteria mentioned it should check if %K line has crossed %D line below minus 40. When this criteria matches and when the %K line is above plus 30 on a 10 minute chart it should signal a BUY.

  33. MANGESH says:

    Sir

    I am using Zerodha Pi

    I want Screener code which follows following conditions

    I want to apply this screener to Nifty Stocks

    Conditions are

    1 Stock CMP ( Current Market Price ) is above last week high

    AND

    2 Stock CMP is below last week low.

    Can we apply above conditions to be satisfied and result is to be displayed.

    i also post in Trading Q&A five day before no one can replay

    Please help
    Mangesh

  34. Siva says:

    Hai,
    Please bear with my Post. I am new in trading . I wish to know the algo trading techniques.i have zeroda account.

    1. How can I get this software.
    2. How can I trade with the help of algo techniques software.

    Regards,
    Siva.

  35. Jaiganesh says:

    Hi,
    I am using Zeordha – Pi, I need a script for below mentioned point.

    1) How to identify the MACD histogram high and low for the previous range.

  36. Amiya Adhikary says:

    Help me to find my exit strategy in Zerodha Pi. For buy entry, Exit Order shall be triggered when price falls below the previous two candle’s low. And for sell entry stop loss shall be triggered when price cross above previous two candle’s high.

  37. Bhushan says:

    i want to set set variable say ‘CLOSE_PRICES’ with close prices of every minute. How can I do that??

  38. Jagadish Gowda says:

    Hi,
    I want a script for open=low and open=high.

  39. Gautam kacha says:

    Whether coding is possible for point and figure chart

Post a comment