EA’s for auto buy/sell signals – Pi

May 11, 2015


EA’s or Expert Advisors as they are popularly known especially in the meta trader community are programs that allow automation of analytic processes. What this means is that you can convert your trading strategy into a code/program, backtest it to see if it had earned money in the past, and take profitable strategies live as expert advisors. You can have multiple expert advisors running at the same time, and the EA will do the job of spotting and alerting you with any buy or sell signal that is generated.

With Pi, we have introduced the concept of expert advisors for the first time on an Indian trading platform. The next time you trade or take someone else’s advise, make sure to first backtest them, it is one of the first steps to take towards trading success.

The programming language used on Pi is called TradeScript, intended for traders who want to code their own trading strategies but don’t know how to program in low-level languages like C, C++, and others. TradeScript is good for traders who don’t know programming, and for those who are looking at it as a stepping stone to get started with backtesting or having programs (EA’s) spot trading opportunities. But for professional traders out there who are adept at coding and run complex trading strategies, TradeScript will not fit the bill. For the professional programmers we have Pi bridge through which you can fire in orders from almost any source.


Initiating backtest window

The backtest option is available under the alerts menu on Pi. You can select the contract/scrip to backtest as shown in the image below.


Selecting a contract for backtesting

Coding and Backtesting


Coding & Backtesting

  1. Your buy code in TradeScript. The example above is for an exponential moving average strategy, so Close>EMA (close,50) which means buy when closing is above 50 candle exponential moving average.
  2. Similarly click on Sell and mention the code Close<EMA (close,50).
  3. Define the periodicity of the candle and how long you want to backtest it for using Bar history. In the example above it is a 50-minute EMA, so periodicity is Minute and Bar interval is 1. I am backtesting for the last 30,000 candles and hence mention the same in Bar history.
  4. Select if you also want to see a backtest chart with all the signals plotted. If you are backtesting more than 20,000 candles it is best to not plot the chart, depending on how powerful your system is, it can crash. Since I am backtesting 30,000 candles in my example, I have kept this unticked. (See the below image on how a backtest chart would look.)
  5. Click on Back Test. All the processing is happening at your machine, so the more powerful your machine is, the faster you will see the backtest results.
  6. All the results with individual trades will be mentioned in this box. In the example above, there have been 1920 trades with 1554 losing and 366 winning in the last 30,000 minutes. Even though there are more losing trades, the strategy is still net profitable (without considering costs) as it has made 8782.5 points in the last 1900 trades.

If you are backtesting smaller number of candles, you can also initiate the chart. Usually the indicators on a backtest chart are plotted separately, this can be dragged and dropped to the main candle panel as show below.


Backtest Chart. left click on the blue EMA line, drag the white square box to the main candle panel.


Backtest chart, same strategy with 3000 candles.

Expert Advisors or EA’s

Now that you are satisfied with the backtest results, you can create your EA.

Creating EA


Creating Expert Advisor

  1. Click on “Create new Expert Advisor” under the main menu Artificial Intelligence.
  2. Give your EA a name, and if you want give it a description and/or message like I have done in the image above for the EA that I have named EMA Cross.
  3. Copy paste the same code from your backtest window for buy/sell respectively.
  4. Click on Save, this will create your EA – EMA Cross.

Taking the EA live


Taking EA live

  1. Open the chart of whichever scrip you want to apply the EA to. I have opened a Nifty future 1-minute chart (the same contract that I had backtested).
  2. Clicking on Apply Expert Advisor under the Artificial Intelligence menu opens up the Expert Advisor box. From the entire list, tick on the EA that you want to take live. We have given a bunch of public EA’s to help you get started. If you want to take only the EMA Cross live, tick on the box next to it.
  3. You will be able to see the description that we had entered earlier. You can also see that you are the owner of this EA, and it is not a public EA.
  4. Click on Apply to take the EA live. You will now start getting buy/sell signals based on this EA.
  5. To disable EA’s, untick and apply.
  6. You should also see this EA icon as shown below once you apply. You can also have multiple EA’s run on single/multiple charts at the same time which is humanly not possible as shown below. I have taken 6 EA’s live on Nifty at the same time.

After taking EA live – the EA icon

Generated Alerts by the EA


Generated alerts

  1. Click on Generated Alerts under the Alerts menu to initiate the window as shown above.
  2. All the EA’s, whenever generating a buy/sell signal, they get logged on this window with their names clearly mentioned.
  3. If you wish to execute an order based on this signal, click on the Buy/Sell box.
  4. You can change the quantity/price on the buy/sell order form.
  5. You can enable/disable sound alerts for Expert Advisors as shown below.
  6. Generated alerts can only be executed manually by clicking on Buy/Sell on the Generated Alerts page.

Enable/Disable Sound alerts

TradeScript Help

You can find the TradeScript user manual under the Help menu on Pi. We have also given over 30 public EA’s to help you get started on Pi. If you have any queries on coding a new EA, you can visit this section on Tradingqna. We also have built our Expert Advisor page, where we will soon have over 100 public EA’s with code.

Consensus – multiple EA’s

Another really cool feature with EA’s is the Consensus Report. You can use multiple EA’s and get a consensus report using all of them on how bullish or bearish a particular scrip currently is. Click on Run Consensus Report, select either single or multiple EA’s, and click on apply to see a consensus report like the one shown below.


Consensus report using EA’s

Video tutorial


Happy Trading,

Founder & CEO @ Zerodha

Post a comment

  1. Amita Patil says:

    Hello Team, I would like to develop alert for Weekly Option contracts . Following are the conditions
    1) Price is above VWAP
    2) OI is below 20 MA on 5 min time frame.

    It is possible to build it? How i can leverage this platform to automatically place buy orders when above condition is met?

  2. NEERAJ BHATIA says:

    Dear Nithin,

    I have just gone thru this document, where it is mentioned that Amibroker software is free for Zerodha Clients, only we have to give our Zerodha ID . BUT Why all AMIbroker related links are not working?

    Neeraj Bhatia

  3. vikash kumar says:

    when will be zerodha pi will be available for mac?

  4. Anmol shah says:

    Hello sir,
    I want to know how can I add stoploss and target while doing backtesting in zerodha pi

  5. Shailendra says:

    I wish to test my strategy for all scripts at one go. During and after market hours.
    I can’t find any here. Can you please help.
    I always have to click a particular script to generate signal.
    I need EA to track all script and generate signal

  6. sophy Francis says:


    I want to do backtest in pi. I need each day’s first candle’s high/low and 3rd candle’s high/low to make my strategy.
    is it possible? if yes please provide its coding.


  7. Dipan Saikia says:


    When using a crossover strategy with Hull moving average, while back testing why does Pi post an error saying “undefined function: HMA”. I can see that Hull moving average is available in Pi, then why is it not available for back testing?

    Please let me know if any other name is used for hull moving average while coding.


  8. Omkar Kulkarni says:

    I have a trading strategies when I take decisions on the basis of two different stocks. Is it possible create an expert advisor for the same.

  9. MAHESH says:

    Name few strategies form ur Algo EA page for safe trades helpful on daily basis on 30 min intervals gaps on volatile & sideways market or with market trend.
    while I tried to change Cover number from 1 to 2/3 on generating stock alerts option of PI its not working.
    Suggestion: Why don’t you add Super trend in to EA Algo codes pages just like Heikin Ashi.

  10. Swapnil says:

    I would like to know how to find day’s first 15 min high and low using script.

  11. Ankit says:

    I want to scan the candle in 5, 15 minutes TF like:

    I tried this formula in Pi scanner but it does not give correct results. When we give candle 1, 2,3 from where it start counting before publish the results? Is it takes the latest candle as 1 and last candle as 2 and previous to that as 3?

  12. Vaibhav Sanjay Gupta says:

    How do I calculate Open Interest Ratio in PI?

  13. Vaibhav Sanjay Gupta says:

    How do I calculate Put-Call Ratio in PI?

  14. vijay says:


  15. Ramesh says:

    Could you some one tell me script to do intraday trading with following strategy
    When there is break out at high side of first 15 min candle I should buy with stop loss of low of candle
    and for sell if breakout of low side . Need to reverse when the SL is triggered. I have code in amibroker but need to
    have in tradescript.

    please help us.


    • Matti says:

      Hi Ramesh, best post this query here. A fellow forum member may be able to help. Also, have you checked out Streak? You can create and manage your strategies a lot more easily.

  16. shreyans says:

    What role does “Exit Short Script” and “Exit Long Script” tabs have while backtesting.

  17. Dhanamohan says:

    I have created the own expert adviser in PI.

    Now, Is that possible to apply the EA for all nifty 50 by single click or is that possible to apply the EA script as default for the scripts.

  18. Manjunath says:

    How to use buy price in sell code

  19. Sanju says:

    plz help me with supertrend ea ! if anyone have !

  20. Ajay kumar says:

    sir i cant place order on PI chart directly whenever i try it shows error please resolve this issue fastly.

  21. chetan bonde says:

    how to take previous candle information in backtesting. for example i want to compare previous candle open with last traded price.

  22. Nirav says:

    sir..if i want to add EA on particular index..then what i have to do??
    & one more thing..how to define exit strategies..that you didn’t explaining here..try to answer at my email please..

  23. Siddhu says:

    Regarding the pi script.
    opening range candle: 1 hour
    I want to buy the stock if the stock is 1% higher than the opening range high
    & Sell when stock if 1% lower than the opening range low.

  24. Dinesh Tamse says:

    Hi Team

    PI is having a Buy and Sell scripting option in single window, so for eg. if my buy and sell signal is based on the crossover, assuming first crossover signal is for buy, than the another crossover happens and the Sell signal will trigger, after the Sell Crossover, will it wait for a new buy signal or it will Short at the same point.

    Simplifying my query with below given steps.
    1. Buy. (MACD Buy Signal)
    2. Sell. (MACD Sell Signal)
    Now the Sell Crossover is in trend……
    3. Sell / Buy (Which signal will trigger ? Will is wait for another Buy Crossover)

    Please help to understand this scenario.

    Additionally is there any other way to trigger Short trade.


  25. Ron Kalra says:

    Dear Sir/Madam,
    Just want to confirm with you that you don’t have Ichimoku Cloud in Zerodha Pi or is it that I don’t see the Ichimoku indicator in my application.
    Wondering how can I use the Expert Advisor for Ichimoku ( which is available on your site ) if I don’t see the indicator in the Pi software.
    I’ll really appreciate if you can add ichimoku indicator in Pi because all my trading decisions are based on Ichimoku.

    Thank you

  26. Ketan Khopkar says:

    Dear Sir,

    This is regarding Our Pi software.
    In back testing we have to select 1 by 1 stock, instead of that can we include the whole stock list as it is included while creating new scanner with three options as, add symbols, add MW symbols & add default symbols. and the results to be showed in horizontal manner for all the stocks added.
    Also same to be included in Scripted alert, so that we can give scripted alert for all the stocks we need at once
    or some alert popup with sound when alert generated in scanner, as, if we are working in some other window we cannot know the generated alerts in scanner until we again open the scanner window.
    This will be very useful and time saving for us.

    Plz revert if my suggestion is worth.

    Hope for your kind support.

    Thank You.

  27. Murugesh says:

    Hi sir

    can create a bracket order EA for stocks, options and index ?

  28. Suresh2011 says:

    Hi Nithin,

    Can you share Elliott wave scanner code for intraday in zerodha pi ? is there any expert advisors available for Elliott wave concept in zerodha pi ?

  29. Ashish says:

    I am getting 2 issues after creation of EA’s.

    1. Is there any way to apply EA’s to all chars of my current Market watch. Currently, i have to apply it by opening one one chart. and then have to apply EA. Also in that , I am getting message as ‘I am exceeded the limit to open charts ‘. and i can not close it.

    2. If i close the chart, my applied EA is gone and i need to do the same work again by opening chart and need to apply EA again. any way to solve both issue will be helpful.


  30. Akanksha says:

    Sir, Can you please provide me a scanner code such that it alerts me when a stock has reached at a certain pivot point like R2 or S2.

  31. mayur godase says:

    Can we create and backtest strategies for range charts in Pi ?
    I personally prefer range charts over normal candlesticks charts, so just wanted to know that.

  32. Ashish says:

    How can I get zerodha pi software?

  33. MANISH says:

    how sell 1% above the purchase value can be scripted please help me for this

  34. SATRUGHAN says:

    Hi Zerodha,
    Your expert advisor is very good, I tried this logic its very profitable on some scripts, but I can’t make this to code, below is the buy and sell script logic please make it in code.
    Buy script
    A= today low price
    B= previous low price
    C= today close price
    D= today open price
    Condition is
    A<B and
    SELL script
    H= today HIGEST price
    E= previous HIGEST price
    F= today OPEN price
    G= today CLOSE price
    H > E
    F > G OR F>G


  35. Krups says:

    I want to backtest on some script HL break on a pertuculer candle for the day. How can I apply the strategy.? Is there any document or something which gives me an idea with an example. I am new to Pi?


  36. SATRUGHAN says:

    Hi Zerodha,
    Your expert advisor is very good, I tried this logic its very profitable on some scripts, but I can’t make this to code, below is the buy and sell script logic please make it in code.
    Buy script
    A= today low price
    B= previous low price
    C= today close price
    D= today open price
    Condition is
    A D OR C=D
    SELL script
    H= today HIGEST price
    E= previous HIGEST price
    F= today OPEN price
    G= today CLOSE price
    H > E
    F > G OR F=G

    • SATRUGHAN says:

      Here is the Buy script condition, please follow this, i don’t know why some symbols are not visible main comment.
      Buy script condition is
      A D OR C=D

      • SATRUGHAN says:

        again some symbols are not visible in buy script, please make sell logic i will convert to buy script,
        please please please please please please

  37. Debolina says:

    Is it Possible To Automate Order Placement Instead Placing It Manually From Alerts ?

  38. ravi says:

    EMA (CLOSE, 5) > EMA (CLOSE , 13) AND REF (EMA (AVERAGE(CLOSE, 5)), 1) < REF (EMA (AVERAGE(CLOSE, 13)), 1)

    EMA (CLOSE, 5) REF (EMA (AVERAGE(CLOSE, 13)), 1)

  39. Sanjeeb Mitra says:

    Hi Nitin, I was trying my hand on the Back Test and found that the result changes depending on whether I click the back test chart or not. For instance, when I run the without the chart, it shows 8 profitable trades but when I click on the chart, it shows only 1 profitable trade.

    Can you please let me know the issue?


  40. kapil sharma says:

    Can any one please let me know
    1) Using EA, which signal will be produced first, a buy or a sell ?
    2) Assuming the first signal is buy & I executed the order, what will be the the next signal, will it be sell ? or it can be any ?
    3) If answer is any then what is the maximum limit to produce back to back buy signals provided that all the signals are being executed, apart from the margins required.
    How the exit strategy can be automated in this case.
    4) If answer of the query # 1) is “any” then
    Writing an EA for buy & its exit condition AND a separate EA for sell & its exit condition, can there be a case where first signal is generated based upon the exit condition without having the actual trade in place. How that can be handled, do I have access to the last trade/order executed using the EA ?

  41. JAMEEL says:

    Always seen PI is not working correctly. always gone to “not responding” plz do something on it. its not only my issue, it happened with my lot of friends. do something.

    • Nikhil Sharma says:

      Yes happens all the time.. Backtesting worked but I haven’t been able to run my scripts ever in live market.. It always(3 out of 3) have crashed.

  42. Muthu Nagarajan says:

    Hi all,

    I want to buy/sell a script based on a trigger in a different script.
    For example, I might buy a bank stock after a bullish crossover in bank nifty?

    Can someone please let me know whether this is possible in PI or Kite? If yes, will learning the coding language that can be downloaded from PI would be suffice?

    Would be great if someone could help me regarding this!!

    Muthu Nagarajan

  43. Ruchira Vats says:

    Hi Nithin,

    Built-in function LLV do not work properly. In place of giving lowest low it is giving lowest high. Can your team please rectify this issue.


  44. Nishit says:

    I want to set a variable in the Buy Script and check that variable in the sell script to determine selling price. I tried going through the TRADESCRIPT documentation on Zerodha Pi, but couldn’t find anything useful.

  45. raj says:


    I want to open ac. Before that I want to know,
    Is it possible to write script in PI to scan all scrips – EA at end of day on daily / intraday to give me alerts with single click?


  46. Hari says:

    Is there any built in Expert Advise for intraday trading on Futures

  47. Ram Niwas says:

    Hello Nithish sir good evening
    I read so many posts about auto buy sell API with kite
    my questions are that:
    1. these APIs are available with kite or third party software?
    2. any fee is required for that software?
    3. these APIs will work with PI algo generated alerts?

    with warm regards
    Ram Niwas ZL0791

    • Matti says:

      Hey Ram. Exchanges don’t allow automation for retail traders. The Kite Connect APIs allow you to create a trading experience for yourself that we may not be able to provide. Best write to talk[at]rainmatter.com with queries pertaining to the APIs.

  48. Ram Niwas says:

    How to view top volume gainer stocks in zerodha kite

  49. Ram Niwas says:

    Is any option to view to volume gainer stocks in kite?

  50. Ram Niwas says:

    Good evening to all
    Nithin sir
    I m newbie in pi and yet to be started trading . My question is
    1. Brokerage charges are higher in pi compare to kite?
    2. If I use algo in pi , there is any extra charges would be paid by trader?

    Thanks in advance
    Ram Niwas

  51. Maheswaran D says:

    I have a question. How to generate buy and sell signal using expert adviser for all the NSE listed stocks, without opening the respective charts and generating advise. My intention is, when I click a generate expert adviser button, It should advise me to buy or sell any stock listed in NSE or BSE stocks without opening the chart.
    Whereas Zerodha has the pi scanner (executes only for only one condition) which generates only “buy or sell” type of signal. I need to Buy and sell signal in the same sort of a system.

  52. Reena says:

    sir when I open zerodha kite in web page, it occur blank. In my laptop web zerodha kite platform is not opened. what is the possible fault can be, and how it can resolve. I have already write is problem to your team but result is zero.

  53. Nikhil says:

    Using Tradescript I want to find following –
    1.Once market opens by 9:15, after 5 min a candle is complete for a 5 min tf.
    2.Take that first 5 min candle and find out its HEIGHT as follows –
    3.After that for previous days find out all candles with same height of above and list it with their date & time or highlight them on the pi chart. How to code this and where I need to run this script is it Scanner or New Scripted Alert?

  54. rozert says:

    hello sir, i am trading in 20 stocks suppose, can i apply expert advisors in all of them with one click and see generated alerts ? or i have to open each chart, apply EA and then view generated alerts?

  55. sivakumar says:

    Dear Sir /madam,
    I am sivakumar, I am a b.com graduate and I would like to do a automatic trade in zerodha pi but since no one is helping me out. they re asking for coding for my strategy but I don’t know to create coding and zerodha support team ask me to go for tradingtna but I didn’t get a possible response so let me know how to proceed further and please tell how to get codings for my strategy and who will help me this scenario.


    • Matti says:

      Shivakumar, I’m afraid you’ll first have to learn how to code your strategies before you start with this. There’s just no way around it.

  56. Bhushan says:

    Is there anyway the alerts generated by EA can be put automatically in exchange?
    Or can I get sample TradeScript to automatically place Orders.

  57. Mahesh says:

    1) Is there any code for Super trend in EA ?
    2) How to apply it for multiple stock future in Nifty Midcap 50 ?


  58. Ashish Jain says:


    I did not find Online Opening trading account with Zerodha a best way, I should have opted for Offline process As this way all paperwork would have completed at the same.

    Your customer care team is not on the same page, if I ask a single query to 3 people, I will get 3 different answers.

    I am new to Zerodha dashboard so I had queries (I know there is a video tutorial available there).

  59. Lingaraj says:

    can i apply exprt advisory for multiple stocks?I want to apply the same advisor for multple stocks at once .

    • Matti says:

      Hey Lingraj, EZ can only be applied to a single stock at a time right now. You’ll have to run the script separately for each symbol.

  60. RA5982 says:

    Pi Alert to my Mobile – as an SMS.
    Possible ?

    • Matti says:

      We don’t have an SMS alert feature as of now for Pi. This is something we’d prefer to avoid as SMS delivery times are never reliable and real-time trade alerts via SMS may just lead to poor user experience.

  61. Zerodha Social says:

    Shardul, can you post this query here.

  62. 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.


    HI Nithin is there a limit to number of scrips that I could apply expert advisor. Example say my market watch has 50 scrips can I apply expert advisor to all these 50 stocks.

  64. Jai says:

    Hi Nithin,
    Can we open Pi and Kite on the same system using same user id at the same time?
    Thank you,

  65. mohd shamsh uddn says:

    i want to plot a stratgy .. in heiken ashi engulfing short & long.. 1) if green candle broken high & low of previous red candle or equal high or low of previous candle go long.. 2) if red candle broken high & low of previous green candle or equal high or low of previous candle go short.. with stoploss same candle high & low. tell me how i can get this stratgy in pi…

  66. JAY S JETHANI says:

    Hello sir . i am earning good profit from zerodha expert advisor. But sir is there anyway the alerts genrated by Ea can be put automatically in exchange?

  67. Ishaq says:

    Dear Sir,

    I was trying the Backtest in Zerodha Pi.
    I want to independently check the effectiveness of:
    1. My Buy Script with Exit Long Script AND
    2. My Sell Script with Exit Short Script.

    The first one gives result. While the second one gives error. It seems like I have to enter both Buy and Sell Script.
    Why sir? Why can’t I backtest only the Sell Script.

  68. ayush says:

    I have a strategy but i do now know how do i code it.
    Would you please suggest a way through which this strategy can be coded and backtested.
    Thank you.

  69. Pratik Uday says:

    Hello Sir,
    I have few queries…
    1) Can I backtest the Chart with 3-4 indcators at the same time?
    2) How can the code of each indicator with will be combined in a single backtest?
    3) I am applying for Finance intern from last 2 year but didnt get the chance. My MBA Finance is going to complete and I really want to start my career with Zerodha. I am regurlarly sending my CVs also but haven’t get any response.Hope to hear good from your side.

  70. Siva says:

    Dear Sir,

    I Need coding for the following techniques. I am new in trading.
    Technique 1 :
    Breakout :
    BUY : If next day by 10:30 am current price is above pivot and total volume from opening to 10:30 am greater than previous days total volume.
    Sell: Vice versa.
    Technique 2 :
    1. STOCHASTIC(5,3,3) above 75 peak breakout.
    2.RSI(14)above 60 peak breakout.
    3. MFI(14)above 60 peak breakout.

    Technique 3 :
    BUY : EMA(14)> EMA(28)> EMA(56) and RSI(14) also also closes above all.
    Sell: Vice versa.

    Technique 4 :
    1. Today’s close must be 1% above previous days close.
    2.RSI(14) must cross 68 mark.
    3.MFI(14) must cross 68 mark.
    4.CCI(14) must cross 110 mark
    5. WMA 3 crosses the WMA 5.

    Technique 5 :


  71. Kedar Joshi says:

    Dear Sir,
    In Ichimoku system, the tankan line is (Highest high of 9 periods+Lowest low of 9 periods)/2
    The code given is (SMA(High,9)+SMA(Low,9))/2. Why do we need to take SMA of high of 9 periods?

  72. Lasitha says:

    Hi Nithin Kamath,

    can you please share your opinion on the below quires?

    1. Can i able to place the automatic buy or sell order once EA gives me the buy or sell signal with quantity?
    2. Can i read the order or traded values in the EA?


  73. Issac says:

    Can we have commands to identify the MAX value during a particular time period, say 11 AM to 11.55 AM?

  74. Ajay says:

    Is there a fully automated trading possibility by adding Take profit, Trailing stop, stop loss and lot multiplier features??

  75. MANGESH says:

    I am sending u these strategies. can these be coded by ur team.

    1. When scrip breaks previous day high.

    2. And breaks previous day low

    3. When scrip is -.50% or+ .50% with price and increase in volume.

  76. Rajesh says:

    How to find inside bar set up using algo code

  77. Saravanan Mohanram says:

    Hi Zerodha Team,
    Trade Script required for the below indicators :

    1) Elder Force
    2) Chande MTM
    3) PSAR
    4) Awesome Oscillator
    5) Vortex

  78. kishor kumar says:

    sir i have a strategy
    1 when to buy
    heikinashi greencandles and parabolic sar is below the candles stochastic should below 40 level in buy mode
    exit whenever parabolicsar goes above the candle
    2when to sell
    heikinashi red candle and parabolic sar is above the candle stochastic should be above 60 in sell mode
    exit whenever parabolicsar comes below the candle
    how can i write the code and how i backtest it and make alerts of buy ,sell signals
    please help me regards this

  79. NITIN says:


  80. Ravi says:

    Is there a way to code in EA such that there are no short sells. A sell should only happen if there is a buy before.
    This is for intraday.


  81. Santosh says:

    Hello Sir, Is there a release of Pi that can be used on a Mac?
    I can see only a Windows platform download available

  82. mahendra pawar says:

    Dear Nitin sir,

    i will see all the videos related to pi expert advisory but i want to know how to add my developed strategy with coding. help me i am new user and also a new online marketing partner. ZG2588

  83. Parth says:

    I had a doubt for the scanner ! how much scripts can be added to a scanner ? and cant we create our own list for the scanner? as in i want to scan all the fno scripts how can i do that ?

    • siva says:

      No limit as such,one can create their own list and yes can add all fno stocks but one has to add each scrip individually. For further queries on this you can write to [email protected].

      • Parth says:

        Adding indiviaully would be a very hectic task ! would request you to make one predefined space for the same ! even once we create the list we cant save the same right ?

  84. sagar says:


    Can you please provide functions to get current position price.
    I.E I want to exit position with RR ratio say 1:2 or why so
    if I bought share for say 100 with autobuy and if price goes to 104 they it should sell and if it goes 98 it should exit position ie… maintaining 1:2 RR ration.

    It would be helpful if there is user manual containing all function to refer.


    Waiting for reply

    • algogeek says:

      In tradescript LAST defines last traded price, if you want to get alert on any price you can write LAST > 100,
      the complete reference of tradescript documentation is available under help menu -> tradescript help.

  85. vilas Panchal says:

    Sir, request to make same thing for mobile application and web kite, as many users may not laptop /pc,

  86. Abhishek says:


    Can the algorithm be set to trade in options?
    If yes then can it select the option strike based on a logic and implement the trade at a specified time?
    Can the square off be automated based on MTM of two trades rather then stop loss of single option?


  87. dheeraj sharma says:

    PI is the best trading platform i have ever trade on
    but it needs just one ……. just one thing …………. scanner alerts should be shown in generated alerts window.
    can you please add this feature in the later update …. please insure me with a time frame

  88. Anklesh Vishwakarma says:

    Can you guide me if their is a script or way so I can execute my order at given perticular time…
    I m in search that more than one order can execute on time set by user.

  89. Barun says:


    I have zerodha account. Query so simple but still not answered by any trading house, why there is no alert sounds or popups for Supertrend indicator. If there is alert facility, then there may be high percentage of winning trades. Please make some options for alert sound or pops for selected scrips.


  90. Saurabh Kelkar says:

    I want to code the following:
    Buy the nearest ATM Straddle (Call and Put) for nifty in the morning.
    Sell once the movement is above 20 points etc. Intraday

    Possible to Backtest ?

  91. khalid says:

    Dear Nithinji,

    Can I do back testing with the formula of average true range ?
    best regards

  92. Jamuna Rani D says:

    Your service is good, I have two doubts please clarify

    1. How to change the bank details in zerodha…

    2. The recent update of 52 weeks high and low and open, low and high filter is very good. but why F&O stocks filter is not able.

    Awaiting for your reply


    Jamuna Rani D

    • Akshay.A says:

      1) To change/update the Primary bank details, you’ll have to send the modification form with the cancelled cheque/bank statement and courier the copies to our Bangalore address. If you wish to add a secondary bank for fund transfer, then you’ll have to send a scanned cheque/bank statement to [email protected]

      2) F&O Contracts are for 3 months, So you wouldn’t get 52-week OHLC. There is a continuous futures chart where you could get the OHLC based on how the continuous futures chart is designed. The 52week high and low is not filter, but if any scrip added on marketwatch it will be highlighted if those values are breached

  93. Kashi says:

    Is there a way to load pre-market F&O limit orders into Pi using tradescript?

  94. Birbal says:

    ek he indicators bahuat sare terminal mai kaise aa jata hai .exm— sharekhan indiainfoline aur aapka pi bhi samil hai .hum convert kyu nahi kar sakte hai.

  95. Birbal says:

    mt4 ka indicators kaise add hoga pi mai.

  96. aman says:

    why to use pi if thr kite?? can any1 explain. m new here.is thr is free exprt advise in pi??

  97. Nida says:

    I want to apply an EA on a 30 min chart. So, I open the chart, set it to 30 mins and then apply the EA. But the EA always seems to be running on the 1 min chart, generating alerts “-[1Minutely]”. Anything else I need to do in order to get this to work on 30 min interval?

    • Nida says:

      Another question related to the above. I keep getting ‘Your script generated an error’ on the scanner screen for my script and the same script runs absolutely fine on the Backtesting and EA screens. Is there any formatting required?

      • Venu says:

        I’m assuming you’re copy pasting the code from the Backtesting screen to the scanner screen. Have observed that by copy pasting, it loses the formatting. This may be the reason you’re getting the error.

    • Venu says:

      Can you send your code to [email protected] so that we could review and give you feedback?

      • Nida says:

        Thanks for the prompt reply, Venu. I have sent the code to [email protected]. I noticed that the scanner clears all the new line characters of the code. So, I gave a space between each line, but that did not work either. Also, what about the 30 min chart for EA? Why does Pi only consider 1 min chart when I run EA on a 30 min chart?

  98. Adinarayana Raghu says:

    How to use 2 different indicators in the same script?
    For example a MA and the uptrend with points

  99. Parth says:

    Please add Percentage Profit & Loss in the Equity holding section in PI.

  100. Ravindra Kumar says:

    I want to make following trading system
    When last price is greater then closed price by 0.5%. The script should get buy. And when the script moves further 0.3% above the buy price, the script should get exit, also stop loss will be below 0.3% of the buy price

  101. Bimal Jain says:

    I dont find many examples of coding for Back testing. More importantly there is not a single example related to Exit coding. I have written a code related to RSI trades but the back testing is showing absurd results.

  102. AMIT says:


  103. Sanjay Vetal says:

    I am newly registered on Zerodha, I am dumb at coding, I am doubtful whether I will be comfortable trading at Zerodha.

  104. Rohit says:

    Hi Team,

    I have a strategy where I use multiple indicators for a chart. Can I use multiple expert advisors to give me an alert after considering in all the factors which I have put for each an every expert advisor.


  105. charan says:

    pls code for open high and open low scanner with top traded quantity for Intraday

  106. RAJ MOHAN BORO says:

    i am not able to use expert adviser in my pi as i can not install it .i called regarding this problem but no use .i am trading only on kite please do for me so that i can use expert adviser on my pi softwear.my id zu3425

  107. Pratheesh Karthikeyan says:

    Sir, while running backtesting in Pi, im not getting buy sell arrows in chart as shown in the above example though my buy and sell scipts are generating signals based on which backtest window is showing profits and losses. Will wait for your comment. Thanks

  108. Sagari says:

    If i added and loaded a new scanner coding with number of stocks, does it give me the signal as soon as the crossover happens or do i need to load the scanner again after particular time.

  109. Jayaraj says:

    dear sir,

    how to install nest platform.i tried multiple time i cant do it.please explain correct way.

  110. Ajinkya Patwardhan says:

    Will ea be created to buy sell on supertrend on renko chart???
    Or it is too complicated???

  111. Kuberan says:

    Thank you for the scripts and the scripting feature.
    The user has to add each script to each stock one by one. If he has two or three computer systems, does he have to repeat the process manually on all the systems? Perhaps, copying a configuration file in Pi installation folder in my desktop and pasting it into Pi installation folder in my laptop must bring up my setup in desktop to laptop. Does the feature already exist? if the answer is no, would it be possible to add it in future? Thank you.

  112. Ananth S H says:

    Dear Nithin

    While trying backtesting in Pi, I noticed there is no option to enter ‘weekly’ in the “periodicity” field. It allows us to enter only minutes or EOD prices. I can not test any strategy with weekly closing prices. Can you configure this option as well.

  113. mukesh says:

    hi, can you please add live testing/simulation environment for walk forwarding testing our strategies please… thank you

  114. atul says:

    i want to backtest but zerodha pi is showing
    502 Bad Gateway

  115. Dilip Sharma RD2620 says:

    Dear Sir, Please let me know how to configure voice alert for buying signal and sell signal.

    thanking you

  116. Sandep says:

    I want to backtest 3EMA(3,15 & 51) indicators to generate buy or sell signals.The strategy should be this:
    1.For buying – 3EMA crosses 15 & 51
    2.For selling – 3EMA crosses 15 & 51 on downside.

    Please help me with the code of this strategy so that I can backtest it.

  117. Keshav says:

    Hi can I use Pi on Mac OS??

  118. Abilash says:

    How to select all stocks for backtesting zerodha pi.. In datasource I can select only one stock in EQ.. I want to back test on all f&o stocks or all the stocks having margin for intraday trading in Zerodha in equities. What to select in select for entering in data source? Thanks

  119. Navo says:

    Hi Nithin,
    Really need your help in writing an automated script for me. When I try to execute it on PI it throws an error.

    My code should have all the following conditions.
    1) 300 Daily EMA & 200 Daily EMA is MORE THAN 20 Daily EMA AND
    2) Open price is below 20 Daily EMA and LTP should be above 20 Daily EMA AND
    3) Previous Close price is GREATER THAN 13 Daily EMA AND
    4) 5 Daily EMA is more than 13 Daily EMA AND
    5) 5 Daily EMA is more than 20 Daily EMA

    Awaiting your response.. Thanks

  120. Vaibhav Sarupria says:

    can expert advice be added to all nifty 50 stock without opening the chart

  121. Ajay says:

    Is it possible to generate automatic trades using moving averages on Pi or other zerodha software.

  122. Arjun Singh says:

    I have a query, the EA i wrote keeps giving me buy/sell signal again and again whenever a new candle forms and the condition is true, “even when I am already in trade and had placed an order”. How to stop this?

    • algogeek says:

      In EA alerts will be generated when the condition matches with LTP , the buy & sell signals also due to repainting of current candle, also verify your script and try to use it on close of the candle. you can post code related queries in tradingqna.com

  123. dipesh dadhich says:

    Hi sir,
    while trying backtesting in zerodha pi, i applied buy and sell code of EMA that shown above in the article and start backtest. Everything goes fine but the chart doesn’t show any buy and sell arrow. i tried backing on nifty dec future on one minute periodicity with 1 bar interval for 30 days.
    Please help me out on this as I’m eager to study backtesting.
    Thank you.
    This is the 3rd time I’m asking this ques. please rply..

  124. Ganesh says:


    Can I get a code for setting up an alert system whereby:
    1) Price breaks the VWAP line (both upside & downside)
    2) MACD bullish and bearish crossovers


  125. Arjun Singh says:

    Can I run multiple EA on multiple instruments at a single time, without opening their chart.

  126. saurabh says:

    Started trading recently with Zerodha and satisfied with the platform and services. I am trying to backtest intraday MIS strategy with Pi but getting some weird results. The buy and sell occurs only when conditions are fulfilled but I want to exit on day end or some exit conditions (even exit long and exit short conditions seems to be fishy) . Can someone please help me with this.It would be great if some example with buy & sell script is provided.

  127. Arjun Singh says:

    Suppose, an EA gave my buy signal and I placed the trade according to it. After some time the same EA gave me sell signal on the same instrument and I placed the sell order, at this time will the long trade be automatically closed by pi/EA or do I have to manually close it (after entering sell order).

  128. Arjun Singh says:

    I have a query, consider I have also coded the Exit Long and Exit Short script with the buy and sell script, will pi generate the exit trade button(signal) in the generated alert window? Or will it only generate buy and sell signal?

  129. Kiran says:

    Is there are strategy available for Renkos using EAs ? Renkos with PSAR or EMS crossover etc ?

  130. dipesh dadhich says:

    Hi sir,
    while trying backtesting in zerodha pi, i applied buy and sell code of EMA that shown above in the article and start backtest. Everything goes fine but the chart doesn’t show any buy and sell arrow. i tried backing on nifty dec future on one minute periodicity with 1 bar interval for 30 days.
    Please help me out on this as I’m eager to study backtesting.
    Thank you.

  131. Nishanth K says:

    How to plot backtest chart? I can see one green and red arrow on the corner but nothing other than that. NO help document as well. My trade script generated at least 20 trades but i couldn’t see any single arrow out there.

  132. mehathab says:

    how we use multi time-frames for same (one) script.
    and could I get ea for my own strategy
    thank you

    • Venu says:

      There’s no option to use multi time frames on a single chart. Also EA or tradescript works with OHLC values and timeframe cannot be set through code, one will have to change/set chart time frame manually.

  133. dipesh dadhich says:

    Hi sir,
    while trying backtesting in zerodha pi, i applied buy and sell code of EMA that shown above in the article and start backtest. Everything goes fine but the chart doesn’t show any buy and sell arrow. i tried backing on nifty dec future on one minute periodicity with 1 bar interval for 30 days.
    Please help me out on this as I’m eager to study backtesting.
    Thank you.

  134. sandip says:

    hello sir, while creating tradescipt EA for backtesting what function to use for supertrend?
    I used ST,STR,SUPERTREND, but it was showing undefined function.

    Buy script:
    TREND(SUPERTREND(15, 5), 5) = UP

    Buy script:
    TREND(SUPERTREND(15, 5), 5) = DOWN.

  135. shashank shekher says:

    How to scan multiple stocks for supertrend crossovers and correspondingly generate alert on the pi screen?

  136. NAVEEN SAROHA says:


  137. vinod says:

    Sir, please add Supertrend code for expert advisor. so that it can be available for trading.

  138. Taneja says:

    Hi Nithin & Siva,

    Being marketing partner of Zerodha , I would like to help my referrals for algo trading however as per my experience , other than a good platform for trading i see lots of missing points which should be at one place in proper procedure. AS of now please help me to get these queries resolved

    1.) Full step-by-step procedure to do fully automatic trading. ( it would be using Pi , kite or separate terminal ? As after reading many post on Zconnect and FAQs and tradingqna , all is messed up ……. Dealer terminal is required, Amibroker plugin, Kite data and APIs……. Algo approval , Exact fee ? any fee for data or software ? for AP need to register for NSE/BSE separately ? , Can you please consolidate all at one palce and explain using what a trader can do with different products …for fully automatic trading

    2.) In Pi while testing out some strategies for backtesting , there are lots of stocks to select then how we can select multiple stocks in one run for a strategy . it’s very time consuming to select one by one and testing it out as we need to fine tune the strategy as well so it’ll take much more time !!

    3.) For a single stock we backtest and change the parameters in strategy to get good result buy there are lots of factors in backtest result report that I know their meaning (Definition) but don’t know their affect on performance , so it would be good if your expert team can provide more detailed explanation with examples which strategy should be considered good or bad with risk,reward, sharpe ratio and so on.

    4.) I feel for backtesting there should be more data as it would include all type of mkt data (uptrend, downtrend and sideways). Generally 4-5 months mkt would be in same trend then backtesting results are very favorable . Is it possible to backtest any strategy with Kite API with full historic data?

    5.) Do you have any plan to share other strategy to traders same like OpenTrade ?


    • 1. If a client is declaring that he is automating trades, he needs to become an AP on the exchange, get approvals for the strategy. Either Kite connect API’s or Pi bridge will work. If strategy involves BSE, then yeah that as well.
      2. If you are trying to do this for automation, suggest you try backtesting on Amibroker. Pi is just a good starting point.
      3. All the details of this is available on google. Lots of information on these ratios.
      4. Yes, you can use Kite API to backtest.
      5. Hmm.. no plans as such.

  139. Srikanta Kumar Naik says:

    Sir, i need Supertrend code for expert advisor. Please give.

  140. RIYAS says:

    back testing with my strategy showing buy sell signal properly and profitable trades but i applied the same strategy in scripted alert on live market it shows extra buy sell signals and trade end up in loss, why it happening how i can solve it.
    when am checking the graph after market back testing graph and live market graph not matching

    • siva says:

      Create scripted alerts refers with current running candle, as repainting of candle happens you may get some more/false signals, repainting happens in every charting platform, to avoid this you can refer to previous candle or trade on only after close of the candle.

  141. Pritish says:

    Trying backtesting and noticed on many results where it shows loss but percent profit is 0%. Is this an error or expected? Can post more examples if required.

    E.g. EMA – DI crossover applied on BANKNIFTY DEC FUT 3 minute 10 day, results in:

    Total number of trades: 2
    Number of losing trades: 2
    Total loss: -528.5000
    Percent profit: 0%

    • algogeek says:

      As per the above regarding profit / loss it is calculated with values given in the summary.Also,for last trade it is difference of the closing price of the chart data and last signal in summary section. you can check it in detail in back-testing summary section.

  142. AKD says:

    Hi! I’m new to Zerodha “PI”.
    Does it possible to use PI “Scanner” (PI>Alerts>Scanner>New Scanner) to scan & short various Stocks based on their EOD Data (as EOD scanner)? Because, I’m getting only “Minute” & “Hour” options in “Periodicity” drop down menu! Is there any alternative option?
    If “Yes”, then requesting you to kindly let me know the procedure.
    If “No”, then requesting you to kindly incorporate the “EOD” scanning facility in to “PI”, which will be a great help to us & make the system near completed.
    Wish to have a prompt reply from your end as always.
    Thanks in advance.

    • algogeek says:

      In Pi, the scanner feature works only in the live market hours as it scan or check based on last traded price of the given conditions to the list of stocks, currently in scanner there is only minute and hour time frame and no end of the day candle time frame as scanner will not work after market hours.
      We Will pass on your feedback.

  143. BHushan says:

    Can you pls share ea for GMMA

  144. srinivas says:

    sir, i am new to pi. while playing around software pi, i noticed that the results generated in back test (buy/sell signals) i.e., the green arrow and red arrow are not plotted on the graph. do i have to enable/disable any option so see the signals. please reply soon dear.

  145. Arjun Singh says:

    Sir, What’s the difference between creating scripted alerts and creating expert advisors? As I see, in creating scripted alerts there’s an extra option to write exit long and exit short strategy, but in creating EA, one can only write buy and Sell script. Does the scripted alerts generate buy, sell and exit trade(long/Short) signals?

  146. Bipin says:

    Hi All,

    I have 2 questions. How can i save the out put value of Average true Range in to a variable and similarly how can i capture the Super Trend Value in to a variable. Please share the formula for the same

    Thanks in Advance


  147. PRAMOD says:

    Just wanted to know how many days Intra day (ex. 5, 15,30,60 minutes) historic charts that we can view in your Pi software.
    Is it displaying intraday Charts for > 30 days ?

  148. harish mehta says:

    sir, can u speck in hindi ? sir, this pi softwear is very use fully but, i dont no this softwear using guide so pls , give me provide buy or sell automatic signal demo request, i have all ready zerodha customer so, pls help me use this softwear knowladge i all ready new user thank

  149. Prashant says:

    Hi zerodha team,

    One input for pi :
    Every trader has his liking for one or more EA’s which is used by him on daily basis for trading. So it will be of great help if EA’s are included in chart template so that can be used very easily.
    Pl. Include this in future releases if possible.

    Best regards,

  150. Prashant says:

    Great….. Thanks for the prompt reply..


  151. Prashant says:

    Hi nitin,
    I have two queries regarding EA’S
    1) Can one EA be used on multiple charts during market hours ?
    2) if yes then, can the settings be used next day , so that we don’t have to do them again ?

    Thanks in advance

  152. sunil tyagi says:

    please provide supertrend in expert advisor.

  153. Himanshu says:

    Is there any way to optimizing indicators values (like in Amibroker) in zerodha Pi. I would love to do backtest while optimizing my indicators value for certain stocks. Thanks

  154. DEBOJYOTY DATTA says:

    Ichimoku Cloud Trading Strategy Given on your site backtest failed

    Buy script

    SET C = (SMA(HIGH,9)+SMA(LOW,9))/2
    SET D = (SMA(HIGH,26)+SMA(LOW,26))/2
    SET A = (C+D)/2
    SET B = (SMA(HIGH,52)+SMA(LOW,52))/2

    Sell script

    SET C = (SMA(HIGH,9)+SMA(LOW,9))/2
    SET D = (SMA(HIGH,26)+SMA(LOW,26))/2
    SET A = (C+D)/2
    SET B = (SMA(HIGH,52)+SMA(LOW,52))/2

  155. Krishna says:

    Hi ,

    I need to know, is EA can be integrate with mobile version of kite.

  156. Pradeep says:

    Dear Nithin / Any Expert,
    Can you please provide details about the trend() function. I would like to know these details about this function: 1. How many previous candles does this function consider to decide about the trend? 2. Does it help in quickly getting the trend change? 3. Or is this useful only the determine the already prevailing trend?


  157. ANUJ says:

    Why cant zerodha add a windows to select the data from this date to this dat e.g 2/02/16 to 02/06/16.max. range of four month will not breach. software will work properly…….and backtesting can be done also on any range of date.

  158. Jyoti says:

    Being a beginner, it would be helpful if you could make some video clips of EAs’ & quant topic there is lot of things to remember and your presentation quite complicated, hope you will do the needful.

  159. Bhushan Kela says:

    Hi Sir,
    I want to know about the Expert advisor in live markets for the following strategy.

    It should scan the market watch or entire market alongwith Futures for OPEN = HIGH and OPEN = LOW condition.
    Is it possible. Please let me know.

    Bhushan Kela

  160. MR says:

    Could you please provide the trascript setup on Pi for the following code:

    MACD 12,26,9
    CCI 10,-100,100
    RSI 14,70,30

  161. Sudhish says:

    Can you please advise how I can write script to scan all scrips at end of day on daily chart to give me alerts ?

    for eg -:

    At the end of day I would like scan all scrips to find the scrips which Satisfies


    How would I do it ?

    • algogeek says:

      Create scripted alerts , scanners or Expert Advisors only works in live markets on intraday charts with live ticks based on last traded price, it will not give any alerts on after market hours, if you want to check the signals on daily basis with day candles you can use backtest and check with historical data.

  162. Arka says:

    Hi my comment has been awaiting moderation since Aug 8. Could you please look into this?

  163. S RAJASHEKAR says:

    I need a code for the following strategy
    Crossover of moving averages and MACD

    SMA 26 EMA13 WMA 9 AND MACD 26.13,9

  164. Arka says:

    Dear Team,

    Firstly, highly impressed with how far Zerodha has come and wish you luck for the future.
    Onto the query,

    I tried the Bollinger Bands EA code from the Zerodha site: https://zerodha.com/expert-advisors/code/bollinger-bands-trading-system

    I applied this to Spicejet stock with a periodicty of MINUTES , Bar Intervals 30 and Days 30. Following is the o/p without the ratios:

    Total number of trades: 1
    Average number of trades per month: 3
    Number of profitable trades: 1
    Number of losing trades: 0
    Total profit: 4.2000
    Total loss: -0.1500
    Percent profit: 96.429%
    Largest profit: 2.3500
    Largest loss: -0.1500
    18-07-2016 14:45:00,LONG,62.9500
    27-07-2016 11:15:00,SHORT,64.8000
    02-08-2016 14:45:00,LONG,62.4500

    I am unable to completely understand this data.
    1. It says total trades 1 but there are 3 trade points
    2. How is 96% profit calculated?
    3. Total number of losing trades is 0 yet there’s a loss amount
    4. Does the algo consider squaring off at the EOD for respective trade?

    Thanks and Regards,

    P.S. Are there any online resources to learn TradeScript?

  165. sr says:

    pi is no doubt one of the best trading platforms i have seen so so far
    but there scope for improvement.
    on immediate terms can you add an alert feature in charts/stocks when it crosses certain level
    and xabcd cypher and Elliott patterns in charts
    currently have to use tradingview alongside pi in multi-screen setup

  166. Vinay says:

    i need code for below startegy to apply as ALERT in PI for selectred scripts .

    1) BUY SIGNAL:

    a) 13 EMA crossover 34 EMA from below oving upwards..
    b) Parabolic SAR is below candle .
    c) stochastic ( 10,3,3) is above 50 .


    a) 13 EMA crossover 34 EMA from above moving below.
    b) Parabolic SAR is above candle .
    c) stochastic ( 10,3,3) is below 50 .

  167. Priyank Saxena says:

    Back testing strategy doesn’t works with ICHIMOKU indicator, whenever I backtest on one stock so it keep on back testing the same stock, it doesn’t allow me to change the stock for another backtest. And whenever I press stop backtesting it opens another graph of same previous script, and this keeps on going till I logout and again log in to the Pi.

    Please look in to the issue.

  168. Mohan says:

    How to program an EA for stochastic? Do anyone have the script?

  169. Raja Rajan says:

    Just uninstall PI and its components completely and then reinstall PI again

  170. Ashish says:

    hello team,

    I’m just unable to “stop backtest” since it’s keep on opening new tab. can you please explain how to stop that? also each new tab unable to close since its giving me error message “The chart is currently in use”. please help on this issue.

  171. Satya Prakash Chaudhary says:

    Regarding Back Test:
    It is seen that when I put a Script/EA for the back test, it generated orders at the CLOSE price of the CANDLES instead of actual moment the script conditions are met.

    Why it is like that?

    Whether the script generates alerts in same way when LIVE in Market?

    Kindly explain the logic of working of EA in LIVE market.


    • Siva says:

      It is because if the conditions are met same signal can be generated any number of times during the candle formation and it does not make any sense, also few times the conditions might get satisfied during the formation of candle but were not after the completion of the candle. The same in live markets.

  172. omprakash says:

    Hi my id is DO0042.Omprakash. Can you please tell the formula for how wti crude oil in dollar is converted to mcx crude oil. eg: Current price is $46.71 and how this price is calculated in mcx crude oil the formula.

  173. Sudhish says:

    Will generated alert execute the alerts automatically, will it just signals when alert becomes true. Also can anyone explain how to edit or delete generated alerts in PI

    • Just give buy/sell alerts. You can edit it by clicking on the same screen where you see all expert advisors. See the image with title “After taking EA live – the EA icon”

  174. Monojit Roy says:

    Hello Kamath/Team,

    I am great admirer of you. You folks did a great job which is commendable.
    Today I am posting one query –

    I have downloaded MT5. Can I bridge NEST with it to trigger AUTO BUY/SELL orders. Also help me how can I open NSE futures/cash segment in MT5.

    The supertrend charts are really quick and human error is something that is losing the business. Please help me.

  175. Rohit says:

    Hi Nithin,

    Is it possible in PI –
    A scanner query like –

    1) Give me the list of stocks from my watchlist who’s Weighted closing & Typical Price say 30 is about to cross over in say – 15 mins timeframe ?

    2) Give me the list of shocks from my marketwatch whose CMP is breaking up or down the price defined by me.

  176. kusum lata says:

    can we increase market watch from 5 to 8.

  177. waqar says:

    is metastock language works on your software…?

  178. Bharat says:

    i just new join and try to understand Create New Expert Advise. I have create new advise name as “Test 1”
    i have applied it on one particular stock . but after close the chart by default Ea strategy also close for that stock. i have to create repeatedly if chart is close and open .
    Is there any solution whenever i open chart my created expert advise will be continue.
    And also i want apply my created strategy to all stocks without open each stock charts.

  179. Srivida says:

    Hi Nithin
    Want to start with thanking you for all your and your team’s efforts on zer0dha. BIG FAN…
    I have written a few strategies on PI and have backtested them. The strategies involved EMA 10, EMA 30 and EMA 50 in one way or other. I have copied them to EA and have applied them on charts too. All went well. My question is this:
    If I open a 10 minute chart for a script at 915 am and apply a EA with EMA 50, will the EA wait for 50 10 minute candles to passby for the day before generating an alert or is the EA applied on running candles no matter the day? IOW, will my EA start generating alerts (if they are applicable) from the first candle of the day itself or will it wait for sometime for some kind of validation?
    A reply is greatly appreciated.

    • It will depend on the chart you are looking at. It will be based on the data on the chart. If your chart has 50 10 min candles, it will start getting signals immediately, if not it will wait for the time period to complete.

      • Srivida says:

        Thanks for your reply Mr.Kamath. PI doesn’t allow me to see more candles than that is generated during the market hours. IOW, I can see only the candles that are pertinent to the trading day in PI when I open a chart. How I fix it? I need my alerts / EAs to be effective with the running candles.

  180. kusum lata says:

    sir will you introduce buying or selling on limit price in Bracket order. if we want to buy 3000 share in intraday in any script it buys on different prices which fails our strategy.

  181. Omkar says:

    Is there any procedure to register my own technical indicator which offered automatic signal. Where shud I GO ?

  182. Murugesh says:

    Hello sir any huge buying or selling is there ??

  183. Arvind says:

    Hi Nithin,
    What are the system requirements to automate the trade ? Also, is it required to be online or offline also we can automate?


  184. ashvini hajare says:

    hi ! I am using supertrend for my trading . I am trying to use code for this indicator. Can you help me to code this & is it applicable on pi charts ? Also I want to know whether is it possible to code multiple indicators in different time frame ?

  185. Wajid says:

    Back test with 120 days is hardly useful.
    When will the limit be increased ? it is still 120 days..

    • Siva says:

      120 days of back-testing for intraday data gives facility to back-test up-to 60,000 1 minute candles. One can do backtesting on daily candles for last 10 years.

  186. Raam says:

    Is there an option to execute the Auto Buy/Sell signals generated, without user intervention?

  187. Vivek says:

    hI Nithin ji,

    Please correct this script,

    last< ema20

    ema20 <psar

    this is for scanner, how to choose 5 mtf and 15 mtf on scanner ?

    • algogeek says:

      For the above condition

      LAST < EMA(CLOSE,20)

      EMA(CLOSE,20)<PSAR(0.02, 0.2)

      you can also post code related queries on tradingqna.com

  188. nagesh says:

    Do we have scanner for supertrend like it shud show scripts which are belw r abve supertrend at the eod or during the day.

  189. ravi says:


    How do i check for a script which enters as soon as a price is broken on the up side ( down side for shorts ) . Currently all the scripts seem to work only on the candle close basis.


  190. Jose says:

    Hi Nithin,
    Can I use EA for positional trades? or is it only for intraday trades.

  191. sunil says:

    Hie Experts.

    I`m trying to write a script but not able to convert into running script
    my idea is


    Two moving average
    Set A = WWS(CLOSE,5)
    set B = WWS(CLOSE,15)
    buy when
    crossover(A,B) and
    sell when

    now i want to introduce stochastic momentum index also in above formula , what i understant from manual is
    below formula

    Stochastic momemtum index
    SMID(14, 2, 3, 9, WMA, WMA) > 40 OR SMIK(14, 2, 3, 9, WMA, WMA) > 40

    but dont know how to combine this with above crossover

    any help with be grateful


  192. MANUS says:

    In your Pi software if I tick one EA from Artificial Intelligence drop down menu, what happens? Whenever the conditions match buy sell arrow erupts or sound alert comes? Or none? How to use your artificial intelligence on live chart for profitable trading please?

  193. AHSAN says:

    hi nittin,

    i want to know that what is the use of go live button in create alert option. is it auto trading button according to our script or somthing else

    • Venu says:

      No, there’s no auto trading permitted on the retail trading platform. By clicking on Go live, alerts start getting generated.

      • Shabeer says:

        Hi venu

        But is that generated alert buy/sell button really working ? I am facing problem for a week now that only first alert button works but rest of the alerts order being rejected with error message ” client order Id already exist ”
        Means if you enter long or short by an alert you will have to exit manually , even if there is an exit alert that button will not work !
        I had raised several tickets now and they are working on it , hope a solution soon
        Is that really a technical error ? Or it’s only with me ?
        Even after reinstalling Pi 3 times and tried it on an other PC
        Can you suggest something from your expertise ? As I am missing so many trading opportunities !

    • Shabeer says:

      Hi Ahsan
      I would like to know , are you using Pi EA and are those buy/sell working for you.
      I mean every generated alerts one by one working for you iwithout any trouble ?

      • AHSAN says:

        hi sabeer ,
        i will let you know by tommarrow i will test everything then i will talk to you
        thanks anyway.

  194. gopi says:

    Hi , Am i missing something??
    I applied the EA and what i get is only alerts(under alerts–>generated alerts) , but dont get any buy/sell icon on the actual live chart ..
    my requirment is very simple , i need my own customization indicator to be displayed in the chart . just like when i apply study , i can see that indicator on my chart .
    hope i explained with east , please help me

  195. Vineet A says:

    1. While going through Tradescript strategies provided, I noticed that the candle stick pattern in Buy/Sell signal have been derived using the reference value of OHLC, which makes me wonder, does Pi’s expert advisors supports the candlestick pattern constant as given in Tradescript pdf for eg. can I use CP() = BULLISH_ENGULFING_LINE instead of those references in Pi’s EA?
    2. Suppose my strategy requires the following condition : (Morningstar OR Dozi) AND MACD Up Trend. How can I go about it?

  196. santana says:

    Hi Nithin,
    Many companies/brokers have started fully algotrading feature on VPS server.

    Are you planning to start like that.

    Peoples have strategies for fully algotrading.

    kindly reply.


  197. Rohin says:

    hey.. kuddos Nithin,for providing broad spectrum of EAs 🙂 I wanted to know if there is way where i can backtest strategies for longer interval of time say like over period of year

  198. Vijay Krishnan says:

    I want to write a script that would apply an EA over all NSE Stocks and write out the output to a text file. How do I achieve this? How can I loop through all the NSE Stocks? I am currently manually backtesting one stock at a time against an EA. It’s taking around a week to identify stocks for delivery based buying. Please do let me know

  199. pranjal rajput says:

    Can expert advisor code consider other scrips while generating the buy/sell ?

    Can we create custom EAs in other language (java,python) which have access to methods of TradeScript.
    Example java code – if( MACD(“INFY”,13, 26, 9, SIMPLE) < X && myJavaMethod()==true )
    This has 2 features, the value of "X" are not hardcoded and myJavaMethod can contain java code that can have custom made logic specific to my own trading strategies/methods.

  200. Sanjib says:

    Every time i use backtest there shows a alert “(‘Your script generated an error’) script generated no trades..make sure that atleast buy or sell script are typed in.”But i already copy and paste the script.

    • algogeek says:

      when we backtest a script for certain historical data, the buy and sell signals generates only when the condition meet, so, if no pattern matches it will show error script generated no trades, try with high liquid stocks/futures like hdfcbank, nifty with more historical data and check if signals are generating.

  201. jai says:

    Does the backtesting a script not consider MIS? If i run through a script for more that 2 days, sometime it shows open position on 1st day and the closing it out another day.

  202. A Das says:

    from where we can get the manual / list of built-in functions of AFL ?

  203. Sahaj says:

    Can any one please tell me best automatic buy sell signal provider please? It is my request to you.

  204. Praveen says:

    Hi All,

    I have one query regarding automating trading

    1st thing, I work only with “Cover Order” for better leverage.

    Can I create an EA in Pi with following situation?

    Lets say currently LTP is 2500


    If price reaches 2520, my EA should execute a “Cover Order” with specified SL (I am also aware that the cover orders are market orders, hence exact 2520 may not be achieved, but that is fine, even if EA can execute a cover order automatically at/around 2520, it sufficient)

    Exit: EA should perform the closing of open “Cover Order” at a specified level

  205. vishal salunkhe says:

    hi nithin just check this modified heiken ashi daily candle with pi heiken ashi . last candle is of 2nd march 2016.
    this modified heiken ashi gives clear trend …

  206. vishal salunkhe says:

    hi nithin just check this modified heiken ashi daily candle with pi heiken ashi . last candle is of 2nd march 2016.

  207. vishal salunkhe says:

    file not attach due error

  208. vishal salunkhe says:

    Hi nithin ,
    I have modifieid heiken ashi excel formula
    can I customise in pi heiken ashi
    if yes ,then how to customise ??
    I also attach yes bank daily modified heiken ashi chart

  209. acedubai says:

    I want the EA to open orders at every bar open in the direction i specify in the EA. The number of orders also will be specified by me in the EA. But before the next order is opened at the next bar open, EA should secure the previous order with a stop loss at cost. Is this doable?
    Are there any 3rd party programmers who can programme this for me?

  210. Sidharth Kumar says:

    Is it possible for EA alerts to directly open a BO dialogue box rather than the usual MIS/CO ?

  211. Krishnaveni says:

    in my zerodha pi -> artificial intelligence -> apply EA showing blank popup box and while creating new EA it is showing error as “The request failedwith HTTP status 417: Expectation failed”..pl help me out

  212. ANKUR KUSHWAHA says:

    Currently facing issues regarding Backtesting. Please tell me where i am doing wrong.

  213. DK2769 says:

    Hi Nitin,

    Firstly I should thank you for the well planned execution of your firm. I am very much happy about the PI EA, Keep up the good work.

    I know none of the strategy works in stock market if there is a surprise news like for example RATECUT…!!!

    Can you please take out some time and advice which script will be best for day traders in the area of…


    I would be proud and happy If I do the same in KITE. Also I would like to thankyou for an idea about opentrade.

    Kundan Prasad

  214. Huma says:

    M getting error message : error in script, for scanner. But this same code runs smoothly in backtesting and EA. So how can I use this code in scanner – I want to scan a list of symbols for intraday.

  215. Preetam says:

    Sir , if I am using an indicator (studies) on kite which is not available on Pi, is the following possible

    1) audio notification that a buy or sell order is generated on the laptop.
    2) message on my mobile incase I dont have access to the laptop.

    Preetam Salwan

  216. Rohit D says:

    Hi Nithin,

    can u please tell me if is it possible to use scanner function for getting buy sell signal from a code
    on 25 scrips or more in real time?
    n please make a video about scanner function for youtube.


  217. YOGESH N says:

    SIR, backtest is a very good tool to use that can prevent getting huge lose.. thanks to you..
    Can you please give me one code that can help me for better trade.
    i usually trade nifty future and options please give me code for this one.

  218. Mehmudd says:


    Possible to backtest multiple strategies at once? I mean combination of 2 or 3 strategies.

    I tried simply pasting two strategies one after one in buy and sell scripts sections of backtest. It was throwing some error. Is there any way to carry out that?

    For ex: I tried BB strategy and RSI, it was throwing error. Please find the print screen attached.

  219. Dark Trader says:

    hI, what would be the code for CCI 50 CROSSOVER SMA 20 of CCI50


  220. Sridhar Rao says:

    Hello , This is Sridhar here from Mumbai. I want to backtest this strategy of Shorting a Near Call Option 600 points away out of money from the Nifty Spot Price on Expiry date. I want to find wether Nifty has breached this 600 points mark in the last 2 years & what is the success ratio of this strategy

  221. Anoop says:


    If i have selected RSI or some other indicator in a cg=hart how do i remove the same from chart without closing it ?

  222. Vivek says:

    Why there is a difference in the back testing alerts and alerts generated at real time? I can see too many alerts getting generated at real time but in back testing there are very few.

    Thank you.

    • It probably has got to do with the code. Can you post the code u r backtesting.

      • Vivek says:

        The script that I’m using is the Expert Advisor inbuilt script ‘ADX,MACD, stachastic and RSI in combination’:

        BUY script-
        ADX(14) > 20 and DIP(14) > 20 AND RSI(CLOSE, 14) > 40 AND REF(MACDSignal(13, 26, 9, SIMPLE), 1) < REF(MACD(13, 26, 9, SIMPLE), 1) AND MACDSignal(13, 26, 9, SIMPLE) 20 and DIN(14) > 20 AND RSI(CLOSE, 14) REF(MACD(13, 26, 9, SIMPLE), 1) AND MACDSignal(13, 26, 9, SIMPLE) > MACD(13, 26, 9, SIMPLE)

        • Vivek says:

          The script that I’m using is the Expert Advisor inbuilt script ‘ADX,MACD, stachastic and RSI in combination’:

          BUY script-
          ADX(14) > 20 and DIP(14) > 20 AND RSI(CLOSE, 14) > 40 AND REF(MACDSignal(13, 26, 9, SIMPLE), 1) < REF(MACD(13, 26, 9, SIMPLE), 1) AND MACDSignal(13, 26, 9, SIMPLE) 20 and DIN(14) > 20 AND RSI(CLOSE, 14) REF(MACD(13, 26, 9, SIMPLE), 1) AND MACDSignal(13, 26, 9, SIMPLE) > MACD(13, 26, 9, SIMPLE)

          Please ignore the previous scripts that I posted.

          • Vivek says:

            The script that I’m using is the Expert Advisor inbuilt script ‘ADX,MACD, stachastic and RSI in combination’:

            BUY script-
            ADX(14) > 20 and DIP(14) > 20 AND RSI(CLOSE, 14) > 40 AND REF(MACDSignal(13, 26, 9, SIMPLE), 1) < REF(MACD(13, 26, 9, SIMPLE), 1) AND MACDSignal(13, 26, 9, SIMPLE) < MACD(13, 26, 9, SIMPLE)

            • Vivek says:

              The script that I’m using is the Expert Advisor inbuilt script ‘ADX,MACD, stachastic and RSI in combination’:

              Sell script :
              ADX(14) > 20 and DIN(14) > 20 AND RSI(CLOSE, 14) REF(MACD(13, 26, 9, SIMPLE), 1) AND MACDSignal(13, 26, 9, SIMPLE) > MACD(13, 26, 9, SIMPLE)

              I had to post it multiple times as the entire script was not getting posted.

  223. Ankur Dahama says:

    I have to scan stocks that are crossing its “Previous Day High” . Previous provide code for the scanner.
    Thank You

  224. Rohit says:


    This is a great software. However, I can see that the trades are to be entered manually by clicking buttons. Is there any option for automatic buy and sell orders?

  225. Rahul says:


    I have one query that suppose If I have enabled one strategy on pi as well as I am not in front of my laptop and laptop is shut down…..Can i get those alerts on my registered mobile number so once i get alert i could place orders through mobile app or through kite….

  226. rohit D says:

    Hi Nithin,

    If i have 35 scrips in my watch list n if I have a strategy coded then is it possible that I get buy sell signal on all 35 scrips in real time n rather not just on a scrip whose chart is on my screen.
    please let me know about this.

    thank you

  227. rahul says:

    kya bracket order modify ho sakte hai?

  228. rahul says:

    and sir ye scanner kya chij hai????

  229. rahul says:

    sir jab b mai bracket order place karta hu to order reject kyo ho jata hai rms: client not enable on product
    aise aata hai

  230. rahul says:

    thanks for reply sir

  231. rahul says:

    i am new in zerodha trading
    plz bataiye ki ye backtest kya hai and reply in hindi

    • Venu Madhav says:

      बॅक टेस्टिंग से आप यह पता लगा पाओगे यदि आपका ट्रेडिंग स्ट्रॅटजी कामयाब रहा है की नही.

      अगर आपके पास कोई ट्रेडिंग स्ट्रॅटजी है तो उसको आप पिछले कई दिनों के चार्ट पे टेस्ट कर सकते है. आपको पहले के चार्ट पे बाइ सेल सिग्नल जेनरेट होगा. आप यह भी पता लगा पाओगे की आपकी स्ट्रॅटजी से कितने ट्रेड्स निकले,उसमे कितने लाभदायक थे और कितने नुक़सानदायक थे. इससे आप अंदाज़ा लगा पाओगे यदि आपको फ्यूचर में वो स्ट्रॅटजी का उपयोग करना है की नही

  232. Tejas Desai says:

    HI Nitin,

    PI is good platform for zerodha trader , But I am not able to do simple scanning in PI . I want to scan those stock which are trading below there opening price , Please help me on this in PI

    Tejas Desai

    • Venu Madhav says:

      On Pi go to Alerts –> Scanner –>Click on New Scanner –> Give it a name –> Condition = LAST Select the periodicity, bar interval and days –> Click on Add Symbols to add the symbols on which you want to scan the given criteria. You can see the Added symbols in the ‘Added Symbols’ dropdown –> Click on Ok –> Click on Load. This will run the scanner and give you the list of scrips which meets your criteria.

  233. Anil says:


    I need some sort of setup as below

    A screener or alert kind of system which can scan over all the NSE stocks during live trading and when ever my strategy is fulfilled ( something like say EMA Crossover happened ), I need to get all the stocks for which the strategy is fulfilled.

    For example: For EMA Crossover of (20,60). I need to know the stocks in NSE for which EMA crossover happened during live trading in 1-minute time frame.

    It would be great if my above requirement can be fulfilled with Pi. Please let me know the possible solution if any.

    Looking forward to hear from you.


    • Anil says:

      I just want the pop-up message or alert with the stock name?

      Also I would like to know how reliable is it to use multiple scanners during live trading in PI?

      When I write the EMA Crossover logic in scanner, will it alert or pop-up message when the crossover happens during live trading?

  234. RAJ says:

    Is it possible for me to apply an EA to a chart and get it stored in the system so that EA is active all the time and will show a signal moment i open pie ;if yes where can i see a list of all my active EAs or should i buy amibroker or other software . I am not very good at coding though.

  235. Ramesh says:

    The EA seems to be useful for only the intraday traders. I would like to use the scanner on all stocks (Closing price) so that I can identify buy and sell opportunities for short term trading. Is it already available? Am I missing something?

  236. Badri says:

    Can a single EA script be used to run on all F&O scripts for parallel scans and generate alerts for multiple matches in Pi?

  237. Ishwar M. says:


    One query regarding the Risk to Reward ratio shown in the Back Test report. Could you please tell me how this is calculated? As I can’t seem to arrive at that number. For example, I have the below data generated in the back test report:

    Total number of trades: 27
    Number of profitable trades: 12
    Number of losing trade: 15
    Total profit: 73.6
    Total loss: -39.2
    Percent profit: 46.739%
    Largest profit: 15.85
    Largest loss: -5.9
    Risk to reward ratio: 0.234

    So, how to arrive at this Risk to reward ratio of 0.234 from the above data? Or is any more data required for calculating this?


    • You will need more data. You will need profit/loss on every single trade.

      • Ishwar M. says:

        Ah ok.

        Nithin, one feature request related to EAs in general. If I leave the EAs running on my computer, can the generated alerts be sent as notifications to Kite? This way we can execute the buy / sell at the right time with Kite on mobile even when we are not around the computer. Or do you already have some plans of being able to Apply EAs directly on the mobile through the android app that is coming up or in Kite itself?

      • Maruthamani P says:

        Hi Mr.Nithin,

        I copy pasted EMA3-15 code back test result of JPAss-EQ

        11/27/2017 9:15:59 AM to 1/25/2018 3:15:59 PM
        Total number of trades: 31
        Average number of trades per month: 17
        Number of profitable trades: 8
        Number of losing trades: 23
        Total profit: 12.1000
        Total loss: -4.5500
        Percent profit: 62.397%
        Largest profit: 6.7000
        Largest loss: -0.8000
        Maximum Drawdown: 0.0000
        Maximum Drawdown (Monte Carlo): 0.0000
        Compound Monthly ROR: 3.8239
        Standard deviation: 6.97585120
        Annualized standard deviation: 9.86534338
        Downside deviation (MAR = 10%): 0.00000000
        Value Added Monthly Index (VAMI): 1.00004298
        Sharpe ratio (RFR = 5%): 1.07513761
        Annualized Sharpe ratio (RFR = 5%): 1.52047419
        Sortino ratio (MAR = 5%): 0.00000000
        Annualized Sortino ratio (MAR = 5%): 0.00000000
        Sterling ratio (MAR = 5%): 0.00000000
        Calmar ratio: 0.00000000

        “Risk to reward ratio: -0.188

        11/29/2017 11:30:59 AM,LONG,18.7500
        11/29/2017 11:45:00 AM,EXIT LONG,18.6500 Loss -0.1
        11/30/2017 2:15:00 PM,LONG,18.3000
        11/30/2017 3:00:00 PM,EXIT LONG,18.0500 Loss -0.25
        12/1/2017 9:15:59 AM,LONG,18.3500
        12/1/2017 11:15:00 AM,EXIT LONG,18.2500 Loss -0.1
        12/5/2017 2:00:00 PM,LONG,17.1000
        12/6/2017 9:15:59 AM,EXIT LONG,16.9500 Loss -0.15
        12/7/2017 9:30:00 AM,LONG,16.7500
        12/7/2017 12:30:00 PM,EXIT LONG,16.7500 Profit = 0
        12/7/2017 12:45:00 PM,LONG,16.8500
        12/7/2017 12:59:59 PM,EXIT LONG,16.7500 Loss = -0.1
        12/7/2017 1:15:00 PM,LONG,16.8000
        12/7/2017 1:45:59 PM,EXIT LONG,16.7500 Loss =-0.05
        12/7/2017 2:45:00 PM,LONG,16.9000
        12/11/2017 9:30:00 AM,EXIT LONG,17.7500 Profit =0.85
        12/11/2017 2:15:00 PM,LONG,17.7500
        12/11/2017 3:00:00 PM,EXIT LONG,17.6000 Loss =-0.15
        12/12/2017 10:45:59 AM,LONG,17.6500
        12/12/2017 11:30:59 AM,EXIT LONG,17.6000 Loss =-0.05
        12/12/2017 11:45:00 AM,LONG,17.6500
        12/13/2017 9:59:59 AM,EXIT LONG,17.8000 Profit =0.15
        12/13/2017 10:30:00 AM,LONG,18.0000
        12/13/2017 1:45:59 PM,EXIT LONG,18.1000 Profit =0.1
        12/13/2017 3:15:59 PM,LONG,18.2500
        12/14/2017 9:30:00 AM,EXIT LONG,17.9500 Loss =-0.3
        12/14/2017 2:00:00 PM,LONG,17.9000
        12/14/2017 2:45:00 PM,EXIT LONG,17.7500 Loss= -0.15
        12/15/2017 9:30:00 AM,LONG,17.9000
        12/15/2017 9:45:00 AM,EXIT LONG,17.7500 Loss= -0.15
        12/19/2017 3:00:00 PM,LONG,17.1000
        12/20/2017 9:15:59 AM,EXIT LONG,16.8500 Loss = -0.25
        12/20/2017 11:30:59 AM,LONG,17.0000
        12/21/2017 3:15:59 PM,EXIT LONG,18.4500 Profit =1.45
        12/22/2017 9:15:59 AM,LONG,18.6500
        12/22/2017 11:30:59 AM,EXIT LONG,18.5000 Loss =-0.15
        12/26/2017 9:15:59 AM,LONG,18.6500
        1/1/2018 9:15:59 AM,EXIT LONG,25.3500 Profit =6.7
        1/1/2018 12:00:00 PM,LONG,26.2000
        1/1/2018 2:45:00 PM,EXIT LONG,25.4000 Loss =-0.8
        1/2/2018 1:30:00 PM,LONG,24.5000
        1/2/2018 1:45:59 PM,EXIT LONG,24.0500 Loss =-0.45
        1/3/2018 9:15:59 AM,LONG,24.8000
        1/3/2018 12:59:59 PM,EXIT LONG,24.6500 Loss =-0.15
        1/4/2018 9:15:59 AM,LONG,24.7000
        1/4/2018 12:45:00 PM,EXIT LONG,24.6500 Loss =-0.05
        1/5/2018 9:15:59 AM,LONG,24.7000
        1/5/2018 11:15:00 AM,EXIT LONG,24.3500 Loss =-0.35
        1/5/2018 1:30:00 PM,LONG,25.5000
        1/8/2018 2:45:00 PM,EXIT LONG,25.4000 Loss =-0.1
        1/10/2018 9:45:00 AM,LONG,23.9500
        1/10/2018 2:45:00 PM,EXIT LONG,24.1000 Profit =0.15
        1/11/2018 12:30:00 PM,LONG,23.9500
        1/11/2018 12:45:00 PM,EXIT LONG,23.8500 Loss =-0.1
        1/12/2018 9:59:59 AM,LONG,23.8500
        1/12/2018 10:30:00 AM,EXIT LONG,23.6500 Loss =-0.2
        1/15/2018 9:59:59 AM,LONG,23.3500
        1/15/2018 1:30:00 PM,EXIT LONG,23.2000 Loss =-0.15
        1/17/2018 11:30:59 AM,LONG,21.6500
        1/18/2018 12:30:00 PM,EXIT LONG,22.8500 Profit =1.2
        1/19/2018 2:00:00 PM,LONG,21.1000
        1/22/2018 12:45:00 PM,EXIT LONG,22.5500 Profit =1.45
        1/23/2018 10:15:00 AM,LONG,22.2500
        1/23/2018 12:45:00 PM,EXIT LONG,22.1000 Loss =-0.15
        1/25/2018 9:15:59 AM,LONG,21.8500
        1/25/2018 1:15:00 PM,EXIT LONG,21.7500 Loss =-0.1
        1/25/2018 2:30:59 PM,LONG,22.0000 Profit =0

        HENCE, TOTAL LOSS = Rs. -4.55

        TOTAL PROFIT = Rs. 12.05

        Net Profit= Rs.7.5

        Profit Percentage = 62.397%


        In above case, Risk to Reward Ratio = 7.5 / (-4.55) = 1.648 OR 62.397% / (-4.55) = 0.137; Whereas back test gives -0.188

        I am very confused in UNDERSTANDING RISK TO REWARD RATIO GIVEN IN PI BACK TEST REPORT, PL guide me how it is being calculated step by step in detail.. I discussed with few traders, nobody has answer.. And How Negative values arrives.. My understanding if I keep 1 risk to 3 profit, i.e, 1:3 = 1/3= 0.333 OR 3 Profit to 1 Risk, i.e, 3:1 = 3/1 = 3 vice-versa.
        Which is correct? how zerodha pi calculates?

        Pl answer. Thanks

      • Amey says:

        Hi Nithin!

        Why is nobody answering the query about how actually risk-reward is calculated on Zerodha Pi Backtest? There are absolutely no resources anywhere and many people are asking this question.

        Is it RISK/REWARD or REWARD/RISK and if so, what constitutes RISK and REWARD?

  238. Ishwar M. says:


    The TREND function does not work in combination with the EMA. For example:
    TREND(EMA(CLOSE, 50), 2) = UP returns no trades.

    I have the latest patch of Pi. This issue happens only for TREND with EMA. TREND with MACD or RSI works fine.

    Could you please look into this?


  239. Uma says:

    Why don’t expert advisors generate buy sell signals on the chart itself? Also, is there a way to apply expert advisor to all open charts at the least?

  240. gaurav says:

    was away from trading for sometime
    installed the updated pi today, it works really

    happy to see many improvements ,runs well, is fast and ezee to use as always

    ((i have traded with the costliest brokerage where they promise you the moon and charge you the solar system.they give you a dedicated adviser -whose job is to make sure you keep bringing in money . i was tired of buggy platform, clueless customer care and very very high charges .its like dealing with a government office :even with such high charges they refuse to provide you a proper charting -you can easily guess the name ))

    no one matches zerodha in terms of user friendliness , and the way u people take care of every query every request is great keep up the good work

  241. Arshad says:

    Hi Nithin,

    Current version of PI has set backtest limit to last 120 days only. Will this be increased in next version? 120 days is very restrictive limit for backtest , it should be minimum of 1-2 years.


    • Arshad the limit of 120 days is on intraday candles only, that is like 50,000 candles of 1 min data. The daily candles can be backtested upto 5 years. But yes, we will increase the intraday data as well.

      • Arshad says:

        Hi Nithin,

        Agreed for intraday 1, 2, 5 mins candles of 1or 2 yr there will be easily 50,000 candles or more which will put load on server. But the number of 1hr, 2hr , 4 hr intraday candles will be much lesser for 1yr or 2yrs. So I think you could still provide 1hour or 2 hours charts for 1 to 2 years.

        The reason I say is because there are a lot of positional strategies which use 1hr, 2 hr charts but carry over the trade overnight. Backtesting these for 1 year will give more confidence as opposed to just 120 days.


  242. Manu says:

    I don’t know why some of the code is removed when I post the message.
    In words the strategy for MACDHIST is
    For Buy:
    (MACDHIST should be greater than zero and previous days MACDHIST should be less than zero ) OR ( previous days MACDHIST should be greater than zero and 2 days back MACDHIST should be less than zero )
    ( MACDHIST should be less than zero and previous days MACDHIST should be more than zero ) OR ( previous days MACDHIST should be less than zero and 2 days back MACDHIST should be more than zero )

  243. Manu says:

    In the above post the code is not complete, the correct code is
    “For Buy
    For SELL:

  244. Manu says:

    I am trying to back test strategy , it gives the backtest result but the chart is blank and the backtesting screen also hangs. When I try to close the chart window it says “chart is in use”. Please correct my code if it has some mistakes. I am testing on 1 minute nifty futures for 1 day data.
    For Buy
    For SELL:
    The problem seems to be with REF(MACDHIST,2) as when I remove this term it works fine but I require it for my signal generation.

  245. Deepak says:

    Is there an option to backtest with the ability to provide a profit target in percentage as exit trade?

  246. Robin says:

    Hi Nithin,
    I have sent a mail to you…….. Please, please, please go thru the mail. I am sure, other traders would have faced this problem in EA generated signals on Pi after the recent changes made.

    Thank you.

  247. Sandip says:

    Hi Nitin,

    I have been asked to upgrade my Internet to Broadband when I last reported issues with signal not generating as per condition when I take it live. Now I have upgraded to 2 Mbps Wired broadband which consistently gives me above 1.5 Mbps even after that the signals generated in live environment and in Back testing are different.

    Please help

  248. peter says:

    A request , Can you add buttons on EA page-Select all/unselect all.

  249. RATHEESH says:

    do you providing nest default option strategies for fully automated algotrading…? if using please send a mail to me or call me on 9744618132

  250. peter says:

    EA ‘strategy with previous and current candle’ – It prompts for a buy and generated alerts shows a sell.Please verify.

  251. Robin says:

    Hi Nithin,
    Sorry, I am bugging u too much.
    I have a request. This request can be fulfilled by making a very small modification on Pi.
    On Pi, when an order is executed, there is an announcement which can be heard very well even from the next room….which is excellent.
    BUT, when an Expert Adviser is triggered, there is only a SINGLE beep and a pop up. If I am in front of the monitor at that time and not engaged in any thing else, then it serves the purpose. But, if I am even little away from the monitor or in the next room or even in front of the computer watching some business channel, it is easy to miss the alert.
    Hence, my request is to make the beep … 4 or 5 times continuously. (an option can be given to the client if he wants single beep or multiple beep)
    Hope this suggestion is useful and can be implemented.

    • peter says:

      I don’t know whether it is recommended. Locate C:\zerodha\pi\res. there is a wav file named “ExpertAdvisorSellAlert”. If you know how to edit wave file try it and make it multiple alert. Try to save the edited file in same name and preserve original file. It works.

  252. Robin says:

    Hi Nithin,
    For backtesting intraday charts (5,10,15,20,30 mins), the maximum duration allowed is only 120 days (4 months)….. which is toooo less to get an idea of the profitability of any strategy.
    Please increase it to at least 1 year (365 days)….preferred will be for 2 or 3 years.
    Pi is so power packed…… but without data it is weak.
    It is like having a Ferrari…but no fuel to drive it ! 🙂
    Pls, take it up on a priority basis.

  253. Robin says:

    Hi Nithin,
    I am in love with Zerodha. I have traded with 2 other brokers earlier, but Zerodha is miles ahead of them…. in technology and also in service….I love the positive and helping attitude of ur team.
    I have a doubt regarding the accuracy of back testing results. I back tested a very simple EMA crossover strategy on NIFTY Futures for 60 days and CNX NIFTY for 120 days period. I tried with different candle stick period (10, 15, 20 min). I was surprised to see a profit of (after charges) Rs.12,000 for one lot . That was for 60 days. For 120 days on CNX NIFTY, I got a profit of (after charges) Rs.23,000. Ofcourse, there were differences for different candle stick periods…. but on an average, this was the result. Even if we take a 10% error/deviation, the profits are too good to be true.

    • Robin, last 4 months had two or three 500 point moves in one direction when EMA’s work very well. So possible, but do check if your code is right.

      • Robin says:

        Thanks for ur time and ur reply.
        1) For backtesting intraday charts (5,10,15,20,30 mins), the maximum duration allowed is only 120 days (4 months)….. which is toooo less to get an idea of the profitability of any strategy. Please increase it to at least 1 year (365 days)….preferred will be for 2 years.
        2) Also, please u[date data for CNX NIFTY for similar duration.

  254. peter says:

    EA. When applying two EA script on a chart. I am getting signals as EA triggered. But quite confusing which EA strategy is triggered. for Eg.
    1. LRI and EMA Sometimes I get erroneous message when LRI triggered it says as EMA is triggered( in the source window of alerts).Any way I can adjust my mind , but I think You have to look into it.
    2. I reported a problem (send email to siva also) when a strategy is triggered we have to wait for the candle to close for generating another alert( buy or cell). If the alert sounded as a buy and the same candle goes below the price there is no alert. and a buy alert remains there , but virtually it is a sell. cannot really trust on EA.

    • Peter, you can name your EA by the strategy. So in the generated alerts window, it will show you which EA generated the alert.
      In technical analysis, trades are usually taken at the close of candle. But we are working on it to give the user an option to choose how he wants an alert, at the close or the way you want. Give it a few more days.

  255. vinodkumar says:

    sir when i applied expert advisers buy and sell signals are generated and shown in generated alert window however it is not appeared in live chart how can i show EA signals in chart

  256. Dhiraj Sharma says:

    Can I backtest pivot breakouts? How to generate signals for pivot breakouts?

  257. Sandip says:

    If I write Sell and Exit Sell script. Its says No result and Please write at least Buy or Sell Script
    But if I write some Buy script for same Profile, Keeping the same Sell and Exit sell script it generates Short Sell and Exit Sell signals

  258. vishal@09 says:

    Hi Zerodha team, I am facing to understand why backtesting in my pi software is behaving erratic. I used simple input such as below:

    after applying this on 30 min infy chart, backtest gave entry at te start of each 30 min candle bar, how to back test this strategy. I have snap shot but not able to attach.

    Pls help, bye vishal

    • vishal@09 says:

      there was typo in above query, the used code in backtesting was:


    • Vishal, can you click on check for latest updates on Pi under the help menu. Update the version of Pi and try again. Few cases where the last update hasn’t happened correctly some issues with backtesting.

  259. Dan says:

    Hello, i am going to open an account very soon.I just came across a site which offers Zerodha club membership in which we get different technical softwares and training like Amibroker and Metatrade etc. Any difference if i open account through that site?

  260. Robin says:

    Hi Nithin,
    The comment I just posted is awaiting moderation. It must be because of the links I have given in the comment (links to tradingqna). Please have a look at the comment.
    Thanks in advance for your time.

  261. Robin says:

    Hi Nithin,
    I was back testing on NIFTY FUTURES (current month) and saw that the data is from 4 May 2015….I realised that the data will be available from the time the contract have started.
    Hence I back tested on CNX NIFTY….by selecting NSE and then INDICES….but saw that even this data is available from 2 Feb 2015. (Both EOD & intraday).
    Is there any other way I can back test data for NIFTY for a longer duration?

  262. Robin says:

    Hi Nithin,
    My strategy to trade in stocks in cash market is to buy on EMA (9,21) CROSSOVER and book a small profit or to exit on EMA (21,9) CROSSOVER.
    I have back tested it on pi on 15 min charts. I would like to Apply Expert Advisors everyday on all the NIFTY 50 stocks at the same time so as to utilise the opportunity as and when arises.
    1) Is this possible on pi?
    2) To Apply Expert Advisors, the chart of the security is to be opened. ……Can the chart be closed after applying EA ?….if the charts can be closed after applying EA, than EA can be applied to any number of securities…..Right?
    3) How many charts can be opened at a time ?

    • 1. You will have to open individual stock charts to apply the EA. Currently max of 10 charts can be opened.
      2. Yes currently the charts need to be open for applying EA. But we are looking at ways to take this limitation out.
      3. 10

  263. MEHUL PARMAR says:


  264. parvati says:


    When I code my strategy and backtest it on PI, it sometimes says that the script generates error, but when I take a closer look, there is no error at all. Also the tool does not say in which line the tool sees an error if any. This is very frustrating when debugging. Please let me know if there are better ways to tackle such situations.


  265. Sandip says:

    Is it possible to have options in EA like in Back testing….. Buy….Exit Buy….Sell….Exit Sell?
    As currently we cannot use it for OPTIONS if we want to just Buy Options and then Sell.
    As it is just Buy and Sell, it generates Sell(Short) Signals which I doesn’t want to go for

  266. lakshman says:

    Sir kindly make some arrangements so that we can known which stocks, commodity going above/below 50/100/200/300 emas like on by default or acting as support/resistance on eod data so that we filter stocks n chose which is highly bullish/bearish stocks and some pattrens like doji hammers inverted hammers n on on on hope even you will do this soon

  267. P RAJENDRA KUMAR says:

    Hello sir,

    After studying all the indicators very very simple stratergy , what i feel, placing buy and sell signal when crossover between price line and 20 days EMA under algo trading

    Kindly advice

  268. cbhumiya says:

    Hi Nitin,

    In the scanner settings the periodicity cannot be set to ‘day’. So it is not possible to compare a current value to the previous day close. Can this ‘day’ periodicity setting allowed by pi.


    • Will forward to the tech team.

      • champak says:

        thanks 🙂

      • champak says:

        Hi Nitin,

        I think that there has been no action from your technical team on my previous query in which I had pointed out that the scanner settings cannot be set to a day. I also find that in scanner settings, if “periodicity” is kept in “minutes” and the “bar interval” kept more than “10” the scanner gives a message about the “maximum number of bars possible” and does not allow the scanner to be set. I believe that if I want a few number of candles then the scanner should allow me to use the settings mentioned above.

      • champak says:

        I want to set the periodicity as ‘minutes’ and bar interval as ’30’ in the scanner and pi is not allowing this to be set.

  269. hello sir ]

    please tell me how to write long exit code

    let say when crude oil crosses its EMA either I sell/buy and as soon as it covers 2 points i want to exit

    Example crude oil CMP 3700 EMA 10 crosses above i initiated buy and when it reaches 3702 i want to exit my position wants to scalp it

  270. cbhumiya says:

    Hi Nitin,

    In the scanner settings the periodicity cannot be set to ‘day’. So it is not possible to compare a current value to the previous day close. Can this ‘day’ periodicity setting allowed by pi.


  271. Haribabu says:

    in PI

    please provide a feature of Pivot points as given in the below link.


  272. Haribabu says:

    I am using PI. it is good.

    Kindly add available Margin to be displayed on top always so that it will be easier.

  273. Sudarshan says:


  274. Sudarshan says:

    L6 = ((C-(H-L)*1.09))
    i want overllay this pivot on price chart , like we can overlay avg in amibroker ?

  275. Arun Kumar says:

    I am using PI, and its just excellent

  276. Arun Kamath says:

    Can we have stats of the EAs. i.e. best time frames, stocks, % winners etc

  277. vivek says:

    hi nitin,

    i’h started trading in pi, so far so good. need some help with EA’s to start with and then algo trading, i do have a strategy, need some help putting and back testing it in EA’s. Thanks.

  278. SathishJ says:

    Hi Nithin,
    From Day 1 I entered Zerodha, I am not able to trade using any of your Desktop, Web, Z5 platforms. Only i am fighting with your Mobile Trader application an d it works fine now.But, i would love to use your Web, Z5, Pi platforms to trade.Please help me. No good answer from your support team.

  279. Ritesh says:

    Can Zerodha request for historical TICK data for NSE from day 1 of online trading (historical intraday bhavcopy) and integrate it within their system, including Pi? It will be great! Much better than all your customers chasing the much needed historical data out on the internet.

    • We are slowly increasing our database. Tick data is not possible, it will be 1 min OHLC data. Daily tick data will be between 20 to 30 GB just for NSE, and it is not practical to store historical data base of ticks and stream it via internet

  280. Krishna says:

    Somehow attachment is not going through! Please let me know your email id, I can send it to yous separately.

    • Someone form our team will get back to you.

      • Krishna says:

        Thanks Nithin.

        I indeed got a call already and the person who called me understood the issue. I had few more issues of which I have sent the screenshots.

        Excellent customer service I should say.

        • Sandeep A says:


          I also have questions on the same lines.
          When i create my custom EA , i dont see option to exit Buy or exit Sell.
          Could you please help on this?

  281. Krishna says:

    Hello Nithin,

    I have recently enrolled with Zerodha. Trying to learn PI and the scripts.

    For the default EAs, I could find scripts for Buy & Sell. How do I determine scripts for Exit Long & Exit Short?


  282. sunil says:

    For fully automated trading in Equity we need dealers terminal.

    is it same rules for commodity trading? some peoples said we can trade fully automatically in commodity.

  283. Ramkumar says:

    Thanks for the reply. Is it possible to plan for this feature in future? I think this is very essential feature for back testing. In this forum I need not stress enough the importance of stoploss.
    I have seen other software doing this. for example Ameritrade trading software. There is a simple check box for stop loss. if u enable it u can put stop either as % or absolute terms.


  284. Vishal says:

    Not sure if this a right place for this feature.
    It happens that that I’m +10000 in morning and -10000 by afternoon. Is it possible to square off all positions when the net profit moves down to +3000 from +10000.

  285. Ramkumar says:

    The question raised by Sravan on (31/5) has not been answered. I also badly need to know how do it. I searched ref. doc and I couldn’t find way to do it. To refresh memory, the problem is “how to access entry price in exit long/short section?”. This will help us in doing things like putting a stop loss.

  286. mehtachandru says:

    Dear Nitin ,

    a) I liked your buy and sell in the same pop up it is easy to quickly to trade on zerodha .

    i have a two questions

    a) does your software support historical indicators of over 1 to 2 years . What i mean is resistance points or lines drawn by us / saved by us in the system which act as horizontal line indicator and are very useful to us to show that the stock is at a particular resistance zone that may move up or down.When i try doing this it does not save for the next day .

    b) is it possible to add the nse nifty as an overlay over a existing stock . This could be helpful instead of toggling around.

    I look forward to your response.

  287. Ashok Jain says:

    Dear Nithin,

    I am not expert in technicals viewing of charts , but i want your algorithmic based trading to help me in getting buy and sell signal time to time . This it seem your EA does. Is this correct what i have understood from your website.

  288. prabhakar says:

    i am using pi it is good but only one market watch is there can it be possible to make multiple watchlist

  289. Debajit says:

    I just start using PI from last month and found very helpful for new commerce who start writing script. I have two questions here:
    1) Is there any way in EA code I can add buy/sale exit also like in back test module.
    2) Once any buy or sale signal generate can draw stop loss & Target line automatic in chart based on
    trade price.

    • 1. Debajit, you can run two separate Expert advisors. So one to Buy and Buy exit (in sell, enter your buy exit code), and similarly a separate EA to Sell and Sell exit.
      2. No, not possible.

  290. prabhu says:

    Hi Nithin ji,

    I have an AFL indicator (purchased from some vendors) that shows arrows for buy and sell in amibroker chart, but i am not sure whether it will be able to connect with PI.

    can i connect the amiborker indicator arrow to place a order in PI, issue is that i don’t have the code of AFL.


    • Yes Prabhu, you can get the AFL to fire orders directly into Pi using Pi bridge. Check this. If you are subscribing data from neotrade analytics for amibroker, they will help you out in coding the AFL also. They have built a utility, if you drag and drop on a chart on Ami, it fires orders into Pi. Speak to them.

  291. fazlur rehman says:

    I am surprised buy the delay you are taking in adding super trend and pivot points. Since long you are promising to add in next release of pi but that next release didn’t come yet which is very irritating ………

    • Fazlur, we have received over a 100 new indicator requests. We will work on that, but first we are working on ensuring that everything else around the platform is optimized.

  292. Abhijeet says:

    As currently there are 30 EAs on website and as you said that Zwerodha is planning to launch about 100 EA’s in next few days.

    One suggestion here, Is it possible to suggest most popular or most used EA if user selects the particular stock for EA?

    For eg.
    Like if I select stock “tata steel” and for the same stock 100 people are using “Bearish Meeting Line (Short trades)” , 80 people are using “Three White Soldiers and Black Crows” and 50 people are using “Commodity Channel Index (CCI)” from past 7 days.

    So while creating new EA on users side is it possible to list those EA as per their popularity / use for that particular stock (in above case “tata steel” )?

    • hmmm.. we can’t track which user is using what EA. EA’s run locally on the client machine.

      • Abhijeet says:

        you can add facility to share individual EA’s to public if user is interested to help others! Also it will be helpful for all zerodha Pi users to know how other people are making profits, its win win situation for trader – Zerodha – other traders!

        Also with this facility more and more Zerodha users start getting interest in trading regularly

  293. Sravan says:

    1. How to reference the long price in back testing exit long script. If I want to test strategy where I exit long if some condition is satisfied or there is loss of 40 points from buy price, how do i code it in exit long script.i.e how to put stoploss in the backtesting script.
    2. While backtesting index futures, I can only select current futures and expired charts are not available. Backtesting against near month futures makes sense since volumes will be more in near month i,e if i want to test june future, it should use may future to test last month since volumes will be there and april future 2 months before instead of testing june future in may and april since trading activity happens there.
    To conclude availability of index data against near month futures across the months would be very helpful.

    • 1. In the backtest, you have buy, buy exit, sell, sell exit options. If you want to backtest with different conditions for profit booking of buy and sell entry, then you will need to run backtest twice, once for buy strategy and use Sell and sell exit for Profit and SL. Similarly backtest on your sell strategy separately.
      2. Yes best backtest on the underlying rather than the futures since there is no continuous futures data on Pi yet. If your strategy includes volume data, then yeah doing this on index spot will not be possible. We are working on giving continuous future charts in Pi, but this will take some time.

      • sravan says:

        Hi nitin,
        Thanks for the quick reply.
        I want to know how to code exit on loss of say x points in the script.
        Search is not working in the code referrnce document.

  294. sandeep says:

    Dear Sir,
    I am new to zerodha.I want to know that Can we create special codes for a particular stock. i.g. I have a strategy for any share that if that stocks goes up I should sell.

    With regards,

  295. algogeek says:


    you can not use 40 in parameters in stochastic, use 9,3,9 or some lesser values than 40

  296. algogeek says:

    The values entered for stochastic is wrong, for stochastic
    Recommended Parameters
    % K Periods: 9
    % K Slowing Periods: 3
    % D Periods: 9
    MA Type: SIMPLE

    SOPK(9, 3, 9, SIMPLE) AND RSI(CLOSE, 14)

    • Sudheer says:

      Thank you for your response. I understand that 9,3,9,SIMPLE are the recommended parameters for Stochastic.
      However, I should be able to provide the custom setting for my strategy to work. The custom settings 40,1,1,SIMPLE have been working very well for me (which I use in my charts). I wanted to code the same for the system to generate the alerts. Please let me know if it is possible to use these settings in the code?

    • RC1404 says:

      Hello Team,
      I really need your help or if you can get me the script for the following on the hourly chart of 60 candle.,
      Buy: when Stochastic oscillator cross over at the bottom
      Sell: when stochastic oscillator cross over at the top
      and i should be able to run this script on all FNO-stock to find the list of stocks which are meeting the criteria.
      I would remain thankful to you for the same.
      Chandan thakur

  297. Sudheer says:

    Need your kind help with the TradeScript code –

    Am trying to backtest the code while combining Stochastic (40,1,1,SIMPLE) and RSI (CLOSE,14) indicators. Pi very well displays the indicator (as shown the attached image) on the chart, but the backtest results throws an error message stating ‘%k slowing periods’ argument of SOPD is invalid. When the Stochastic(40,1,1,SIMPLE) indicator works on a chart, why doesn’t the same parameters work with the TradeScript?

    Please help!

  298. santana pereira says:

    My trading ID DS5660
    I have gone to your Pi video link and have queries as under:
    1) Is the coding language same for Z-platform and Pi platform ?
    2) Is coding in Pi platform is limited for average and not for professional.?
    3) Can you send me the video link or examples of strategies coding already done for AFL amibroker platform.
    4) What are the aproximate charges for coding, bridge connect and data per month.

    Thanking you for early reply.

    Yours trully,

    • 1. It is only on Pi.
      2. Tradescript the programming language on Pi is for traders who are not necessarily proficient at coding. SO yeah if you compare it to AFL, what it can do is limited.
      3. Check this post on using Pi bridge for Amibroker http://zerodha.com/z-connect/tradezerodha/pi-bridge/pi-bridge-for-amibroker
      4. We don’t charge anything for coding, and you have to buy data for amibroker from a data vendor (Data on Pi can’t be used for amibroker). Pi bridge for now is free, but it will cost around Rs 300 per month soon.

  299. Harshal says:

    Hiii Nithin,

    as i tried to trade with help of EA in Pi. But it is very difficult to trade as a lot of buy/sell signals are generated after a minute. so it is hard to trade. if one strategy gives buy signal, next minute it gives sell signal. it is very confusing.
    plz help me out

  300. dd0847 says:

    hi nitin,
    1st time saw a glimpse of pi; though seemed flashy and easy to use, I was unable to access several very basic components;
    1. is DEMA(double EMA), TEMA(triple EMA) provided in the backend? If no, is it possible for me to edit the library and compile it with my own extended set of formulas?
    2. When I ‘Apply exper advisor’ with ‘MACD histogram’ as the choice, no buy/sell indicators of any kind like arrow is present;(I am trying to see how things work at the end of day after market hours)
    please help

    does login to zconnet, tradingQ&A all different?so many logins and so many passwords…. sigh.. :((((

    • 1. You can add upto 10 indicators, so you can add multiple EMA’s individually. You can’t currently create your own indicators.
      2. When you apply expert advisors whenever an alert is generated it shows up on generated alerts window, you will also hear a beep.

  301. biju says:

    waiting for fully automated trading

  302. Bharath says:

    I am using MT4 based strategy can i link MT4 to PI or NEST Trader (ZT)? If yes please let me know more information.

  303. Vivek says:

    Hi Nitin,

    I am long term investor, though i would like try this automation thing.
    Why this restriction of active trader to get PI?


    • Vivek, huge amount of resources required to run Pi.So every instance of person using Pi, we will be spending more on the resources. Even if you are not trading, and have atleast 10k in your account, it is considered active.

      • Vivek says:

        So i see this as if i am going to make profit i will become active automatically, else will not use and will free up resources. I do not want my money to sit ideal like minimum balance of bank a/c :), though i have reasonable holding of equity in demat.

        Should not holding be criteria too for PI?

  304. How to download Pi? Where to click for download?

  305. Jay says:


    I humbly request you that first you give a proper training your team (Those who are giving a demo on Pi). I am new customer of zerodha and I installed Pi. I thought clear some of my questions by arranging a demo. Unfortunately the person who gave a demo does not have a sufficient knowledge on Pi. I was really disappointed. Please setup a separate team only for demo. or else you create a video and publish in youtube. I know most my question were answered in z-connect blog page comments section. But I should go all the comments to find an answer. It is very time consuming. so please consolidate all the questions which is posted here and create a youtube video with answers.


    • Yes Jay, we are putting up videos and we will train the team on this as well.

      • Pyush says:

        Yes Nitin please, Because even i faced the same problem but slowly learning from Z-connect, most of the time even support team cant help on those……..

        I know the effort you are putting and making it investor friendly so the the profit can be earned for both but when these new things comes in market for first time, you just cant leave the investors and traders just like that, this is a great opportunity for you as today in india more new and new young investors and traders are coming make the use of it.

        Hope you will work on it and hope you are really doing good.

        Thank you
        Take care
        Keep smiling

  306. Gopi says:

    Hai Nithin Sir,

    1) can we code in trade script about know the status of the order placed, and on order completion only place another order(placing orders with condition).?

    2) is their any database connection or file support in pi, to record order number, order status, and values if any for that order.?

    3) how amibroker know the order is completed or in pending.?

    4) is the trail version of amibroker software sufficient to do intraday.?

    5) is pi itself sufficient to fully automate the trading terminal of dealer.?

    6) is their enquiry about order status available in pi(TS) or need support of ami(AFL).?

    7) for pi based semi automation do i need to subscribe datafeeds.?

    8) pi is not installing on my system. my OS date expired, is it the reason?

    9) do you offering any API for pi based automation?

    10) is Trade Script will allow to code for BO, AMO, and Basket Orders?

    Please Answer my Queries here. Dont reply with contatc tsiva or any other?

    • Gopi, I can answer only those which are general queries, anything specific to your account you will still have to send an email to [email protected] 🙂
      1. No, you can’t fetch order status using Tradescript.
      2. Currently no, but we will soon have it for people using Pi bridge.
      3. As of now not possible, people who fire orders using Ami and Pi bridge are doing it as market orders.
      4. Yes
      5. Yes, but we are still not letting this happen.
      6. Using AFL you should be able to fetch order details using Pi bridge soon.
      7. Semi automation on Pi using tradescript – you don’t need datafeeds as it is already available on Pi. If you are semi-atuomating through AFL, you will need data feeds to run Amibroker.
      8. Possible, you need to send an email to [email protected]
      9. The bridge itself can be used for automation.
      10. No

  307. Gopi says:

    pi will fire the orders, then what is the use of amibroker?

    • The programming language on Pi called tradescript is not as advanced as AFL (amibroker formula language). So if it is any complex strategy, you will need to use AFL.

  308. ashokn4ever says:

    Dear Nithin,
    Do you have any Mutual Fund Assistance with Zerodha?

  309. akhil says:

    please dont get into investment advisory services market is flooded with those , the only reason i and a lot of other people came here was because of your low cost if you expand into those areas i beleive you wont be able to sustain your low cost
    please a lot of indians only require the basics email statements optional mobile alerts i believe nse does that free of cost for trade confimations //and no hidden charges especially no hidden charges if you charge only what you advertise people will be loyal to you other wise if they see there money drained without prior notification they will instantly switch over

    • Yep, we haven’t done advisory for last 5 years, and don’t intend to get into doing that in the future as well.

      • Pritam says:

        Yes i agree , just concentrate on the scaling to large number of retail clients , no need for stock research etc , only need to get better in improving the technology part like adding more features to mobile app etc .

  310. Honest krishna says:

    Can you generate best trade signals out of using many of these proven strategies and send to the terminal of clients as buy or sell orders with defined risk ratios. You can provide a option to pre select risk (quantity) of different levels and upon selecting the same, quantity should auto appear in the order. It should generate by default bracket order. It should be for top 200 cash liquid stocks, liquid futures,highly traded options, Nifty and nifty options also.
    We believe any recommendation with certain degree of faith, and we have full faith in you systems. This will provide lot of comfort for the clients. You should build expert team to get best trades using all these. For clients who are not pro in technical this will be like heaven. And also no need for clients to invest in costly hardware.

    • Honest krishna says:

      Also if it can be done through call and trade then its awesome.

    • Yes Krishna, but if we give such signals we will be getting into that investment advisory side of business. We don’t want to get there atleast for now. Have replied to ur email.

  311. Paras says:

    Hello Nithin,

    I am facing lot of problems while trading through current zerodha web portal, i am eagerly waiting for using KITE. So can you please let me know when we are planning to launch KITE.


  312. Kiran says:

    Hello Nithin,
    I opened my account at zerodha on nov last year. Since then I have been quite satisfied with the service. But off late I am having some tough experiences from the support team. I really feel I should bring it to your notice, so posting it here. If you could get back to me, I can clarify.

  313. charan says:


    My charts are not loading in PI it says unable to “connect to the data server should be soon” . I am not able trade because of this. whom should i contact for this???


    • Charan, we had sent an email/SMS asking to update Pi with the latest patch available on Q. Go to q.zerodha.com, download the latest patch that you see under Pi menu. Run this patch, it should start working.

  314. sohail says:

    Hello Sir,
    I am sending u these stregies. can these be coded by ur team.
    1. When 12 ema crosses above/ below 26 ema with increae in volume.
    2. When scrip breaks previous day high or previous day low with increase in volume
    3. When scrip is +5% or -5% with increase in volume.
    Does ur software indicates intraday new highs and lows made by the srips.
    Is ur brokerage is same for low volume traders or ocassional traders

  315. Piyush says:

    I want to know the code for ADX and MACD to back test please can anyone help me.

    Thank you

  316. khuranavikram says:

    i got sms regarding new version of Pi dated 11.5.15 but not able to find the link. Please help.


  317. harpreet singh says:

    is there an ea for floor pivots?? if not i request you to add this simple tool to pi …

  318. Samir says:

    Hi Nithin,
    I have 3 Questions.
    1. Why you don’t have Channel breakout indicator in Pi, it does not have to do any calculation at all.
    2. Do you have indicator for Swing trading in Pi,
    3. The Pi upgrade link is not working, every time I enter my user id and password its rejecting, also it blocks after 3 attempts.

  319. Rahul Shah says:

    I have apply EA of 14-26 EMA crossover but I am not able to see any alert in generated alert box why is so?
    and whenever I do anything in artificial intelligence section PI got stuck.

  320. vivek says:

    in the image above(http://zerodha.com/z-connect/wp-content/uploads/2015/05/back2.jpg) a backtest is being done using the 50 ema crossover. somehow i feel it cannot be so profitable as is being suggested by the backtest report(i know its not inclusive of costs. but even if costs are factored in, its still a very good outcome 8782 pts profit may reduce to maybe around 3000 pts).
    my question is: can i fully rely on the backtest report, when even such a simple strategy appears to be easily profitable?

    • Vivek, you can plot the backtest with the chart to see the buy/sell signals on the chart. You can also look at the trades that show up in the backtest report.

      • nipun says:

        I think back test report is not reliable if it computes profit using ltp.
        I have some questions about backtest report ,
        In backtest which price considered ,Is it LTP or Buy/Sell ?
        If Buy trade then it always gives seller price as displayed on live .

  321. Saket says:

    Couple of quick questions:

    (1)Can I automate the trade execution part as well? Meaning if certain conditions are met automatically execute buy/sell of a script(without any manual intervention).

    (2)If above setting is possible, please confirm that once done above setting can be switched ‘on’ until I manually deactivate same.

    I need to take the human emotions completely out of trading.


    • The facility is there on the platform to automate trade execution, but we can’t offer as the exchanges in India don’t allow retail automation of trading strategies.

      • Prateek Jhunjhunwala says:

        So an individual trader in India cannot do automated trading, even if he puts more than Rs 2 lacs in his trading account? Any other options which he could explore?

        • Prateek, yes. Exchanges say that if the strategy is running on the brokerage’s server, and if it is approved, it should be okay. But again, regulations around this are very grey.

      • Nilesh says:

        Hi Nitin,
        I have created a strategy and applued it in EA. Now I want to execute the buy / sell orders automatically as per the signals.
        Could you please guide me how i can do it through Pi.


  322. R.K says:

    Hi Nithin,

    I recently opened a a/c with Zerodha, whats the historical data available in Pi, as i could see candle only from 1-Jan-2015 in Bank nifty , and if that is the limit right now, when can we get complete data. thank you

    • R.K, if you are opening futures historical data, you will be able to see it only from when the contract came into existence. So May futures, you can see only from Feb end. If you open spot/index charts, you can see intraday from last 7 to 8 months, historical upto 5 years for top 200 stocks, Nifty and Banknifty.

  323. Arun Kamath says:

    Hope you add ichimoku EA as well

  324. dvr says:

    Hi nitin,
    I want to do this backtest using spot prices, but data source is available for future prices. Is there any way to backtest our code with spot prices?

    • Yes dvr, while backtesting instead of choosing Futures, choose spot. Currently there is historical data for the top 200 stocks, and Nifty/Banknifty spot indices.

      • dvr says:

        Thanks nitin, I think i can’t see the spot option as my account is only enabled by FnO trading only.

        • ah right, so you have to either open a new demat, or send us a client master proof from any other demat that you hold. This can be mapped, after which you will start seeing spot prices as well.

  325. krunesh says:

    When I click to open chart, it stops working. it is happening again and again.

  326. santana pereira says:

    hI nithin,
    I have three queries
    1) In Sharekhan or Geojit when any new updates are available, we have to click in their platform
    software itself. And your software is updated to latest.
    I phone to your support team to update my Pi latest v1.0.0.6, he says I have to write to
    your [email protected], Which delays the matter ?
    2) Also another doubt is the code language used in Zerodha platform and Pi platform is same ?
    Since your Pi is your latest, can I see the link or all codes done in Pi platform. Then only I can decide to go for BRIDGE connect to AMIBROKER.
    3) the alerts generated in Pi platform cannot be transfered to SMS or email, to avoid near the computer whole day.?
    Yours sincerely,

    • 1. The latest release of Pi has the option “Check for updates” in the help menu.
      2. You can see quite a few sample tradescript codes here. But this is different from AFL used on amibroker, so a little confused on what you are asking.
      3. Not possible for now.

  327. ST says:

    New version is crashing too much. If i open more than one chart it crashes,from morning till now it happened 6 times.

  328. Sushovan says:

    Why not put a option to convert this page as a printable format ? That way I can take a printout instead of opening the page everytime I need to refer.

  329. vivek says:

    Awesome work zerodha for the 100 EAs list (https://zerodha.com/expert-advisors)…..am just lost for words

    “We have also given over 30 public EAs to help you get started on Pi.”
    where are those EAs?

  330. stock hunter says:

    Hi Nithin, I checked Edit expert advisor option but there is no “Apply”menu..Please check the screen shot for your reference

  331. manju says:

    Wud be great if you list all the Amibroker snippet equivalents for TradeScript. For example, the previous candle is defined as Ref( L , -1) whereas here its slightly different i think.

    • Yes Manju, we will introduce all of this here: https://zerodha.com/expert-advisors/. If you have any queries on this do ask on http://tradingqna.com/

      • Sudhir shenoy says:

        Hi Zerodha team. I would like to suggest a technical tip that the renkos is not time bound so the pi should go in 0 minute span immediately we select renko as charting pattern but 0 minute is not a option. Saw that the sensitivity of price is affected by this. The renko is reluctant to form till the minute is over . Please respond

        • Renko on Pi needs some fixes, we are working on it. Suggest you to use the charts on Kite if following Renko.

          • Vishal says:

            Hi Nithin….

            You guys created amazing product/company Zerodha.
            I wonder all strategies are Math calculations. I mean why would any retail investor learn technical analysis when softwares like Pi-bridge can automate strategies execution and make money.

            Do you have any software which can signal buy/sell based on All the indicators and Technical Graphs available. Why we retail investors need to cram/learn.


          • Latha George says:

            Dear Nitin,

            How to make an EA for the following logic

            Paramter Value
            Preferred Timeframe Intraday 1 minute
            Indicators Used RSI(17), ADX(14)
            Buy Condition RSI(17)>=75 AND ADX(14)>25
            Short Condition RSI(17)25
            Sell Condition Same as Short Condition OR Time>=03:15 PM
            Cover Condition Same as Cover Condition OR Time>=03:15 PM
            Stop Loss 0.5%
            Targets No fixed target, Stop and reverse when AFL gives opposite signal
            Position Size 150 (fixed) or 80% of equity (as per your risk appetite)
            Initial Equity 200000
            Brokerage 50 per order
            Margin 10%

      • sanjay says:

        is there possible to got all the stocks list that crrosed 10-20 or 50-100 sma crossover at the end of the day or in live market from all nse scripts not specific scripts.

        • Currently no, maybe in the future.

          • RISHABH says:


          • Ashit Vora says:

            It should be possible using Kite API. Right?
            ie. Scanning all the stocks and sending a alert when a event is triggered.

          • Ashit Vora says:

            It should be possible using Kite API. Right?
            ie. Scanning all the stocks and sending an alert when an event is triggered.

          • vijay says:

            Dear Sir,
            Is it possible to create range break out strategy say for first 15 min high low and trade on break out on either side…. or range an be customize
            I am not tech savvy…it would be great if your team could help me out in coding this.

      • saroj kumar mondal says:

        Dear Nithin Sir,
        First of i want to say you are my true inspiration to the stock market. All i learned about Indian market because of your tutorial and zerodha. Thank you. And also i have question for you. Is it possible to generate alert not only generate alert page but also in chart in live market just like back test(green arrow, red arrow). Suppose i have 3 alert
        1. macd 2. stochastic 3. rsi. Suppose stochastic give buy signal and green arrow appear in chart with “2” written under the arrow. And again Thank you.

      • Vijay sharma says:

        How to do range break out startegy coding on PI

    • vijay says:

      Dear Sir,
      Is it possible to create range break out strategy say for first 15 min high low and trade on break out on either side…. or range an be customize
      I am not tech savvy…it would be great if your team could help me out in coding this.

    • Kunal says:

      How to write Vwap Script for buy and sell for Zerodha Script?
      5 min candle below vwap and 5 min candle above vwap?

    • Misleading Zarodha none of b says:

      Misleading none of volume indicators work on index. I will quit this useless platform

      • Shubham says:

        Hey, indices aren’t stocks or contracts and cannot be traded directly. You can only trade indices using F&O or ETFs.

        Since there are no trades on the Indices, volume data will not be available and the volume-based indicators will not show any data. Explained here.