-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhistory.pine
More file actions
45 lines (36 loc) · 2.09 KB
/
history.pine
File metadata and controls
45 lines (36 loc) · 2.09 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
//@version=6
indicator(title="Price Change History", shorttitle="Price Chg", precision=2)
// FEATURES
// - Track change over any number of trading sessions.
// - Highlight bars that rise above a certain value.
// - Highlight bars that fall below a certain value.
// - Track the occurrence of highlighted bars.
// Source code on GitHub: https://github.com/chingc/TradingView
// Follow me on X: https://x.com/NeonNoodle22
// User settings
source = input.source(defval=close, title="Source", tooltip="The source for calculations.")
length = input.int(defval=1, title="Trading Sessions", minval=1, tooltip="Number of trading sessions to consider.")
highlightUpper = input.float(defval=5, title="Highlight Above", tooltip="Highlight if change rises above this value.")
highlightLower = input.float(defval=-5, title="Highlight Below", tooltip="Highlight if change falls below this value.")
highlightRange = input.int(defval=50, title="Highlight Range", minval=1, tooltip="Number of trading sessions to consider when calculating the occurrence of highlighted bars.\n\ne.g. If there are 3 highlighted bars within a highlight range of 50, the answer is 0.06.\n\nThis is the orange number on the status line.")
asPercent = input.bool(defval=true, title="As Percentage", tooltip="Show change as percentage or as points.")
// Change dataset
dataset = asPercent ? ta.change(source, length) / source[length] * 100 : ta.change(source, length)
// Return a color depending on the change
paint(change) =>
switch
change > highlightUpper => color.aqua
change < highlightLower => color.fuchsia
change >= 0 => color.green
=> color.red
// Draw the bars
plot(series=dataset, color=paint(dataset), style=plot.style_columns)
// Calculate the occurrence of highlighted bars within the highlight range
orangeNumber(bars) =>
count = 0
for i = 0 to highlightRange - 1
if bars[i] > highlightUpper or bars[i] < highlightLower
count += 1
count / highlightRange
// Display the orange number on the status line
plot(series=orangeNumber(dataset), color=color.orange, display=display.status_line)