-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsyntax_test.pine
164 lines (142 loc) · 8.2 KB
/
syntax_test.pine
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
// SYNTAX TEST "Packages/Pine/Pine.sublime-syntax"
// x
// ^^^^ comment
study("Ichimoku", overlay=true, precision=8)
// ^ support.function
// ^^^^^^^^^^ string.quoted.double
// ^^^^^^^ variable.parameter
// ^ keyword.operator.assignment
// ^^^^ constant.language
// ^^^^^^^^^ variable.parameter
// ^ keyword.operator.assignment
// ^ constant.numeric
// Tenkan Sen Turning Line (highest high + lowest low)/2 for the last 9 periods
// Kijun Sen Standard Line (highest high + lowest low)/2 for the past 26 periods
// Chikou Span Lagging Line current closing price time-shifted backwards (into the past) 26 periods
// Senkou Span A 1st Leading Line (tenkan sen + kijun sen)/2 time-shifted forwards (into the future) 26 periods
// Senkou Span B 2nd Leading Line (highest high + lowest low)/2 for 52 periods time-shifted forwards (into the future) 26 periods
// Options
tenkan_sen_periods = input(9, minval=1, title="Tenkan Sen Periods (Turning Line)")
// ^^^^^^^^^^^^^^^ variable
// ^ keyword.operator.assignment
// ^^^^^ support.function
// ^ constant.numeric
// ^^^^^^ variable.parameter
// ^ keyword.operator.assignment
// ^ constant.numeric
// ^^^^^ variable.parameter
// ^ keyword.operator.assignment
// ^^^ string
kijun_sen_periods = input(26, minval=1, title="Kijun Sen Periods (Standard Line)")
senkou_span_b_periods = input(52, minval=1, title="Senkou Span B Periods (2nd Leading Line)")
displacement_periods = input(26, minval=1, title="Displacement Periods (Time Shift)")
// Functions
// Donchian Channel
// highest high and the lowest low of the last n periods
// https://en.wikipedia.org/wiki/Donchian_channel
donchian(len) => avg(lowest(len), highest(len))
// ^^^^^ support.function
// ^^ keyword.operator
// ^^^ support.function
// ^^^^^^ support.function
// ^^^^^^^ support.function
// Calculations
tenkan_sen = donchian(tenkan_sen_periods)
// ^ variable.parameter
// ^ keyword.operator.assignment
// ^ support.function
kijun_sen = donchian(kijun_sen_periods)
senkou_span_a = avg(tenkan_sen, kijun_sen)
senkou_span_b = donchian(senkou_span_b_periods)
study('Ichimoku')
// ^^^^^^^^^^ string.quoted.single
// Plot Tenkan Sen
plot(tenkan_sen, title="Tenkan Sen (Turning Line)", color=#00FF00, transp=0)
// ^^^^^ variable.parameter
// ^ keyword.operator.assignment
// ^^^^^^^ support.constant
// Kijun Sen
plot(kijun_sen, title="Kijun Sen (Standard Line)", color=#FF0000, transp=0)
// Chikou Span
plot(close, offset = -displacement_periods, title="Chikou Span (Lagging Line)", color=#FF00FF, transp=0)
// ^^^^^ constant.language
// Plot Senkou Span A
senkou_span_a_plot = plot(senkou_span_a, offset=displacement_periods, color=#FFFFFF, title="Senkou Span A (1st Leading Line)", transp=0)
// Plot Senkou Span B
senkou_span_b_plot = plot(senkou_span_b, offset=displacement_periods, color=#FFFF00, title="Senkou Span B (2nd Leading Line)", transp=0)
// Plot Bullish Kumo colour (if bullish)
is_bullish_kumo = senkou_span_a >= senkou_span_b
// ^^ keyword.operator.comparison
bullish_kumo_senkou_span_a = plot(is_bullish_kumo ? senkou_span_a : na, editable=false, transp=100, style=areabr, offset=displacement_periods, color=#FFFFFF)
// ^ keyword.operator.ternary
// ^ keyword.operator
// ^^ constant.language
// ^ keyword.operator.assignment
// ^^^^^ constant.language
// ^ keyword.operator.assignment
// ^^^ constant.numeric
bullish_kumo_senkou_span_b = plot(is_bullish_kumo ? senkou_span_b : na, editable=false, transp=100, style=areabr, offset=displacement_periods, color=#FFFF00)
fill(bullish_kumo_senkou_span_a, bullish_kumo_senkou_span_b, color=#FFFF00, transp=70, title="Bullish Kumo (Cloud)")
// ^ support.function
// Plot Bearish Kumo colour (if bearish)
is_bearish_kumo = senkou_span_a <= senkou_span_b
bearish_kumo_senkou_span_a = plot(is_bearish_kumo ? senkou_span_a : na, editable=false, transp=100, style=areabr, offset=displacement_periods, color=#FFFFFF)
bearish_kumo_senkou_span_b = plot(is_bearish_kumo ? senkou_span_b : na, editable=false, transp=100, style=areabr, offset=displacement_periods, color=#FFFF00)
fill(bearish_kumo_senkou_span_b, bearish_kumo_senkou_span_a, color=#FF0000, transp=70, title="Bearish Kumo (Cloud)")
is_day_equal_to(day) => dayofweek == day and close ? 1 : 0
// ^^^^^^^^^^^^ support.function
// ^^ keyword.operator
// ^^^^^^^^^ constant.language
// ^^ keyword.operator.comparison
// ^^^ keyword.operator.logical
// ^^^^^ constant.language
// ^ keyword.operator.ternary
// ^ constant.numeric
// ^ keyword.operator
// ^ constant.numeric
is_mon = is_day_equal_to(dayofweek.monday)
// ^ variable
// ^ keyword.operator.assignment
// ^^^^^^^^^ constant.language
is_tue = is_day_equal_to(dayofweek.tuesday)
// ^^^^^^^^^ constant.language
is_wed = is_day_equal_to(dayofweek.wednesday)
// ^^^^^^^^^ constant.language
is_thu = is_day_equal_to(dayofweek.thursday)
// ^^^^^^^^^ constant.language
is_fri = is_day_equal_to(dayofweek.friday)
// ^^^^^^^^^ constant.language
is_sat = is_day_equal_to(dayofweek.saturday)
// ^^^^^^^^^ constant.language
is_sun = is_day_equal_to(dayofweek.sunday)
// ^^^^^^^^^ constant.language
plotchar(display_mon, char="M", color=color.white, location=location.bottom)
// ^ support.function
// ^^^^^^^^^^^ constant.language
// ^^^^^^^^^^^^^^^ constant.language
m_kijun_sen = security(tickerid, "1M", avg(lowest(26), highest(26)))
// ^^^^^^^^ support.function
// ^^^ support.function
// ^^^^^^ support.function
// ^^ constant.numeric
// ^^^^^^^ support.function
// ^^ constant.numeric
is_pivot_low = low[5] < low[6] and low[5] < low[7] and low[5] < low[8] and low[5] < low[9] and low[5] < low[4] and low[5] < low[3] and low[5] < low[2] and low[5] < low[1]
// ^^^ constant.language
// ^ -constant
// ^ constant.numeric
// ^ -constant
fast = 12, slow = 26
fastMA = ema(close, fast)
// ^^^ support.function
// ^^^^^ constant.language
slowMA = ema(close, slow)
macd = fastMA - slowMA
signal = sma(macd, 9)
plot(macd, color=color.blue)
// ^^^^^^^^^^ constant.language
plot(signal, color=color.orange)
// ^^^^^^^^^^^^ constant.language
// https://github.com/gerardroche/sublime-pine/issues/9
backtest_safety = bb_bands_diff
// ^^^^ -keyword