-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevels.tosts
More file actions
195 lines (158 loc) · 7.45 KB
/
levels.tosts
File metadata and controls
195 lines (158 loc) · 7.45 KB
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
# levels.tosts
# Modified by: Rishi Dhupar
# Create levels on charts
# Previous Day High/Low/Close + Premarket High/Low + High/Low/Open of Day
# Created by Wiinii
# V1.6
# Some code based on code by Mobius (premarket) and TraderKevin (ATR lines
# https://usethinkscript.com/threads/previous-day-high-low-close-premarket-high-low-high-low-open-of-day-for-thinkorswim.13139/
declare hide_on_daily;
input length = 1;
input showOnlyLastPeriod = yes;
input ShowBubbles = yes;
input locate_bubbles_at = {default Expansion, Time};
input locate_bubbles_at_time = 800;
input BarsFromExpansion = 1;
input ShowPricesInBubbles = yes;
def bn = BarNumber();
def na = Double.NaN;
def h = high;
def l = low;
def o = open;
def c = close;
def v = volume;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;
def isExpansion = locate_bubbles_at == locate_bubbles_at.Expansion and IsNaN(close);
def firstExpansionBar = if !IsNaN(close[-1]) and isExpansion then 1
else if isExpansion then firstExpansionBar[1] + 1 else 0;
def BubbleLocation = if locate_bubbles_at == locate_bubbles_at.Time then timeopen
else isExpansion and firstExpansionBar == BarsFromExpansion;
def Intraday = if GetAggregationPeriod() < 86400000 then 1
else 0;
def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and getTime() <= RegularTradingEnd(getYYYYMMDD());
#----- Previous Day High/Low/Close -----#
plot PD_High;
plot PD_Low;
plot PD_Close;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
PD_High = na;
PD_Low = na;
PD_Close = na;
} else {
PD_High = Highest(high(period = aggregationPeriod)[-displace], length);
PD_Low = Lowest(low(period = aggregationPeriod)[-displace], length);
PD_Close = close(period = aggregationPeriod)[-displace];
}
PD_High.SetDefaultColor(Color.DARK_ORANGE);
PD_High.SetStyle(Curve.LONG_DASH);
PD_High.SetLineWeight(2);
PD_High.HideTitle();
PD_Low.SetDefaultColor(Color.DARK_ORANGE);
PD_Low.SetStyle(Curve.LONG_DASH);
PD_Low.SetLineWeight(2);
PD_Low.HideTitle();
PD_Close.SetDefaultColor(Color.WHITE);
PD_Close.SetStyle(Curve.LONG_DASH);
PD_Close.SetLineWeight(2);
PD_Close.HideTitle();
DefineGlobalColor("PD_High", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_High, "PDH: " + (if ShowPricesInBubbles then AsText(PD_High) else ""), GlobalColor("PD_High"));
DefineGlobalColor("PD_Low", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_Low, "PDL: " + (if ShowPricesInBubbles then AsText(PD_Low) else ""), GlobalColor("PD_Low"), no);
DefineGlobalColor("PD_Close", Color.WHITE);
AddChartBubble(ShowBubbles and BubbleLocation, PD_Close, "PDC: " + (if ShowPricesInBubbles then AsText(PD_Close) else ""), GlobalColor("PD_Close"));
PD_High.HideBubble();
PD_Low.HideBubble();
PD_Close.HideBubble();
#----- Premarket High/Low -----
# Credit: Mobius
# Overnight High (ONhigh):
# - Initializes at the high price when transitioning from RTH to non-RTH hours
# - Continuously updates to new highs during non-RTH hours
# - Retains previous overnight high value until updated or RTH resumes (no explicit reset)
def ONhigh = if !RTH and RTH[1] then h
else if !RTH and h > ONhigh[1] then h
else ONhigh[1];
# Identify the Bar Number of the Overnight High (ONhighBar)
# This variable records the bar number where the Overnight High (ONhigh) occurred.
# It checks if the current bar is outside regular trading hours and if the current high equals ONhigh.
# If both conditions are true, it assigns the current bar number to ONhighBar.
# If not, it retains the previous value of ONhighBar.
def ONhighBar = if !RTH and h == ONhigh then bn
else ONhighBar[1];
# Overnight Low (ONlow):
# - Initializes at the low price when transitioning from RTH to non-RTH hours
# - Continuously updates to new lows during non-RTH hours
# - Resets to NaN (Not a Number) when RTH resumes, discarding previous overnight low
# - Intended for tracking price movements and identifying potential support levels outside regular trading hours
def ONlow = if !RTH and RTH[1] then l
else if RTH then Double.NaN
else if !RTH and l < ONlow[1] then l
else ONlow[1];
def ONlowBar = if !RTH and l == ONlow then bn
else ONlowBar[1];
# Returns the most recent overnight high price,
# updated when a new overnight high is detected
def OverNightHigh = if bn == HighestAll(ONhighBar) then ONhigh
else OverNightHigh[1];
# Returns the most recent overnight low price,
# updated when a new overnight low is detected
def OverNightLow = if bn == HighestAll(ONlowBar) then ONlow
else OverNightLow[1];
plot PM_High;
plot PM_Low;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
PM_High = na;
PM_Low = na;
} else {
PM_High = if OverNightHigh > 0 then OverNightHigh else na;
PM_Low = if OverNightLow > 0 then OverNightLow else na;
}
#PM_High.SetHiding(!PlotOverNightExtremes);
PM_High.SetLineWeight(2);
PM_High.SetDefaultColor(Color.CYAN);
PM_High.SetStyle(Curve.LONG_DASH);
PM_High.HideBubble();
PM_High.HideTitle();
#PM_Low.SetHiding(!PlotOverNightExtremes);
PM_Low.SetStyle(Curve.LONG_DASH);
PM_Low.SetDefaultColor(Color.CYAN);
PM_Low.HideBubble();
PM_Low.HideTitle();
DefineGlobalColor("PM_High", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONhighBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_High, "PMH: " + (if ShowPricesInBubbles then AsText(PM_High) else ""), GlobalColor("PM_High"));
DefineGlobalColor("PM_Low", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_Low, "PML: " + (if ShowPricesInBubbles then AsText(PM_Low) else ""), GlobalColor("PM_Low"), no);
#----- Today Open/High/Low -----#
plot High_of_Day;
plot Low_of_Day;
plot DayOpen;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DayOpen = na;
High_of_Day = na;
Low_of_Day = na;
} else {
DayOpen = open(period = aggregationPeriod)[0];
High_of_Day = Highest(high(period = aggregationPeriod), length);
Low_of_Day = Lowest(low(period = aggregationPeriod), length);
}
DayOpen.SetDefaultColor(Color.GRAY);
DayOpen.SetPaintingStrategy(PaintingStrategy.DASHES);
DayOpen.SetLineWeight(2);
DayOpen.HideTitle();
High_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
High_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
High_of_Day.SetLineWeight(2);
High_of_Day.HideTitle();
Low_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
Low_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Low_of_Day.SetLineWeight(2);
Low_of_Day.HideTitle();
DefineGlobalColor("Open", Color.LIGHT_GRAY);
AddChartBubble(ShowBubbles and BubbleLocation, DayOpen, "Open: " + (if ShowPricesInBubbles then AsText(DayOpen) else ""), GlobalColor("Open"));
DefineGlobalColor("High_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, High_of_Day, "HOD: " + (if ShowPricesInBubbles then AsText(High_of_Day) else ""), GlobalColor("High_of_Day"));
DefineGlobalColor("Low_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, Low_of_Day, "LOD: " + (if ShowPricesInBubbles then AsText(Low_of_Day) else ""), GlobalColor("Low_of_Day"), no);