Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Introduction to Backtesting a Trading System using Amibroker

56 sec read

Backtesting is a simple process that helps a trader to evaluate his trading ideas and provides information about how good the trading system performs on the given historical dataset. It talks a lot about the behavior of the trading system, the risk involved in trading a particular trading system, and a lot about trading system performance. Here is a video tutorial with step by step guide on how to perform simple backtesting using Amibroker.

Simple EMA Crossover Trading System

//Marketcalls Backtesting Tutorial

_SECTION_BEGIN("EMA Crossover Trading System");
SetChartOptions(0,chartShowArrows|chartShowDates);

//Plot CandleSticks
Plot( C, "Price", ParamColor( "Color", colorDefault ), ParamStyle( "Style", styleCandle, maskPrice ) );


//Compute EMA 20 and EMA50

EMA20 = EMA(C,20);
EMA50 = EMA(C,50);


//Plot the EMA lines


Plot(EMA20,"EMA20",colorGreen,styleLine);  //Shorter Length EMA
Plot(EMA50,"EMA50",colorblue,styleLine);  //Longer Length EMA


//Logical Buy and Sell Rules

Buy = Cross(EMA20,EMA50);  //Positive Crossover 
sell = Cross(EMA50,EMA20); //Negative Crossover

//Short AND Cover for a system which wants to go short


//Plot Buy and Sell Arrows

/* Plot Buy and Sell Signal Arrows */

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);



//At what Price to Buy

BuyPrice = Close;
SellPrice = Close;


//Money Management - How much to buy


SetPositionSize( 100000, spsValue ); // 1 Lakh in each trade

//PositionSize = 100000;



//Trade Delays

SetTradeDelays(0,0,0,0);




_SECTION_END();
Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Sending Smart Futures/Spot – Signals to Two-Legged Options Execution…

Thought of making an open source AFL code demanded by most of the option traders to control the cost, to control the risk, and...
Rajandran R
12 min read

Send Smart Options Execution Orders from Futures or Spot…

This tutorial provides instructions on how to utilize simple buy and sell trading signals in Spot/Future charts to place option orders (including ATM, ITM,...
Rajandran R
19 min read

Backup your Amibroker EOD/Intraday Database in CSV Format

This Amibroker tutorial helps you to export your entire Amibroker EOD/Intraday Database in CSV Format with just a click of a button. Backing up...
Rajandran R
1 min read

5 Replies to “Introduction to Backtesting a Trading System using Amibroker”

  1. Sir, whether there is a similar indicator as mt4 Fiji trend indicator , in amibroker Afl code, where we can curve fit / modify the time frame in the indicator ?, If any kindly specify..,

  2. There are somany system avilble on your site and am confused.am new in this field and trding in bullionfutures carryforwrd.
    Is it possible totrade witout stoploss?

    Plese advise suitble sytem/softwre for me

    1. 1)Learn how to backtest
      2)Take the system and backtest with your desired set of trading instruments
      3)Understand the risk/nature of trading system
      4)If suits your risk profile adapt it. Else move on to next one!

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More