-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSF-Awesome-Oscillator-Indicator-User-Inputs-lightBackground.txt
175 lines (147 loc) · 8.62 KB
/
SF-Awesome-Oscillator-Indicator-User-Inputs-lightBackground.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
//@version=5
// Overlay=false makes the indicator labels nicer (doesn't include the script name with the MA / EMA label)
// The MAs may be in their own panel (like RSI and Stoch) just drag them (left-click) from their panel to the
// actual chart, then click "3dots", "Pin to scale", "Pinned to right side" to merge the scales into one
indicator(title="Peanuts", shorttitle="Peanuts", overlay=false, timeframe="", timeframe_gaps=true)
color_style_select = input.string(defval="K", title="K, P or M", options=["K", "P", "M"], group="Use K-col, P-col or M-col")
k_col_selected = color_style_select == "K" ? true : false
p_col_selected = color_style_select == "P" ? true : false
m_col_selected = color_style_select == "M" ? true : false
if (k_col_selected and p_col_selected and m_col_selected)
runtime.error("No matching MA type found.")
line_or_step_select(type) =>
switch type
1 => plot.style_line
0 => plot.style_stepline
// ma 20
ma20Source = input(defval = close)
ma20Length = input.int(defval = 20, minval = 1)
// ma 200
ma200Source = input(defval = close)
ma200Length = input.int(defval = 200, minval = 1)
// ma 100
ma100Source = input(defval = close)
ma100Length = input.int(defval = 100, minval = 1)
// ma 300
ma300Source = input(defval = close)
ma300Length = input.int(defval = 300, minval = 1)
//ema 21
ema21Source = input(defval = close)
ema21Length = input.int(defval = 21, minval = 1)
//ema 25
ema25Source = input(defval = close)
ema25Length = input.int(defval = 25, minval = 1)
//ema 32
ema32Source = input(defval = close)
ema32Length = input.int(defval = 32, minval = 1)
//ema 34
ema34Source = input(defval = close)
ema34Length = input.int(defval = 34, minval = 1)
// ema200 - actually SMMA99
ema200Source = input(defval = close)
ema200Length = input.int(defval = 99, minval=1)
// ema 13
ema13Source = input(defval = close)
ema13Length = input.int(13, minval=1)
//Declare EMA
ma20 = ta.sma(ema200Source, ma20Length)
ma100 = ta.sma(ma100Source, ma100Length)
ma300 = ta.sma(ma300Source, ma300Length)
ma200 = ta.sma(ma200Source, ma200Length)
ema13 = ta.ema(ema13Source, ema13Length)
ema21 = ta.ema(ema21Source, ema21Length)
ema25 = ta.ema(ema25Source, ema25Length)
ema32 = ta.ema(ema32Source, ema32Length)
ema34 = ta.ema(ema34Source, ema34Length)
EMA200() =>
ema200 = 0.0
ema200 := na(ema200[1]) ? ta.sma(ema200Source, ema200Length) : (ema200[1] * (ema200Length - 1) + ema200Source) / ema200Length
// getting different timeframe MA/EMAs that can use the "timeframe gaps" checkbox (from indicator function)
BackgroundData(symbol, timeframe, data) =>
isLive = barstate.isrealtime
request.security(symbol, timeframe, data[isLive ? 1 : 0])[isLive ? 0 : 1]
// plot h4ema200-everywhere (H4-ema200 on all timeframes)
h4ema200 = 0.0
h4ema200 := BackgroundData(syminfo.tickerid,"240", EMA200())
// don't plot h4ema200-everywhere on H4 chart
currentChartTimeframe = timeframe.period
h4ema200plot = currentChartTimeframe=="240" ? false : true
// K colours
h4ema200Col_k = color.new(color.blue, 0)
ma300Col_k = color.new(#ab47bc, 0)
ma200Col_k = color.new(color.orange, 0)
ema200Col_k = color.new(#ff0000, 0)
ma100Col_k = color.new(#2962ff, 0)
ema13Col_k = color.new(#1eb025, 0)
ema21Col_k = color.new(#1eb025, 0)
ema25Col_k = color.new(#1eb025, 0)
ema32Col_k = color.new(#1eb025, 0)
ema34Col_k = color.new(#1eb025, 0)
// P colours
h4ema200Col_p = color.new(color.orange, 0)
ma300Col_p = color.new(#ab47bb, 0)
ma200Col_p = color.new(#0044ff, 0)
ema200Col_p = color.new(#434651, 0)
ma100Col_p = color.new(#1eb024, 0)
ema13Col_p = color.new(#1848cc, 0)
ema21Col_p = color.new(#1848cc, 0)
ema25Col_p = color.new(#1848cc, 0)
ema32Col_p = color.new(#f23645, 0)
ema34Col_p = color.new(#f23645, 0)
// M colors
// K colours
h4ema200Col_m = color.new(color.blue, 0)
ma300Col_m = color.new(#ab47bc, 0)
ma200Col_m = color.new(color.orange, 0)
ema200Col_m = color.new(#5d606b, 0)
ma100Col_m = color.new(#2962ff, 0)
ema13Col_m = color.new(color.black, 0)
ema21Col_m = color.new(#1eb025, 0)
ema25Col_m = color.new(#1eb025, 0)
ema32Col_m = color.new(#1eb025, 0)
ema34Col_m = color.new(#1eb025, 0)
// Plot K lines
plot(na, title="---------- K ----------", color=color.red)
plot(h4ema200plot and (k_col_selected==true) ? h4ema200 : na, title="4hEMA200", color=h4ema200Col_k, linewidth=2)
p300maK=plot((k_col_selected==true) ? ma300 : na, title="MA300", color=ma300Col_k, linewidth=1, style=plot.style_circles)
plot((k_col_selected==true) ? ma200 : na, title="MA200", color=ma200Col_k, linewidth=2, display=display.none)
plot((k_col_selected==true) ? EMA200() : na, title="EMA200", color=ema200Col_k, linewidth=2, style=plot.style_line)
p100maK=plot((k_col_selected==true) ? ma100 : na, title="MA100", color=ma100Col_k, linewidth=1, style=plot.style_circles)
plot((k_col_selected==true) ? ema13 : na, title="EMA13", color=ema13Col_k, linewidth=1)
// switch between displaying the default fast EMAs of K & P
plot((k_col_selected==true) ? ema21 : na, title="EMA21", color=ema21Col_k, linewidth=1, style=plot.style_stepline)
plot((k_col_selected==true) ? ema25 : na, title="EMA25", color=ema25Col_k, linewidth=1, style=plot.style_stepline, display=display.none)
plot((k_col_selected==true) ? ema32 : na, title="EMA32", color=ema32Col_k, linewidth=1, style=plot.style_cross, display=display.none)
plot((k_col_selected==true) ? ema34 : na, title="EMA34", color=ema34Col_k, linewidth=1, style=plot.style_cross, display=display.none)
// Plot P lines
plot(na, title="---------- P ----------", color=color.blue)
plot(h4ema200plot and (p_col_selected==true) ? h4ema200 : na, title="4hEMA200", color=h4ema200Col_p, linewidth=2, display=display.none)
p300maP=plot((p_col_selected==true) ? ma300 : na, title="MA300", color=ma300Col_p, linewidth=1, style=plot.style_circles, display=display.none)
plot((p_col_selected==true)? ma200 : na, title="MA200", color=ma200Col_p, linewidth=2, display=display.none)
plot((p_col_selected==true) ? EMA200() : na, title="EMA200", color=ema200Col_p, linewidth=2, style=plot.style_stepline)
p100maP=plot((p_col_selected==true) ? ma100 : na, title="MA100", color=ma100Col_p, linewidth=1, style=plot.style_circles)
plot((p_col_selected==true) ? ema13 : na, title="EMA13", color=ema13Col_p, linewidth=1)
plot((p_col_selected==true) ? ema21 : na, title="EMA21", color=ema21Col_p, linewidth=1, style=plot.style_stepline, display=display.none)
plot((p_col_selected==true) ? ema25 : na, title="EMA25", color=ema25Col_p, linewidth=1, style=plot.style_stepline)
plot((p_col_selected==true) ? ema32 : na, title="EMA32", color=ema32Col_p, linewidth=1, style=plot.style_cross)
plot((p_col_selected==true) ? ema34 : na, title="EMA34", color=ema34Col_p, linewidth=1, style=plot.style_cross, display=display.none)
// Plot M lines
plot(na, title="---------- M ----------", color=color.red)
plot(h4ema200plot and (m_col_selected==true) ? h4ema200 : na, title="4hEMA200", color=h4ema200Col_m, linewidth=2)
p300maM=plot((m_col_selected==true) ? ma300 : na, title="MA300", color=ma300Col_m, linewidth=1, style=plot.style_circles, display=display.none)
plot((m_col_selected==true) ? ma200 : na, title="MA200", color=ma200Col_m, linewidth=2, display=display.none)
plot((m_col_selected==true) ? EMA200() : na, title="EMA200", color=ema200Col_m, linewidth=2, style=plot.style_line)
p100maM=plot((m_col_selected==true) ? ma100 : na, title="MA100", color=ma100Col_m, linewidth=1, style=plot.style_circles, display=display.none)
plot((m_col_selected==true) ? ema13 : na, title="EMA13", color=ema13Col_m, linewidth=1)
// switch between displaying the default fast EMAs of K & P
plot((m_col_selected==true) ? ema21 : na, title="EMA21", color=ema21Col_m, linewidth=1, style=plot.style_stepline, display=display.none)
plot((m_col_selected==true) ? ema25 : na, title="EMA25", color=ema25Col_m, linewidth=1, style=plot.style_stepline, display=display.none)
plot((m_col_selected==true) ? ema32 : na, title="EMA32", color=ema32Col_m, linewidth=1, style=plot.style_cross, display=display.none)
plot((m_col_selected==true) ? ema34 : na, title="EMA34", color=ema34Col_m, linewidth=1, style=plot.style_cross, display=display.none)
// fill macro MAs (Ichi cloud!)
fillColorSelectK = (ma100 > ma300) ? color.new(color.lime, 75) : color.new(color.red, 75)
fillColorSelectP = (ma100 > ma300) ? color.new(color.lime, 75) : color.new(color.red, 75)
fillColorSelectM = (ma100 > ma300) ? color.new(#a4dfe6, 75) : color.new(#c2c5cd, 75)
fill(p100maK, p300maK, color=k_col_selected ? fillColorSelectK : na, title="K", display=display.none)
fill(p100maP, p300maP, color=k_col_selected ? fillColorSelectP : na, title="P", display=display.none)
fill(p100maM, p300maM, color=m_col_selected ? fillColorSelectM : na, title="M")