Augubhai's ORB System

#11
Hi Astro,

I hope you are testing with intraday data. The code is written for the 5 minutes timeframe - off course, you can change it. The lines will be clear if check in the 5 minutes timeframe.

The yellow patta indicates the Opening Range. We take position when the price breaks out of this range.

The red dotted line is the Stop Loss line. If the price touches this line, we exit immediately. Else, we exit at the end of day. You can vary the SL percentage and test different scenarios.

You can also optionally add a Target percentage. All this can be done by changing the parameters.

You
Please post in afl format copy and paste always gives errors unable to correct Regards:confused:
 
#12
Hi augubhai

A little more tweaking of the AFL is required. The break out is shown for first candle, where as it should for the range of candles selected in param. Probably these two lines need Modification?
ORBH = ValueWhen(NewDay,HighestOfDay ,1) * (1 + (EntryBufferPct/100));
ORBL = ValueWhen(NewDay,LowestOfDay ,1) * (1 - (EntryBufferPct/100));

I am not a programmer, so cant do anything on this.

Still a good afl.

SRJC
 

augubhai

Well-Known Member
#13
Hi augubhai

A little more tweaking of the AFL is required. The break out is shown for first candle, where as it should for the range of candles selected in param. Probably these two lines need Modification?
ORBH = ValueWhen(NewDay,HighestOfDay ,1) * (1 + (EntryBufferPct/100));
ORBL = ValueWhen(NewDay,LowestOfDay ,1) * (1 - (EntryBufferPct/100));

I am not a programmer, so cant do anything on this.

Still a good afl.

SRJC
Hi SJRC,

Thanks for pointing out the error. I am posting version 1.1 of the AFL. Please review it.
 

augubhai

Well-Known Member
#14
PHP:
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}




_SECTION_BEGIN("Augubhai's ORB System v1.1"); 

//--Intraday time frame 
TimeFrameSet(in5Minute); //If reseting, check formula for TimeFrameInMinutes 
TimeFrameInMinutes = 5;

//--Define all params 
EntryBufferPct = ParamOptimize("Entry Buffer %", 0, 0, 2, 0.1);
SLPct = ParamOptimize("SL %", 1.4, 0.1, 10, 0.1);
TargetPct = ParamOptimize("Target %", 0, 0, 20, 0.5);
MaxTarget = 100;
TargetPct = IIf(TargetPct == 0, MaxTarget, TargetPct); 
EntryTimeStart = ParamOptimize("Entry Time Start (Minutes)", 5, 5, 120, 5);
EntryBarStart = floor(EntryTimeStart/TimeFrameInMinutes) - 1;
EntryTimeEnd = ParamOptimize("Entry Time End (Minutes)", 25, 10, 180, 5);
EntryBarEnd = floor(EntryTimeEnd/TimeFrameInMinutes) - 1;
EntryBarEnd = IIf(EntryBarEnd < EntryBarStart, EntryBarStart, EntryBarEnd);  

//--Plot Price Candle Chart
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorBlack, styleNoTitle | GetPriceStyle() ); 

//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1  
NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0; 
printf("\n NewDay  : " + NewDay ); 
EndDay = (Day()!= Ref(Day(), 1)); 
printf("\n EndDay  : " + EndDay );
FirstBarTime = ValueWhen(NewDay,TimeNum(),1); 
EndTime = ValueWhen(EndDay,TimeNum(),1);
SquareOffTime = EndTime;

//--Calculate ORB, and SL
HighestOfDay = HighestSince(NewDay,H,1); 
LowestOfDay = LowestSince(NewDay,L,1); 
BarsSinceNewDay = BarsSince(NewDay);
ORBH = ValueWhen(BarsSinceNewDay<=EntryBarStart,HighestOfDay ,1) * (1 + (EntryBufferPct/100)); 
ORBL = ValueWhen(BarsSinceNewDay<=EntryBarStart,LowestOfDay ,1) * (1 - (EntryBufferPct/100)); 
ORBHSL = ORBH * (1-(SLPct/100)); 
//ORBHSL = ORBL; 
ORBLSL = ORBL * (1+(SLPct/100));
//ORBLSL = ORBH; 
ORBHTarget = ORBH * (1+(TargetPct/100));
ORBLTarget = ORBL * (1-(TargetPct/100));

//--Find Buy, Sell, Short & Cover Signals
BuySignal = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart); 
printf("\nBuySignal : " + BuySignal ); 
ShortSignal = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) ; 
printf("\nShortSignal  : " + ShortSignal ); 
BarsSinceLastBuySignal = (BarsSince(Ref(BuySignal,-1)) + 1);
BarsSinceLastShortSignal = (BarsSince(Ref(ShortSignal,-1)) + 1);
BarsSinceLastEntrySignal = Min(BarsSinceLastBuySignal, BarsSinceLastShortSignal);
BothEntrySignalsNull = IsNull(BarsSinceLastBuySignal) AND IsNull(BarsSinceLastShortSignal); //true for start of Day 1
printf("\n\nBarsSinceNewDay : " + BarsSinceNewDay ); 
printf("\n BarsSinceLastEntrySignal : " + BarsSinceLastEntrySignal); 
Buy = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Sell = (L <= ORBHSL) OR (H >= ORBHTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastBuySignal); 
Short = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Cover = (H >= ORBLSL) OR (L <= ORBLTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastShortSignal); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Handle if ORB broken both sides on same bar
//--And remove duplicate Sell & Cover signals, since ExRem did not work as needed when Buy & Sell on same bar
orbBothSides = IIf(Buy AND Short, 1, 0); 
Buy = IIf(orbBothSides AND C <= O, 0, Buy); 
Short = IIf(orbBothSides AND C > O, 0, Short); 
Sell = IIf(orbBothSides AND C > O AND (L <= ORBHSL), 1, Sell); 
Sell = IIf((BarsSince(Buy) < (BarsSince(Ref(Sell,-1))+1)) OR (BarsSince(Buy) AND IsNull(BarsSince(Ref(Sell,-1)))),Sell,0);
Cover = IIf(orbBothSides AND C <= O AND (H >= ORBLSL), 1, Cover); 
Cover = IIf((BarsSince(Short) < (BarsSince(Ref(Cover,-1))+1)) OR (BarsSince(Short) AND IsNull(BarsSince(Ref(Cover,-1)))),Cover,0);
printf("\n\norbBothSides : " + orbBothSides); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Special Condition for 18 & 19 May 2009
Buy =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Buy );
Sell =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Sell );
Short =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Short );
Cover =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Cover );

//--Set prices
BuyPrice = IIf(Buy, ORBH, Null); 
SellPrice = IIf(Sell, IIf(H >= ORBHTarget, ORBHTarget, Max(ORBHSL, L)), Null); 
ShortPrice = IIf(Short, ORBL, Null); 
CoverPrice = IIf(Cover, IIf(L <= ORBLTarget, ORBLTarget, Min(ORBLSL, H)), Null); 

//--Plot ORB, and SL 
Plot(ORBHSL,"",colorRed,styleDashed); 
Plot(ORBLSL,"",colorRed,styleDashed); 
Plot(IIf(TargetPct == MaxTarget, Null, ORBHTarget),"",colorGreen,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBLTarget),"",colorGreen,styleDashed);
PlotOHLC( ORBL, ORBH, ORBL, ORBH, "", colorYellow, styleCloud); 
 
//--Plot Signals
shape1 = Buy * shapeUpArrow + Sell * shapeDownArrow; 
PlotShapes( shape1, IIf( Buy, colorGreen, colorGreen), 0, IIf( Buy, Low, High ) ); 
shape2 = Cover * shapeUpArrow + Short * shapeDownArrow; 
PlotShapes( shape2, IIf( Cover, colorRed, colorRed), 0, IIf( Cover, Low, High ) ); 
GraphXSpace = 5; 

//--Restore time frame 
TimeFrameRestore(); 
_SECTION_END();
 

myamit

Well-Known Member
#18
Per your request, please find attached herewith chart of Nifty (your ORB AFL has already been applied) for last 5 days.

Also I had few questions...
1. On certain days you do not take trade (atleast as per AFL).... for example on 15-Mar-2011 (also on 12-Jan-2011) no trade executed. Could you please explain ration here?

2. You have defined special conditions for 18th May & 19th May 2009 ... Any specifc reason... or this was the election result day when Nifty hit upper circuit.

3. Could you please explain usage of variables EntryTimeStart, EntryBarStart, EntryTimeEnd, EntryBarEnd.

4. Also instead of target (can we define trailing stop loss after target is achieved)? For stoploss, I've tried to keep other side of range limit (+4 filter). I've seen that you've commented that code so it seems you also have tried/thought about this. I appreciate if you share your findings.

5. Lastly, do you consider taking mutiple trade in day (for example if SL has been hit on first trade or target has been achieved .. and ofcourse we are again in range for while).

Thank you for all your help.
 
Last edited:

augubhai

Well-Known Member
#19
Per your request, please find attached herewith chart of Nifty (your ORB AFL has already been applied) for last 5 days.
Amit, thanks for posting the chart. This will really help people to "see" the method.

Also I had few questions...
1. On certain days you do not take trade (atleast as per AFL).... for example on 15-Mar-2011 (also on 12-Jan-2011) no trade executed. Could you please explain ration here?
I do not have the historical data for these dates, but I am guessing that these were dates on which there was no opening range breakout in the first 25 minutes. I am assuming that you did not change the default parameters in my code while creating the chart.

In my code, I have set the default values of EntryTimeStart as 5 minutes, and EntryTimeEnd as 25 minutes.

EntryTimeStart is the period that is considered for the Opening Range. So if the EntryTimeStart is 5 minutes, the High and Low at the end of the first 5 minutes of trading will define the Opening Range for the day. Whenever, price goes above the High+Buffer, we Buy. Similarly, if price goes below the Low-Buffer, we Sell.

Hope this explanation is clear. The Opening Range is the most important concept in any ORB method. It is simple stuff, but maybe the way that I am explaining makes it sound complex.

I have also used a parameter EntryTimeEnd. The default value is 25 minutes, which means that if the price does not break out of the Opening Range (above the High+Buffer or below Low-Buffer) within the first 25 minutes of trading, we will not trade on that day. I am guessing that this is what happened on the dates that you mentioned. Most of the times, if the range is not broken within the first hour or so, if may just turn out to be a range-bound day and not very profitable. Just my observation on a few days - but I have also seen many exceptions.

You can change the value of EntryTimeStart, EntryTimeEnd and other parameters by right clicking on the chart and selecting "Parameters".

2. You have defined special conditions for 18th May & 19th May 2009 ... Any specifc reason... or this was the election result day when Nifty hit upper circuit.
Yes. that was the election result day. We would not have been in a position to trade this method on that day.

3. Could you please explain usage of variables EntryTimeStart, EntryBarStart, EntryTimeEnd, EntryBarEnd.
EntryBarStart is the bar corresponding to the EntryTimeStart, and EntryBarEnd is the bar corresponding to the EntryTimeEnd

4. Also instead of target (can we define trailing stop loss after target is achieved)? For stoploss, I've tried to keep other side of range limit (+4 filter). I've seen that you've commented that code so it seems you also have tried/thought about this. I appreciate if you share your findings.
The other side of range is not something that I have seriously considered. The reason is that on some days the range is very narrow, and a small pullback will hit your stop loss. On other days, the range can be very wide, increasing the risk. If we want to use the other side of range, then it will be good to avoid trades on days when the range is very narrow or very wide. Just my thoughts, but I have not evaluated seriously.

5. Lastly, do you consider taking multiple trade in day (for example if SL has been hit on first trade or target has been achieved .. and ofcourse we are again in range for while).
As I mentioned, the inspiration for this method came from Dhiraj's 2652 method, where you take the trade in the opposite direction if the Stop Loss is hit. I did consider a similar approach, but did not evaluate it rigorously. This single breakout method itself is profitable enough.

Thank you for all your help.
Whew! I think this is the longest post that I have ever written.
 
#20
i am also a new Amibroker user, and really want to learn TA with the same.
You are the most welcomed as a teacher for Bigenners.more than thanks lot...........................................
 

Similar threads

Zerodha – Open Paperless Account

Open online account with Zerodha. Free delivery trading and Max Rs 20 for Intraday, F&O, Currency and Commodity Trading. Intraday High leverage with MIS, CO and BO.

Name:Phone:
Email:City:
State:
Are you a day trader?