Stock Portfolio Organizer
The ultimate porfolio management solution.
Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Open Range Breakout for Amibroker (AFL)
Rating:
4 / 5 (Votes 2)
Tags:
amibroker, ORB, breakout
Traditional Open Range Breakout Indicator
Indicator / Formula
Copy & Paste Friendly
// ORB Based Trading system with Stoploss and Target
_SECTION_BEGIN("ORB ");
SetPositionSize(1*RoundLotSize,spsShares);
newday = Day() != Ref(Day(),-1);
mins = Param("Breakout(mins)",15,1,60,1);
starttime = ParamTime("Start Time","09:30");
endtime = ParamTime("End Time","14:30");
sqofftime = ParamTime("Sqoff Time","15:15");
mode = ParamList("Risk Control(Stop/Target)","DISABLED|POINTS|PERCENTAGE");
buffer = Param("Buffer",0,0.05,1000,0.01);
stop = Param("Stoploss",20,0.05,1000,0.01);
target = Param("Target",50,0.05,1000,0.01);
TickSz = Param("Tick Size",0.05,0.0001,1,0.0001);
TradeLimit = Param("Trade Limit Per Day",2,1,10,1);
orbh = ValueWhen(newday,TimeFrameGetPrice("H",in1Minute*mins,0))+buffer;
orbl = ValueWhen(newday,TimeFrameGetPrice("L",in1Minute*mins,0))-buffer;
//removing the values of ORBH and ORBL until the breakoutmeasuretime is reached
orbh = IIf(TimeNum()<starttime,Null,orbh); //redefining the ORBH value
orbl = IIf(TimeNum()<starttime,Null,orbl); //redefining the ORBL value
Plot(orbh,"ORBH",colorYellow,styleThick);
Plot(orbl,"ORBL",colorYellow,styleThick);
//Initialization
Buy =0;
Sell = 0;
Short = 0;
Cover = 0;
longstoplevel = Null;
longtargetlevel = Null;
shortstoplevel = Null;
shorttargetlevel = Null;
//Trading Logic without Stop and Target
orbcondlong = IsNull(Ref(orbh,-1)) AND orbh>0 AND Open < orbh AND High > orbh;
orbcondshort = IsNull(Ref(orbl,-1)) AND orbl>0 AND Open > orbl AND low < orbl;
if(mode=="DISABLED")
{
//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong) AND TimeNum()>=starttime AND TimeNum()<=endtime;
Sell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND TimeNum()<=endtime;
Cover = Cross(High,orbh) OR TimeNum()>=sqofftime;
//Removing Excessive Signals only for Entry
Buy = ExRem(Buy,Sell);
Short = ExRem(Short,Cover);
//removing excessive signals for the day
Buy = Buy AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
short = short AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
//Remove Excessive Entry and Exit Signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
BuyPrice = ValueWhen(Buy,orbh);
SellPrice = ValueWhen(Sell,IIf(Cross(orbl,Low),orbl,Close));
ShortPrice = ValueWhen(Short,orbl);
CoverPrice = ValueWhen(Cover,IIf(Cross(High,orbh),orbh,Close));
buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);
}
if(mode=="POINTS")
{
//Trading Logic with Stop and Target (points)
//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong) AND TimeNum()>=starttime AND TimeNum()<=endtime;
iSell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND TimeNum()<=endtime;
iCover = Cross(High,orbh) OR TimeNum()>=sqofftime;
//Removing Excessive Signals only for Entry
Buy = ExRem(Buy,iSell);
Short = ExRem(Short,iCover);
//removing excessive signals for the day
Buy = Buy AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
short = short AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
//Calculate the Entry Price
BuyPrice = ValueWhen(Buy,orbh);
ShortPrice = ValueWhen(Short,orbl);
longstoplevel = BuyPrice - stop;
longtargetlevel = BuyPrice + target;
shortstoplevel = shortPrice + stop;
shorttargetlevel = shortPrice - target;
//Exit signal can happen due to 1)Negative Crossover 2)Stophit 3)Targethit
Sell = isell OR Cross(longstoplevel,Low) OR Cross(High,longtargetlevel);
Cover = icover OR Cross(High,shortstoplevel) OR Cross(shorttargetlevel,Low);
//Remove Excessive Entry and Exit Signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
//Long Exit Price
SellPrice = IIf(isell,ValueWhen(isell,orbl),
IIf(Cross(longstoplevel,Low),longstoplevel,
IIf(Cross(High,longtargetlevel),longtargetlevel,null)));
//Short Exit Price
CoverPrice = IIf(icover,ValueWhen(icover,orbh),
IIf(Cross(High,shortstoplevel),shortstoplevel,
IIf(Cross(shorttargetlevel,Low),shorttargetlevel,null)));
buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);
Plot(IIf(buycontinue,longstoplevel,Null),"BuyStop Level",colorRed,styleDashed);
Plot(IIf(buycontinue,longtargetlevel,Null),"BuyTarget Level",colorgreen,styleDashed);
Plot(IIf(shortcontinue,shortstoplevel,Null),"ShortStop Level",colorRed,styleDashed);
Plot(IIf(shortcontinue,shorttargetlevel,Null),"ShortTarget Level",colorgreen,styleDashed);
}
if(mode=="PERCENTAGE")
{
//Trading Logic with Stop and Target (Percentage)
//Trading Logic with Stop and Target (points)
//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong) AND TimeNum()>=starttime AND TimeNum()<=endtime;
iSell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND TimeNum()<=endtime;
iCover = Cross(High,orbh) OR TimeNum()>=sqofftime;
//Removing Excessive Signals only for Entry
Buy = ExRem(Buy,iSell);
Short = ExRem(Short,iCover);
//removing excessive signals for the day
Buy = Buy AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
short = short AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
//Calculate the Entry Price
BuyPrice = ValueWhen(Buy,orbh);
ShortPrice = ValueWhen(Short,orbl);
longstoplevel = BuyPrice*(1 - stop/100);
longtargetlevel = BuyPrice * (1+target/100);
//Round it of to nearest Tick Size
longstoplevel = TickSz * round(longstoplevel/TickSz);
longtargetlevel = TickSz * round(longtargetlevel/TickSz);
shortstoplevel = shortPrice * (1 + stop/100);
shorttargetlevel = shortPrice * (1-target/100);
//Round it of to nearest Tick Size
shortstoplevel = TickSz * round(shortstoplevel/TickSz);
shorttargetlevel = TickSz * round(shorttargetlevel/TickSz);
//Exit signal can happen due to 1)Negative Crossover 2)Stophit 3)Targethit
Sell = isell OR Cross(longstoplevel,Low) OR Cross(High,longtargetlevel);
Cover = icover OR Cross(High,shortstoplevel) OR Cross(shorttargetlevel,Low);
//Remove Excessive Entry and Exit Signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
//Long Exit Price
SellPrice = IIf(isell,ValueWhen(isell,orbl),
IIf(Cross(longstoplevel,Low),longstoplevel,
IIf(Cross(High,longtargetlevel),longtargetlevel,null)));
//Short Exit Price
CoverPrice = IIf(icover,ValueWhen(icover,orbh),
IIf(Cross(High,shortstoplevel),shortstoplevel,
IIf(Cross(shorttargetlevel,Low),shorttargetlevel,null)));
buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);
Plot(IIf(buycontinue,longstoplevel,Null),"BuyStop Level",colorRed,styleDashed);
Plot(IIf(buycontinue,longtargetlevel,Null),"BuyTarget Level",colorgreen,styleDashed);
Plot(IIf(shortcontinue,shortstoplevel,Null),"ShortStop Level",colorRed,styleDashed);
Plot(IIf(shortcontinue,shorttargetlevel,Null),"ShortTarget Level",colorgreen,styleDashed);
}
_SECTION_END();
_SECTION_BEGIN("Trading Signal");
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(Sell * shapestar, colorBrightGreen, 0, High, 12);
PlotShapes(Cover * shapestar, colorRed, 0, Low, -12);
_SECTION_END();
_SECTION_BEGIN("Price");
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", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
//Dashboard Controls.
_SECTION_BEGIN("Trading Dashboard");
strg_name = ParamStr("Strategy Name","ORB");
fontsize = Param("Font Size",14,12,36,1);
GfxSelectFont("BOOK ANTIQUA", fontsize, 400);
GfxSetBkMode(1); //Transparent Mode
GfxSetTextColor(colorWhite);
//build dyanmic dashboard colors based on the ongoing trades
color = IIf(buycontinue,colorGreen,IIf(shortcontinue,colorRed,colorGrey40));
GfxSelectPen(colorWhite);
GfxSelectSolidBrush(SelectedValue(color));
width = Status("pxchartwidth"); //output will be in terms of number of pixels
height = Status("pxchartheight");
//GfxRoundRect(20,height-150,320,height-30,15,15);
GfxGradientRect(20,height-150,320,height-30,SelectedValue(color),colorBlack);
sigstatus = WriteIf(buycontinue,"Buy Signal",WriteIf(shortcontinue,"Short Signal","No Trade - Relax"));
PNL = IIf(buycontinue,Close-buyprice,IIf(shortcontinue,ShortPrice-close,Null));
GfxTextOut(strg_name,30,height-130);
GfxTextOut(sigstatus+" : "+IIf(buycontinue,BuyPrice,IIf(shortcontinue,ShortPrice,Null)),30,height-110);
GfxTextOut("Profit/Loss : "+SelectedValue(Prec(PNL,2)),30,height-90);
_SECTION_END();
1 comments
Leave Comment
Please login here to leave a comment.
Back
Wow.