Augubhai's ORB System

augubhai

Well-Known Member
#2
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"); 

//--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); 
ORBH = ValueWhen(NewDay,HighestOfDay ,1) * (1 + (EntryBufferPct/100)); 
ORBL = ValueWhen(NewDay,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
BarsSinceNewDay = BarsSince(NewDay); 
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();
 
Last edited:

augubhai

Well-Known Member
#3
Many good systems in this forum are ignored just because the author does not evangelize it. Not everyone can be a Saint or SH. I definitely will not have much time to respond to queries about this system. This is out here for any one to back test, and use profitably.

Let's see if this gets noticed or ignored.

Due credit should go to Dhiraj's 2652 system for inspiring me to develop this system.
 

lvgandhi

Well-Known Member
#4
How to use it? Can you describe the system?
 
#5
It looks good, but how do you use it? It would be nice if you could give us an example of how you used it on nifty charts and when did you buy and when did you sell and under what conditions.
 
#6
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"); 

//--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); 
ORBH = ValueWhen(NewDay,HighestOfDay ,1) * (1 + (EntryBufferPct/100)); 
ORBL = ValueWhen(NewDay,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
BarsSinceNewDay = BarsSince(NewDay); 
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();
Could you help me how to plot this AFL in Amibroker
 

augubhai

Well-Known Member
#7
To answer the queries above - this is a simple intraday ORB system. ORB stands for Opening range break-out.

We decide on a period to watch - it could be the first 5, 10, 15, 30, 60 minutes - anything that you decide. Assuming that we decide that the opening range period is 10 minutes. At the end of 10 minutes, place a Buy Stop Loss order at the day's high(+filter), and a Sell Stop Loss order at the day's low(+filter). The filter need not be a big number, otherwise you could lose some part of a good move.

If the Buy Stop Loss gets triggered, you could either decide to leave the the Sell Stop Loss unchanged or modify it to a fixed percentage or a trailing Stop Loss. It is up to you to decide on the stock, filter, and method of Stop Loss once you are in position.

The premise is that we make the most profits during trending days. Generally, on trending days, the Open and Close are at near the extreme ends of the daily range, with minor pullbacks. So once you are in position, if you set your Stop Loss to avoid pullbacks, then you would get the most of a trending day with less risk. The key here is to decide on the Stop Loss. The Stop Loss will vary from stock to stock and period to period. The AFL will help you backtest and decide on the Stop Loss.

With whatever backtest I have done, the maximum returns were when there was no stop loss. Obviously, that is more risky, and I never trade without a Stop Loss.

This is not something new that I discovered. You will find so many ORB systems on the internet. What I want to share is that I have been profitably trading this system successfully for many years now - on NIFTY and recently on Bank Nifty. (Sometimes there have also been very serious whipsaws as well).

This is an Intraday method that does not require any charts. You just need to know the day's high and low at the end of the opening range period. You also do not need any AFL, except for backtesting.

Hope this answers your queries.
 
#9
now ther is no error sorry about this but some qu.
1- what is the mining of yallow patta (line)????
2-what is the mining of red doted line ???

Plese help .....
 

augubhai

Well-Known Member
#10
now ther is no error sorry about this but some qu.
1- what is the mining of yallow patta (line)????
2-what is the mining of red doted line ???

Plese help .....
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
 

Similar threads