-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathStocksMarketsSessions
171 lines (141 loc) · 8.44 KB
/
StocksMarketsSessions
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
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Edward - https://github.com/45609/Scripts/
//@version=5
indicator("Stocks Markets Sessions", "Stocks Markets Sessions", overlay = true, max_bars_back = 5000, max_boxes_count = 500,max_labels_count = 500,max_lines_count = 500)
YourTZ = input.string('UTC+8:00', 'Time Zone',group = 'Basic Setting')
DaysToShow = input.int(2, "Days to Show", minval = 1, group = "Basic Setting")
SessionsGrp = 'Stocks Markets Sessions'
//Session Tokyo
sesTokyo_color = input.color(#0CC1C0, '', inline = 'tokyo', group = SessionsGrp)
show_sesTokyo = input(true, 'Tokyo', inline = 'tokyo', group = SessionsGrp)
rangeTokyo = input.string('1h' , '', options = ['5m', '15m', '30m', '1h', 'Session'], inline='tokyo', group = SessionsGrp)
sesTokyo_text = 'Tokyo ' + rangeTokyo
sesLondon_color = input.color(#ACBBE8, '', inline = 'london', group = SessionsGrp)
show_sesLondon = input(true, 'London', inline = 'london', group = SessionsGrp)
rangeLondon = input.string('Session' , '', options = ['5m', '15m', '30m', '1h', 'Session'], inline='london', group = SessionsGrp)
sesLondon_text = 'London ' + rangeLondon
//Session NewYork
sesNewYork_color = input.color(#C5ACE8, '', inline = 'newyork', group = SessionsGrp)
show_sesNewYork = input(true, 'NewYork', inline = 'newyork', group = SessionsGrp)
rangeNewYork = input.string('Session' , '', options = ['5m', '15m', '30m', '1h', 'Session'], inline='newyork', group = SessionsGrp)
sesNewYork_text = 'New York ' + rangeNewYork
//Info Table
Show_Info_Table = input(true, 'Info Table', group = 'Table')
Size = input.string(size.small , 'Table Text Size' , options = [size.small, size.normal])
Position = input.string(position.top_right, 'Table Position', options = [position.top_left, position.top_center, position.top_right, position.middle_left, position.middle_center, position.middle_right, position.bottom_left, position.bottom_center, position.bottom_right] )
tfMultiplier = timeframe.multiplier
enabledSessions = (show_sesTokyo ? 1 : 0) + (show_sesLondon ? 1 : 0) + (show_sesNewYork ? 1 : 0)
var box[] boxesArray = array.new<box>()
var label[] labelsArray = array.new<label>()
//Session Timing
var string Tokyo = '0900-1500'
var string London = '0800-1630'
var string NewYork = '0930-1600'
// Tokyo Range
var string Tokyo_Range = rangeTokyo == '5m' ? '0900-0905' :
rangeTokyo == '15m' ? '0900-0915' :
rangeTokyo == '30m' ? '0900-0930' :
rangeTokyo == '1h' ? '0900-1000' : Tokyo
// London Range
var string London_Range = rangeLondon == '5m' ? '0800-0805' :
rangeLondon == '15m' ? '0800-0815' :
rangeLondon == '30m' ? '0800-0830' :
rangeLondon == '1h' ? '0800-0900' : London
// New York Range
var string NewYork_Range = rangeNewYork == '5m' ? '0930-0935' :
rangeNewYork == '15m' ? '0930-0945' :
rangeNewYork == '30m' ? '0930-1000' :
rangeNewYork == '1h' ? '0930-1030' : NewYork
TokyoTZ = "Asia/Tokyo"
LondonTZ = "Europe/London"
NewYorkTZ = "America/New_York"
On_sesTokyo = math.sign(nz(time(timeframe.period, Tokyo, TokyoTZ)))
On_sesLondon = math.sign(nz(time(timeframe.period, London, LondonTZ)))
On_sesNewYork = math.sign(nz(time(timeframe.period, NewYork, NewYorkTZ)))
On_rangeTokyo = math.sign(nz(time(timeframe.period, Tokyo_Range, TokyoTZ)))
On_rangeLondon = math.sign(nz(time(timeframe.period, London_Range, LondonTZ)))
On_rangeNewyork = math.sign(nz(time(timeframe.period, NewYork_Range, NewYorkTZ)))
//High & Low Session Detector
LowHighSessionDetector(On_Range, On_Session, Color_Session, Text_Session) =>
var int Bar = 0
var float High = 0.0
var float Low = 0.0
var box BoX = na
var label LabeL = na
if (On_Range[1] == 0 and On_Range == 1)
Bar := bar_index
High := high
Low := low
else if (On_Range[1] == 1 and On_Range == 1)
High := math.max(high , High)
Low := math.min(low , Low)
else if On_Session == 0
High := 0.0
Low := 0.0
Bar := 0
if On_Session > On_Session[1] and str.tonumber(timeframe.period) <= 60
BoX := box.new(bar_index,High, bar_index , Low, bgcolor = color.new(Color_Session, 85), border_color = color.rgb(34, 101, 155), border_style = line.style_dotted)
LabeL := label.new(Bar, High , text = Text_Session ,xloc = xloc.bar_index, yloc = yloc.price, size = size.small, style = label.style_label_down, textcolor = Color_Session, color = color.rgb(255, 255, 255, 100))
array.push(boxesArray, BoX)
array.push(labelsArray, LabeL)
if array.size(boxesArray) > DaysToShow * enabledSessions
box.delete(array.shift(boxesArray))
label.delete(array.shift(labelsArray))
if (On_Range[1] == 1 and On_Range == 1)
box.set_top(BoX, High)
box.set_bottom(BoX, Low)
if On_Session and On_Session == On_Session[1]
// box.set_top(BoX, High)
// box.set_bottom(BoX, Low)
box.set_right(BoX, bar_index)
label.set_x(LabeL,math.round(math.avg(Bar,bar_index)))
label.set_y(LabeL, High)
if show_sesTokyo
LowHighSessionDetector(On_rangeTokyo,On_sesTokyo,sesTokyo_color,sesTokyo_text)
if show_sesLondon
LowHighSessionDetector(On_rangeLondon,On_sesLondon,sesLondon_color,sesLondon_text)
if show_sesNewYork
LowHighSessionDetector(On_rangeNewyork,On_sesNewYork,sesNewYork_color,sesNewYork_text)
//Info Table
// Start and Enf Time in Info Table
SplitFunction(x, TZ ,YourTZ) =>
Text = str.split(x, '-')
STime = Text.size() > 0 ? (Text.get(0)) : '0000'
ETime = Text.size() > 0 ? (Text.get(1)) : '0000'
SHour = str.substring(STime ,0,2)
SMin = str.substring(STime ,2,4)
EHour = str.substring(ETime ,0,2)
EMin = str.substring(ETime ,2,4)
SUTCTimestamp = timestamp(TZ, year, month, dayofmonth, int(str.tonumber(SHour)), int(str.tonumber(SMin)), 0)
EUTCTimestamp = timestamp(TZ, year, month, dayofmonth, int(str.tonumber(EHour)), int(str.tonumber(EMin)), 0)
SconvertedHour = hour(SUTCTimestamp, YourTZ)
SconvertedMinute = minute(SUTCTimestamp, YourTZ)
EconvertedHour = hour(EUTCTimestamp, YourTZ)
EconvertedMinute = minute(EUTCTimestamp, YourTZ)
YourStart = str.tostring(SconvertedHour) + ':' + str.tostring(SconvertedMinute < 10 ? '0' +
str.tostring(SconvertedMinute) : str.tostring(SconvertedMinute))
YourEnd = str.tostring(EconvertedHour) + ':' + str.tostring(EconvertedMinute < 10 ? '0' +
str.tostring(EconvertedMinute) : str.tostring(EconvertedMinute))
Start = YourStart
End = YourEnd
[Start, End]
[Tokyo_Start, Tokyo_End] = SplitFunction(Tokyo, TokyoTZ, YourTZ)
[London_Start, London_End] = SplitFunction(London, LondonTZ, YourTZ)
[NewYork_Start, NewYork_End] = SplitFunction(NewYork, NewYorkTZ, YourTZ)
var Info_Table = table.new(Position, 5, 11, bgcolor = #0d1a3f, border_color = color.rgb(28, 48, 109), border_width = 1,
frame_color = #373a46 , frame_width = 1)
if Show_Info_Table
table.cell(Info_Table, 0, 1, 'Session', text_color = color.white, text_size = Size)
table.cell(Info_Table, 1, 1, 'Start(' + YourTZ + ')', text_color = color.white, text_size = Size)
table.cell(Info_Table, 2, 1, 'End(' + YourTZ + ')', text_color = color.white, text_size = Size)
table.cell(Info_Table, 0, 2, 'Tokyo', text_color = sesTokyo_color, text_size = Size)
table.cell(Info_Table, 0, 3, 'London', text_color = sesLondon_color, text_size = Size)
table.cell(Info_Table, 0, 4, 'NewYork', text_color = sesNewYork_color, text_size = Size)
//Start Time
table.cell(Info_Table, 1, 2, Tokyo_Start , text_color = color.white, text_size = Size)
table.cell(Info_Table, 1, 3, London_Start , text_color = color.white, text_size = Size)
table.cell(Info_Table, 1, 4, NewYork_Start , text_color = color.white, text_size = Size)
//End Time
table.cell(Info_Table, 2, 2, Tokyo_End , text_color = color.white, text_size = Size)
table.cell(Info_Table, 2, 3, London_End , text_color = color.white, text_size = Size)
table.cell(Info_Table, 2, 4, NewYork_End , text_color = color.white, text_size = Size)