Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Now the recent curiosity on building Trading AI Agents.

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. A complete example is the backtestable ORB study for Amibroker.

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.

Masterclass on AmiBroker AFL coding

AMIBROKER

Masterclass on AmiBroker AFL coding

Write trading systems, explorations and backtests in AFL, and use ChatGPT to code faster.

  • AFL from basics to trading systems
  • Backtesting and optimisation done right
  • 7 courses in one masterclass
Learn AFL coding →by Marketcalls

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.

ORB levels AFL open range breakout indicator chart

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);
Marketcalls Elite Traders Club

MEMBERSHIP

Marketcalls Elite Traders Club

Every Marketcalls course and live mentorship in one membership: 127 courses and 2,500+ hours of learning.

  • Market Profile, Orderflow, AFL, Pine Script and Python
  • Live mentorship and TradEdge trading room
  • Premium tools and the Elite Slack community

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Now the recent curiosity on building Trading AI Agents.

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