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)

Code Snippet : ORB – Open Range Breakout Levels – Amibroker AFL Code (Better Version)

1 min read

Open Range Breakout is a simple strategy that monitors the first 5min / 15min / 15min / 30min / 60min range from the start of the market. From the opening high range and low range is calculated for the specified timeframe. Most of the AFL code found on the internet is either buggy or not suitable for building back-testable trading systems. To solve this issue we are releasing a prototype for ORB – Open Range Breakout Levels. On top of this indicator now traders can build backtestable trading systems.

Recommended Timeframe to Run this strategy: 1min or 5min charts (Higher timeframe may or may not yield desired results)

By default, the code uses a 60min range breakout from the market open. However, Parameters can be changed from the Parameter window. Currently Open Range breakout options are available for 5min / 15min / 15min / 30min / 60min ranges. However, if someone needs a customized ORB range then code customization needs to be done accordingly.

Code will start plotting the Open Range values only if the Open Range timeframe is completed else nothing will be plotted. For example for an Open Range value of 60min. The plot will start only from 10:15:00 onwards for NSE Futures instruments and will start from 11:00:00 onwards for MCX futures instruments automatically.

The code works well with Illiquid scripts. Quick AFL is turned off to compute for all the bars.

Code Snippet: ORB – Open Range Breakout Levels – Amibroker AFL Code

//Better Version of Open Range Breakout 
//Coded By Rajandran R - www.marketcalls.in
//Created Date - 04 Dec 2018

//Recommended Timeframe to Run this strategy : 1min or 5min charts 
//Higher timeframe may or may not yield desired results

_SECTION_BEGIN("Open Range Breakout");

SetBarsRequired(-2,-2); //Turn Quick AFL Off

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g ", Ref(O,-1), Ref(H,-1), Ref(L,-1), Ref(C,-1)));

SetChartOptions(0 , chartShowArrows | chartShowDates);
Plot(Close,"Candle", colorDefault, styleCandle);


orb = ParamList("ORB Range", "5min|10min|15min|30min|60min",4);

newday = Day() != Ref(Day(),-1);  //check if new day or not

starttime = ValueWhen(newday,TimeNum());


//5min ORB
if(orb == "5min")
{
IBendtime = starttime+500;
minh = ValueWhen(newday,TimeFrameGetPrice("H",in5Minute));
minl = ValueWhen(newday,TimeFrameGetPrice("L",in5Minute));
}

//15min ORB
if(orb == "10min")
{
IBendtime = starttime+1000;
minh = ValueWhen(newday,TimeFrameGetPrice("H",in5Minute*2));
minl = ValueWhen(newday,TimeFrameGetPrice("L",in5Minute*2));
}



//15min ORB
if(orb == "15min")
{
IBendtime = starttime+1500;
minh = ValueWhen(newday,TimeFrameGetPrice("H",in5Minute*3));
minl = ValueWhen(newday,TimeFrameGetPrice("L",in5Minute*3));
}


//30min ORB
if(orb == "30min")
{
IBendtime = starttime+3000;
minh = ValueWhen(newday,TimeFrameGetPrice("H",in5Minute*6));
minl = ValueWhen(newday,TimeFrameGetPrice("L",in5Minute*6));
}

//60min ORB
if(orb == "60min")
{
IBendtime = starttime+6000;
minh = ValueWhen(newday,TimeFrameGetPrice("H",inhourly));
minl = ValueWhen(newday,TimeFrameGetPrice("L",inhourly));
}

printf("%g",IBendtime);

DayOpen = TimeFrameGetPrice("O",inDaily);
DayHigh = TimeFrameGetPrice("H",inDaily);
DayLow = TimeFrameGetPrice("L",inDaily);

ORBH = IIf(TimeNum() < IBendtime, Null ,minh);
ORBL = IIf(TimeNum() < IBendtime, Null, minl);


Plot(ORBH,"ORBH",colorBlue);
Plot(ORBL,"ORBL",colorred);
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)

Stoploss, Multi Target, and Trailing Stoploss Module – Amibroker…

After Intraday V2.0 Amibroker Module - a readymade drag and drop module to convert any trading strategy into the intraday trading system with alerts,...
Rajandran R
6 min read

Line Trading – Algomojo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
58 sec read

Plotting Day Wise Equity Curve using Amibroker

We know that Amibroker provides an equity curve for the whole strategy. Is there a way where we can build a simple Day Wise...
Rajandran R
1 min read

7 Replies to “Code Snippet : ORB – Open Range Breakout Levels…”

  1. Hi.. sir.. can u please add the option to make the ORB lines thicker.. it’s too thin.. it’s hard to see..

    Thanx in advance..

  2. sir can you please help to create complete code for buy and sell event with fixed target price ?

Leave a Reply

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