Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

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 Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Algomojo Index Straddle/Strangle Execution Module with Intraday Stoploss

This tutorial focus on how to automate your index straddle/strangle strategy with intraday stop-loss levels with time-based entry and exits using Algomojo Platform and...
Rajandran R
7 min read

Learn How to Login into Algomojo Account using Amibroker

In the last tutorial, we learn how to automate the algomojo login process and in this video tutorial, we are going to learn with...
Rajandran R
1 min read

Amibroker Execution Module – Hedged Index Futures for Directional…

In the last tutorial, we learn the importance of Hedging Futures Position with OTM Options for Reduced Margin. This tutorial focus on how to...
Rajandran R
14 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