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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | // 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.