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.
Coding and Backtesting
- 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.
- Similarly click on Sell and mention the code Close<EMA (close,50).
- 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.
- 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.)
- 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.
- 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.
Expert Advisors or EA’s
Now that you are satisfied with the backtest results, you can create your EA.
- Click on “Create new Expert Advisor” under the main menu Artificial Intelligence.
- 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.
- Copy paste the same code from your backtest window for buy/sell respectively.
- Click on Save, this will create your EA – EMA Cross.
Taking the EA live
- 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).
- 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.
- 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.
- Click on Apply to take the EA live. You will now start getting buy/sell signals based on this EA.
- To disable EA’s, untick and apply.
- 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.
Generated Alerts by the EA
- Click on Generated Alerts under the Alerts menu to initiate the window as shown above.
- All the EA’s, whenever generating a buy/sell signal, they get logged on this window with their names clearly mentioned.
- If you wish to execute an order based on this signal, click on the Buy/Sell box.
- You can change the quantity/price on the buy/sell order form.
- You can enable/disable sound alerts for Expert Advisors as shown below.
- Generated alerts can only be executed manually by clicking on Buy/Sell on the Generated Alerts page.
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.