-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgold_5min.pine
217 lines (178 loc) · 9.14 KB
/
gold_5min.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//@version=4
study(title="My:Chandelier:Expert Advisor", overlay=true)
// EA ID 5608726102199
///////////////////////////////////////////////
// User Input
///////////////////////////////////////////////
var lastEntry = float(0)
var tp = float(0)
var lastEntryTpReached = false
var lastOrderType = ""
// Auto Configure for 5 min XAUUSD Chandelier
// Metatrader Expert Advisor API Request Data
EAuid = input('5608726102199', title='EA UID', group = "Pine Connector Info", type=input.string)
EAtickerId = input('XAUUSD.a', title='EA Ticker ID', group = "Pine Connector Info", type=input.string)
EAvolume = input(0.1, title='EA Volume', group = "Pine Connector Info", type=input.float)
EAtakeProfit = input(45, title='EA Take Profit Pips', group = "Pine Connector Info", type=input.integer)
EAstopLoss = input(32, title='EA Stop Loss Pips (0 = auto)', group = "Pine Connector Info", type=input.integer)
EAenablePartial = input(false, title='Enable Partial Profit', group = "Pine Connector Info Partial", type=input.bool)
EAvolumePartial = input(0.3, title='EA Volume Partial', group = "Pine Connector Info Partial", type=input.float)
EAtakeProfitPartial = input(20, title='EA Take Partial Profit Pips', group = "Pine Connector Info Partial", type=input.integer)
// Enable or Disable a Signal
weekendSignals = input(false, title='Enable Week End Signals', group = "Signal E/D", type=input.bool)
enableNFP = input(false, title='Enable Signals during NFP Day', group = "Signal E/D", type=input.bool)
enableChandelierSignal = input(true, title='Enable Chandelier Signal', group = "Signal E/D", type=input.bool)
maxMinPriceCancel = input(2, title='Block Chandelier if gap', group = "Signal E/D", type=input.integer)
// Enable / Disable visual plotting on the chart
showChandelier = input(true, title='Display Chandelier', group = "Other", type=input.bool)
///////////////////////////////////////////////
// Manually disable Signals
///////////////////////////////////////////////
isNfpDay = if (dayofweek(time('D')) == 5 and dayofmonth(time('D')) <= 8 and dayofmonth(time('D')) > 1)
true
else
false
isWeekEnd = dayofweek(time('D')) == 6 or dayofweek(time('D')) == 7
forceDisableSignals = if (weekendSignals == false and isWeekEnd)
true
else if (enableNFP == false and isNfpDay)
true
else
false
signalDisabledBackgroundColor = forceDisableSignals ? color.new(color.red, 60) : na
bgcolor(signalDisabledBackgroundColor)
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
// STRATEGY 1 -- Chandelier Strategy
///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
// STRATEGY 1 -- Indicators Configuration
///////////////////////////////////////////////
//
// Bollinger Band Config
//
bollingerBandLength = 20
bollingerBandMultiplier = 2
bollingerBandBasis = sma(close, bollingerBandLength)
//
// Average True Range Config
//
averageTrueRangeLength = 22
averageTrueRangeMultiplier = 4.8 * atr(averageTrueRangeLength)
//
// Support of a bullish momentum. If the price is coming back down to this support, it's likely going to
// trigger a Chandelier Short Signal
//
longStop = highest(close, averageTrueRangeLength) - averageTrueRangeMultiplier
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop
//
// Resistance of a bearish momentum. If the price is coming back up to this resistance, it's likely going to
// trigger a Chandelier Buy Signal
//
shortStop = lowest(close, averageTrueRangeLength) + averageTrueRangeMultiplier
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
//
// Definition of the direction, 1 = bullish / -1 = bearish
//
var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
///////////////////////////////////////////////
// STRATEGY 1 -- Alert Configuration
///////////////////////////////////////////////
//
// We define whether we are on a buy or sell setup
//
maxMinPriceCancelV = if (maxMinPriceCancel == 0)
5000
else
maxMinPriceCancel
triggerChandelierBuy = dir == 1 and dir[1] == -1 and close < shortStop + maxMinPriceCancelV
triggerChandelierSell = dir == -1 and dir[1] == 1 and close > longStop - maxMinPriceCancelV
/////////////////////////////////////////////////////////////
// STRATEGY 1 -- Indicators Plot on the Chart - VISUAL ONLY
/////////////////////////////////////////////////////////////
longPlot = plot(showChandelier and dir == 1 ? longStop : na, display=display.none, editable=false)
shortPlot = plot(showChandelier and dir == -1 ? shortStop : na, display=display.none, editable=false)
midPricePlot = plot(showChandelier ? ohlc4 : na, display=display.none, editable=false)
fill(midPricePlot, longPlot, color=color.new(color.green, 90))
fill(midPricePlot, shortPlot, color=color.new(color.red, 90))
plot(bollingerBandBasis, "Basis", color=color.new(#FF6D00, 90))
///////////////////////////////////////////////
// STRATEGY 1 -- Chandelier Strategy - END //
///////////////////////////////////////////////
allowOrder = enableChandelierSignal and forceDisableSignals == false
orderType = if (triggerChandelierBuy)
'buy'
else if (triggerChandelierSell)
'sell'
else
'buy/sell'
alertMessage = 'GOLD / ' + tostring(orderType) + ' / ' + tostring(close, '#.##') + ' / ' + 'TP=' + tostring(tp, '#.##')
// baseMessage = tostring(EAuid) + ',' + tostring(orderType) + ',' + tostring(EAtickerId) + ',' + 'sl=' + tostring(EAstopLoss) + ','
// baseMessage_partial = baseMessage + 'tp=' + tostring(EAtakeProfitPartial) + ',risk=' + tostring(EAvolumePartial)
// baseMessage_full = baseMessage + 'tp=' + tostring(EAtakeProfit) + ',risk=' + tostring(EAvolume) + ',betrigger=' + tostring(EAtakeProfitPartial) + ',beoffset=5'
if (triggerChandelierBuy or triggerChandelierSell)
lastEntryTpReached := false
lastEntry := close
if (triggerChandelierBuy)
lastOrderType := "buy"
tp := close + 1
else if (triggerChandelierSell)
lastOrderType := "sell"
tp := close - 1
alert(alertMessage, alert.freq_once_per_bar_close)
// if (EAenablePartial)
// alert(tostring(baseMessage_partial), alert.freq_once_per_bar_close)
// alert(tostring(baseMessage_full), alert.freq_once_per_bar_close)
if (lastOrderType == "buy" and high >= tp)
lastEntryTpReached := true
else if (lastOrderType == "sell" and low <= tp)
lastEntryTpReached := true
var table panel = table.new("bottom_right", 10, 20, border_width = 1)
table.cell(panel, 0, 0, "current entry : " + tostring(lastOrderType), bgcolor = color.teal, text_color=color.white, text_size=size.auto)
table.cell(panel, 1, 0, "Pips from entry", bgcolor = color.teal, text_color=color.white, text_size=size.auto)
table.cell(panel, 2, 0, "Exit price (green reached)", bgcolor = color.teal, text_color=color.white, text_size=size.auto)
table.cell(panel, 0, 1, tostring(lastEntry), bgcolor = color.white, text_size=size.auto)
PL = if (showChandelier and dir == 1)
(close - lastEntry) * 10
else if (showChandelier and dir == -1)
(lastEntry - close) * 10
PL_color = if (lastEntryTpReached)
color.blue
else if(PL > 0)
color.green
else if(PL < 0)
color.red
else
color.orange
pipsCell = if(lastEntryTpReached)
"Waiting Next Entry"
else
tostring(PL, "#.##") + " pips"
table.cell(panel, 1, 1, tostring(pipsCell), bgcolor = PL_color, text_color=color.white, text_size=size.auto)
tpReachedColor = if (lastEntryTpReached)
color.green
else
color.orange
table.cell(panel, 2, 1, 'TP=' + tostring(tp, "#.##"), bgcolor = tpReachedColor, text_color=color.white, text_size=size.auto)
nextEntryOrderType = if (lastOrderType == "buy")
"sell"
else
"buy"
table.cell(panel, 0, 3, "Next Entry : " + tostring(nextEntryOrderType), bgcolor = color.teal, text_color=color.white, text_size=size.auto)
table.cell(panel, 1, 3, "-", bgcolor = color.black, text_color=color.black, text_size=size.auto)
table.cell(panel, 2, 3, "Next Entry TP", bgcolor = color.teal, text_color=color.white, text_size=size.auto)
nextEntryPrice = if (lastOrderType == "buy")
longStop - maxMinPriceCancelV
else
shortStop + maxMinPriceCancelV
nextEntryTp = if (nextEntryOrderType == "buy")
nextEntryPrice + 1
else
nextEntryPrice - 1
table.cell(panel, 0, 4, tostring(nextEntryPrice, '#.##'), bgcolor = color.white, text_size=size.auto)
table.cell(panel, 1, 4, "-", bgcolor = color.black, text_size=size.auto)
table.cell(panel, 2, 4, tostring(nextEntryTp, '#.##'), bgcolor = color.white, text_size=size.auto)