-
Notifications
You must be signed in to change notification settings - Fork 0
/
ORBI_Algo.txt
409 lines (389 loc) · 18.1 KB
/
ORBI_Algo.txt
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#=========================================================================================================================
#SOURCE:
#=========================================================================================================================
#https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/
#=========================================================================================================================
HOW TO USE:
#=========================================================================================================================
Opening Range Breakout is one of the original Floor Trader Strategies.
Why it works: Overnight orders accumulate. Those orders being placed during the first 15 minutes of Regular Trading Hours combined with the typical high volume in the first 30 minutes of trading make this the most volatile trading period of the day. Regularly released reports during the first 30 minutes of trading add to the volatility and effect the days direction.
Original thinkScript Code: http://tos.mx/RiBfIw
You must understand the following notes from the author in order to use it:
Features of this study:
The yellow dashed line is the Day Filter Line and is used to determin the trend direction for the day. The dominant time spent above or below this line during the Opening Range Period typically determines the days trend.
Green points indicate a close at EOD above the yellow line.
Red Points a close below the yellow line. Yellow points a neutral or balanced day, close Between the Opening Range Extremes and often very near the Day Filter Line.
The Opening Range is plotted with a green and red dashed line. Trades can be taken when there is an open outside these range lines. Up to 5 Targets are generated using Average True Range to plot target lines. When price crosses the first target line part of the trade should be taken as Risk Off profit and a stop should be placed at the entry point ensuring a profitable trade.
If price crosses further targets stops should be moved to the proceeding target until stopped or your profit target is met. Initial Risk Stops are an open below the bar's low prior to entry or the Risk Lines plotted below the Opening range Lines. When price tests the opening range lines from below for the upper line or above for the lower lines trades can be taken with a first target to the yellow line from either direction and a Risk Stop line outside the opening range at the First Target lines or a close outside the Opening Range Lines.
FYI the color of Probable close direction points are statistically accurate between 60% and 70% of the time. Trading against the direction of the ORB's Day Filtered Direction should be considered counter trend trades.
As of 01.03.2017 You have just under a 52% probability that a DAILY bar will close green. So a 60% to 70% probability is a nice edge.
#=========================================================================================================================
#CODE:
#=========================================================================================================================
declare Hide_On_Daily;
declare Once_per_bar;
input OrMeanS = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input OrMeanE = 0935.0; #hint OrMeanE: End Mean period. Usually End of first bar.
input OrBegin = 0930.0; #hint OrBegin: Beginning for Period of Opening Range Breakout.
input OrEnd = 1000.0; #hint OrEnd: End of Period of Opening Range Breakout.
input CloudOn = no; #hint CloudOn: Clouds Opening Range.
input AlertOn = yes; #hint AlertOn: Alerts on cross of Opening Range.
input ShowTodayOnly = {"No", default "Yes"};
input nAtr = 4; #hint nATR: Lenght for the ATR Risk and Target Lines.
input AtrTargetMult = 2.0; #hint ATRmult: Multiplier for the ATR calculations.
def h = high;
def l = low;
def c = close;
def bar = barNumber();
def s = ShowTodayOnly;
def ORActive = if secondsTillTime(OrMeanE) > 0 and
secondsFromTime(OrMeanS) >= 0
then 1
else 0;
def today = if s == 0
or getDay() == getLastDay() and
secondsFromTime(OrMeanS) >= 0
then 1
else 0;
def ORHigh = if ORHigh[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then h
else if ORActive and
h > ORHigh[1]
then h
else ORHigh[1];
def ORLow = if ORLow[1] == 0
or ORActive[1] == 0 and
ORActive == 1
then l
else if ORActive and
l < ORLow[1]
then l
else ORLow[1];
def ORWidth = ORHigh - ORLow;
def na = double.nan;
def ORHA = if ORActive
or today < 1
then na
else ORHigh;
def ORLA = if ORActive
or today < 1
then na
else ORLow;
def O = ORHA - Round(((ORHA - ORLA) / 2) / TickSize(), 0) * TickSize();
def ORActive2 = if secondsTillTime(OREnd) > 0 and
secondsFromTime(ORBegin) >= 0
then 1
else 0;
def ORHigh2 = if ORHigh2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then h
else if ORActive2 and
h > ORHigh2[1]
then h
else ORHigh2[1];
def ORLow2 = if ORLow2[1] == 0
or ORActive2[1] == 0 and
ORActive2 == 1
then l
else if ORActive2 and
l < ORLow2[1]
then l
else ORLow2[1];
def ORWidth2 = ORHigh2 - ORLow2;
def TimeLine = if secondsTillTime(OREnd) == 0
then 1
else 0;
def ORmeanBar = if !ORActive and ORActive[1]
then barNumber()
else ORmeanBar[1];
def ORendBar = if !ORActive2 and ORActive2[1]
then barNumber()
else ORendBar[1];
def ORL = if (o == 0 , na, o);
plot ORLext = if barNumber() >= highestAll(ORmeanBar)
then HighestAll(if isNaN(c[-1])
then ORL[1]
else double.nan)
else double.nan;
ORLext.SetDefaultColor(color.Yellow);
ORLext.SetStyle(curve.Long_DASH);
ORLext.SetLineWeight(3);
ORLext.HideTitle();
def ORH2 = if ORActive2
or today < 1
then na
else ORHigh2;
plot ORH2ext = if barNumber() >= highestAll(ORendBar)
then HighestAll(if isNaN(c[-1])
then ORH2[1]
else double.nan)
else double.nan;
ORH2ext.SetDefaultColor(color.Green);
ORH2ext.SetStyle(curve.Long_DASH);
ORH2ext.SetLineWeight(3);
ORH2ext.HideTitle();
def ORL2 = if ORActive2
or today < 1
then na
else ORLow2;
plot ORL2ext = if barNumber() >= highestAll(ORendBar)
then HighestAll(if isNaN(c[-1])
then ORL2[1]
else double.nan)
else double.nan;
ORL2ext.SetDefaultColor(color.Red);
ORL2ext.SetStyle(curve.Long_DASH);
ORL2ext.SetLineWeight(3);
ORL2ext.HideTitle();
def RelDay = (ORL - ORL2) / (ORH2 - ORL2);
def dColor = if RelDay > .5
then 5
else if RelDay < .5
then 6
else 4;
def pos = (ORH2 - ORL2)/10;
plot d1 = if (TimeLine , ORH2, na);
plot d2 = if (TimeLine , ORH2 - ( pos * 2), na);
plot d3 = if (TimeLine , ORH2 - ( pos * 3), na);
plot d4 = if (TimeLine , ORH2 - ( pos * 4), na);
plot d5 = if (TimeLine , ORH2 - ( pos * 5), na);
plot d6 = if (TimeLine , ORH2 - ( pos * 6), na);
plot d7 = if (TimeLine , ORH2 - ( pos * 7), na);
plot d8 = if (TimeLine , ORH2 - ( pos * 8), na);
plot d9 = if (TimeLine , ORH2 - ( pos * 9), na);
plot d10 = if (TimeLine ,(ORL2), na);
d1.SetPaintingStrategy(PaintingStrategy.POINTS);
d2.SetPaintingStrategy(PaintingStrategy.POINTS);
d3.SetPaintingStrategy(PaintingStrategy.POINTS);
d4.SetPaintingStrategy(PaintingStrategy.POINTS);
d5.SetPaintingStrategy(PaintingStrategy.POINTS);
d6.SetPaintingStrategy(PaintingStrategy.POINTS);
d7.SetPaintingStrategy(PaintingStrategy.POINTS);
d8.SetPaintingStrategy(PaintingStrategy.POINTS);
d9.SetPaintingStrategy(PaintingStrategy.POINTS);
d10.SetPaintingStrategy(PaintingStrategy.POINTS);
d1.AssignValueColor(GetColor(Dcolor));
d2.AssignValueColor(GetColor(Dcolor));
d3.AssignValueColor(GetColor(Dcolor));
d4.AssignValueColor(GetColor(Dcolor));
d5.AssignValueColor(GetColor(Dcolor));
d6.AssignValueColor(GetColor(Dcolor));
d7.AssignValueColor(GetColor(Dcolor));
d8.AssignValueColor(GetColor(Dcolor));
d9.AssignValueColor(GetColor(Dcolor));
d10.AssignValueColor(GetColor(Dcolor));
d1.HideBubble();
d2.HideBubble();
d3.HideBubble();
d4.HideBubble();
d5.HideBubble();
d6.HideBubble();
d7.HideBubble();
d8.HideBubble();
d9.HideBubble();
d10.HideBubble();
d1.HideTitle();
d2.HideTitle();
d3.HideTitle();
d4.HideTitle();
d5.HideTitle();
d6.HideTitle();
d7.HideTitle();
d8.HideTitle();
d9.HideTitle();
d10.HideTitle();
addCloud(if CloudOn == yes
then orl
else double.nan
, orl2,createColor(244,83,66), createColor(244,83,66));
addCloud(if CloudOn == yes
then orl
else double.nan
, orh2,createColor(66,244,131), createColor(66,244,131));
# Begin Risk Algorithm
# First Breakout or Breakdown bars
def Bubbleloc1 = isNaN(close[-1]);
def BreakoutBar = if ORActive
then double.nan
else if !ORActive and c crosses above ORH2
then bar
else if !isNaN(BreakoutBar[1]) and c crosses ORH2
then BreakoutBar[1]
else BreakoutBar[1];
def ATR = if ORActive2
then Round((Average(TrueRange(h, c, l), nATR)) / TickSize(), 0) * TickSize()
else ATR[1];
def cond1 = if h > ORH2 and
h[1] <= ORH2
then Round((ORH2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else cond1[1];
plot ORLriskUP = if bar >= OREndBar and !ORActive and today
then HighestAll(ORH2ext - 2)
else double.nan;
ORLriskUP.SetStyle(Curve.Long_Dash);
ORLriskUP.SetDefaultColor(Color.Green);
ORLriskUP.HideTitle();
def crossUpBar = if close crosses above ORH2
then bar
else double.nan;
AddChartBubble(bar == HighestAll(crossUpBar), ORLriskUP, "RiskON ORH", color.green, no);
plot ORLriskDN = if bar >= OREndBar and !ORActive and close < ORL
then HighestAll(ORL2ext + 2)
else double.nan;
ORLriskDN.SetStyle(Curve.Long_Dash);
ORLriskDN.SetDefaultColor(Color.Red);
ORLriskDN.HideTitle();
def crossDnBar = if close crosses below ORL2ext
then bar
else double.nan;
AddChartBubble(bar == HighestAll(crossDnBar), HighestAll(ORLriskDN), "Risk ON ORL", color.red, yes);
# High Targets
plot Htarget = if bar >= BreakoutBar
then cond1
else double.nan;
Htarget.SetPaintingStrategy(paintingStrategy.Squares);
Htarget.SetLineWeight(1);
Htarget.SetDefaultColor(Color.White);
Htarget.HideTitle();
AddChartBubble(BubbleLoc1, Htarget, "RO", color.white, if c > Htarget then no else yes);
def condHtarget2 = if c crosses above cond1
then Round((cond1 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget2[1];
plot Htarget2 = if bar >= BreakoutBar
then condHtarget2
else double.nan;
Htarget2.SetPaintingStrategy(PaintingStrategy.Squares);
Htarget2.SetLineWeight(1);
Htarget2.SetDefaultColor(Color.Plum);
Htarget2.HideTitle();
AddChartBubble(BubbleLoc1, Htarget2, "2nd T", color.plum, if c > Htarget2
then no
else yes);
def condHtarget3 = if c crosses above condHtarget2
then Round((condHtarget2 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget3[1];
plot Htarget3 = if bar >= BreakoutBar
then condHtarget3
else double.nan;
Htarget3.SetPaintingStrategy(PaintingStrategy.Squares);
Htarget3.SetLineWeight(1);
Htarget3.SetDefaultColor(Color.Plum);
Htarget3.HideTitle();
AddChartBubble(isNaN(C[-1]), Htarget3, "3rd T", color.plum, if c > Htarget3 then no else yes);
def condHtarget4 = if c crosses above condHtarget3
then Round((condHtarget3 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget4[1];
plot Htarget4 = if bar >= HighestAll(BreakoutBar)
then condHtarget4
else double.nan;
Htarget4.SetPaintingStrategy(PaintingStrategy.Squares);
Htarget4.SetLineWeight(1);
Htarget4.SetDefaultColor(Color.Plum);
Htarget4.HideTitle();
AddChartBubble(BubbleLoc1, Htarget4, "4th T", color.plum, if c > Htarget4 then no else yes);
def condHtarget5 = if c crosses above condHtarget4
then Round((condHtarget4 + (ATR * AtrTargetMult)) / TickSize(), 0) * TickSize()
else condHtarget5[1];
plot Htarget5 = if bar >= BreakoutBar
then condHtarget5
else double.nan;
Htarget5.SetPaintingStrategy(PaintingStrategy.Squares);
Htarget5.SetLineWeight(1);
Htarget5.SetDefaultColor(Color.Plum);
Htarget5.HideTitle();
AddChartBubble(BubbleLoc1, Htarget5, "5th T", color.plum, if c > Htarget5 then no else yes);
# Low Targets
def cond2 = if L < ORL2 and
L[1] >= ORL2
then Round((ORL2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else cond2[1];
plot Ltarget = if bar >= HighestAll(OREndBar)
then highestAll(if isNaN(c[-1])
then cond2
else double.nan)
else double.nan;
Ltarget.SetPaintingStrategy(PaintingStrategy.Squares);
Ltarget.SetLineWeight(1);
Ltarget.SetDefaultColor(Color.White);
Ltarget.HideTitle();
AddChartBubble(BubbleLoc1, cond2, "RO", color.white, if c < Ltarget
then yes
else no);
def condLtarget2 = if c crosses below cond2
then Round((cond2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget2[1];
plot Ltarget2 = if bar >= HighestAll(OREndBar)
then highestAll(if isNaN(c[-1])
then condLtarget2
else double.nan)
else double.nan;
Ltarget2.SetPaintingStrategy(PaintingStrategy.Squares);
Ltarget2.SetLineWeight(1);
Ltarget2.SetDefaultColor(Color.Plum);
Ltarget2.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget2, "2nd T", color.plum, if c < condLtarget2
then yes
else no);
def condLtarget3 = if c crosses below condLtarget2
then Round((condLtarget2 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget3[1];
plot Ltarget3 = if bar >= HighestAll(OREndBar)
then highestAll(if isNaN(c[-1])
then condLtarget3
else double.nan)
else double.nan;
Ltarget3.SetPaintingStrategy(PaintingStrategy.Squares);
Ltarget3.SetLineWeight(1);
Ltarget3.SetDefaultColor(Color.Plum);
Ltarget3.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget3, "3rd T", color.plum, if c < Ltarget3
then yes
else no);
def condLtarget4 = if c crosses condLtarget3
then Round((condLtarget3 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget4[1];
plot Ltarget4 = if bar >= HighestAll(OREndBar)
then highestAll(if isNaN(c[-1])
then condLtarget4
else double.nan)
else double.nan;
Ltarget4.SetPaintingStrategy(PaintingStrategy.Squares);
Ltarget4.SetLineWeight(1);
Ltarget4.SetDefaultColor(Color.Plum);
Ltarget4.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget4, "4th T", color.plum, if c < Ltarget4
then yes
else no);
def condLtarget5 = if c crosses condLtarget4
then Round((condLtarget4 - (AtrTargetMult * ATR)) / TickSize(), 0) * TickSize()
else condLtarget5[1];
plot Ltarget5 = if bar >= HighestAll(OREndBar)
then highestAll(if isNaN(c[-1])
then condLtarget5
else double.nan)
else double.nan;
Ltarget5.SetPaintingStrategy(PaintingStrategy.Squares);
Ltarget5.SetLineWeight(1);
Ltarget5.SetDefaultColor(Color.Plum);
Ltarget5.HideTitle();
AddChartBubble(BubbleLoc1, condLtarget5, "5th T", color.plum, if c < Ltarget5
then yes
else no);
def last = if secondsTillTime(1600) == 0 and
secondsFromTime(1600) == 0
then c[1]
else last[1];
plot LastClose = if Today and last != 0
then last
else Double.NaN;
LastClose.SetPaintingStrategy(PaintingStrategy.Dashes);
LastClose.SetDefaultColor(Color.White);
LastClose.HideBubble();
LastClose.HideTitle();
AddChartBubble(SecondsTillTime(0930) == 0, LastClose, "PC", color.gray, yes);
alert(c crosses above ORH2, "", Alert.Bar, Sound.Bell);
alert(c crosses below ORL2, "", Alert.Bar, Sound.Ring);
# End Code ORB with Risk and targets