-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathno_repait_futres-v1.0.txt
429 lines (278 loc) · 17.1 KB
/
no_repait_futres-v1.0.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © binancash
//@version=5
strategy("Futures - New Script", overlay=true, pyramiding=1, default_qty_type = strategy.fixed, default_qty_value = 200 )
stopPer = input(10, title='Stop Loss %') / 100
takePer = input(10, title='Take Profit %') / 100
longStop = strategy.position_avg_price * (1 - stopPer)
shortStop = strategy.position_avg_price * (1 + stopPer)
shortTake = strategy.position_avg_price * (1 - takePer)
longTake = strategy.position_avg_price * (1 + takePer)
low1d = request.security(symbol=syminfo.tickerid, timeframe="60", expression=low, lookahead=barmerge.lookahead_on)
//vwap start
point_lb = 5
point_rb = 5
//plot(close)
oh = math.max(open[5], open[4], open[3], open[2], open[1], open)
ol = math.min(open[4], open[3], open[2], open[1], open)
point_ph = ta.pivothigh(oh, point_lb, point_rb)
point_pl = ta.pivotlow(ol, point_lb, point_rb)
var float running_ph = na
var float running_pl = na
running_ph := running_ph
running_pl := running_pl
if point_ph
running_ph := point_ph
if point_pl
running_pl := point_pl
plot(running_ph, title = 'R', style = plot.style_circles, linewidth = 1,color=color.red, offset = -point_rb)
plot(running_ph, title = 'R', style = plot.style_circles, linewidth = 1,color=color.red, offset = 0)
plot(running_pl, title = 'S', style = plot.style_circles, linewidth = 1,color=color.blue,offset = -point_rb)
plot(running_pl, title = 'S', style = plot.style_circles, linewidth = 1,color=color.blue, offset = 0)
avg_change = (math.abs(open[10] - open[9]) + math.abs(open[9] - open[8]) + math.abs(open[8] - open[7]) + math.abs(open[7] - open[6]) + math.abs(open[6] - open[5]) + math.abs(open[5] - open[4]) + math.abs(open[4] - open[3]) + math.abs(open[3] - open[2]) + math.abs(open[2] - open[1]) + math.abs(open[1] - open[0]))/10
avg = (open[10] + open[9] + open[8] + open[7] + open[6] + open[5] + open[4] + open[3] + open[2] + open[1])/10
o_h = math.max(open[3], open[2], open[1])
o_l = math.min(open[3], open[2], open[1])
o_o = open[1]
o_c = open
src(_src) =>
Close = (o_h + o_l + o_o + o_c)/4
Open = (o_o + o_c) / 2
High = math.max(o_h, math.max(Open, Close))
Low = math.min(o_l, math.min(Open, Close))
HL2 = math.avg(High, Low)
HLC3 = math.avg(High, Low, Close)
OHLC4 = math.avg(Open, High, Low, Close)
Price = _src == 'close' ? Close : _src == 'open' ? Open : _src == 'high' ? High : _src == 'low' ? Low : _src == 'hl2' ? HL2 : _src == 'hlc3' ? HLC3 : OHLC4
Source = math.round(Price / syminfo.mintick) * syminfo.mintick // PineCoders method for aligning Pine prices with chart instrument prices
// === PLOTTING ===
bar_up = src('close') < src('open')
//plotcandle(src('open'), src('high'), src('low'), src('close'), title = "", color = barColor, wickcolor = barColor, bordercolor = barColor) // plot bars
//plotbar(open[1], o_h, o_l, open)
//plot(avg, color=color.rgb(39, 0, 212), linewidth=4)
//////////////////////////////////
open3m = request.security(symbol=syminfo.tickerid, timeframe="3", expression=open, lookahead=barmerge.lookahead_on)
open5m = request.security(symbol=syminfo.tickerid, timeframe="5", expression=open, lookahead=barmerge.lookahead_on)
open8m = request.security(symbol=syminfo.tickerid, timeframe="8", expression=open, lookahead=barmerge.lookahead_on)
open10m = request.security(symbol=syminfo.tickerid, timeframe="10", expression=open, lookahead=barmerge.lookahead_on)
avg_3m_8 = (open3m[7] + open3m[6] + open3m[5] + open3m[4] + open3m[3] + open3m[2] + open3m[1] + open3m)/8
avg_3m = (open3m[2] + open3m[1] + open3m)/3
//avg_5m = (open5m[10] + open5m[9] + open5m[8] + open5m[7] + open5m[6] + open5m[5] + open5m[4] + open5m[3] + open5m[2] + open5m[1]+ open3m)/10
avg_5m = (open5m[4] + open5m[3] + open5m[2] + open5m[1]+ open3m)/5
//avg_8m = (open8m[10] + open8m[9] + open8m[8] + open8m[7] + open8m[6] + open8m[5] + open8m[4] + open8m[3] + open8m[2] + open8m[1]+ open3m)/10
avg_8m = (open8m[7] + open8m[6] + open8m[5] + open8m[4] + open8m[3] + open8m[2] + open8m[1]+ open3m)/8
//avg_10m = (open10m[10] + open10m[9] + open10m[8] + open10m[7] + open10m[6] + open10m[5] + open10m[4] + open10m[3] + open10m[2] + open10m[1]+ open3m)/10
avg_10m = (open10m[9] + open10m[8] + open10m[7] + open10m[6] + open10m[5] + open10m[4] + open10m[3] + open10m[2] + open10m[1]+ open3m)/10
wma_3m_3 = ta.wma(avg_3m, 3)
plot(wma_3m_3, color = color.blue)
wma_3m_8 = ta.wma(avg_3m_8, 8)
plot(wma_3m_8, color = color.red)
wma_5m_5 = ta.wma(avg_3m, 11)
plot(wma_5m_5, color = color.yellow)
wma_8m_8 = ta.wma(avg_8m, 21)
plot(wma_8m_8, color = color.white)
wma_10m_10 = ta.wma(avg_10m, 48)
plot(wma_10m_10, color = color.gray)
rsi = ta.rsi(avg, 5)
bottomsupport = running_pl and avg > running_pl and avg > avg[1] and rsi > rsi[1] + 8
plotshape(bottomsupport ? low : na, title="Logic1", style=shape.diamond, location=location.absolute, color=color.yellow, size=size.normal)
bigdrop = rsi + 8 < rsi[1] and avg > ta.sma(avg, 11) and running_ph and avg < running_ph and not (wma_3m_3[1] < wma_3m_3)
is_cross_res = ta.crossover(avg, running_ph) and avg > wma_3m_3 and wma_3m_3 > wma_5m_5
plotshape(bigdrop ? low : na, title="Logic1", style=shape.diamond, location=location.absolute, color=color.blue, size=size.normal)
plotshape(is_cross_res ? low : na, title="Logic2", style=shape.diamond, location=location.absolute, color=color.white, size=size.normal)
/////////////////////////
close10 = avg_10m //request.security(symbol=syminfo.tickerid, timeframe="11", expression=avg_10m, lookahead=barmerge.lookahead_on)
wma10_11 = ta.wma(avg_10m, 4)
wma_10_11 = request.security(symbol=syminfo.tickerid, timeframe="11", expression=wma10_11, lookahead=barmerge.lookahead_on)
//plot(wma_10_11, 'ema10_11', color.blue)
wma10_48 = ta.wma(avg_10m, 9)
wma_10_48 = request.security(symbol=syminfo.tickerid, timeframe="12", expression=wma10_48, lookahead=barmerge.lookahead_on)
//plot(wma_10_48, 'ema10_48', color.orange)
close8 = avg_8m //request.security(symbol=syminfo.tickerid, timeframe="5", expression=avg_8m, lookahead=barmerge.lookahead_on)
wma8_11 = ta.wma(avg_8m, 3)
wma_8_11 = request.security(symbol=syminfo.tickerid, timeframe="12", expression=wma8_11, lookahead=barmerge.lookahead_on)
//plot(wma_10_11, 'ema10_11', color.purple)
wma8_48 = ta.wma(avg_8m, 8)
wma_8_48 = request.security(symbol=syminfo.tickerid, timeframe="11", expression=wma8_48, lookahead=barmerge.lookahead_on)
up10m = false
if close10 > wma_10_11
up10m := true
down8m = false
if close8 < wma_8_48
down8m := true
//plotshape(down8m ? low1d*0.998: na, title="No Short", style=shape.circle, location=location.absolute, color=color.yellow, size=size.tiny)
//plotshape(up10m ? low1d*0.995: na, title="No Short", style=shape.circle, location=location.absolute, color=color.blue, size=size.tiny)
/////////////////////////*****
// logic buy sell improve start
src = avg
di = (6 - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (0.4 * 0.4 + 0.4 * 0.4 * 0.4)
c4 = -3.0 * (2.0 * 0.4 * 0.4 + 0.4 + 0.4 * 0.4 * 0.4)
c5 = 3.0 * 0.4 + 1.0 + 0.4 * 0.4 * 0.4 + 3.0 * 0.4 * 0.4
var float i1 = na
var float i2 = na
var float i3 = na
var float i4 = na
var float i5 = na
var float i6 = na
i1 := c1 * src + c2 * nz(i1[1])
i2 := c1 * i1 + c2 * nz(i2[1])
i3 := c1 * i2 + c2 * nz(i3[1])
i4 := c1 * i3 + c2 * nz(i4[1])
i5 := c1 * i4 + c2 * nz(i5[1])
i6 := c1 * i5 + c2 * nz(i6[1])
Cto = -0.4 * 0.4 * 0.4 * i6 + c3 * i5 + c4 * i4 + c5 * i3
//bfrC = Cto > nz(Cto[1]) ? raise : Cto < nz(Cto[1]) ? fall : na
//plot(Cto, title='Trend', linewidth=2, style=plot.style_line, color=color.new(color.red, 0), editable=false)
ema3 = ta.ema(avg_3m, 3)
//plot(ema3, title='EMA', linewidth=2, style=plot.style_line, color=color.new(color.white, 0))
var bool is_cross_up = false
var bool is_cross_down = false
if ta.crossover(ema3, Cto)
is_cross_up := true
is_cross_down := false
if ta.crossunder(ema3, Cto)
is_cross_down := true
is_cross_up := false
//condition Long & Short
long = (avg > Cto and avg[1] < Cto[1] and avg > avg[1] or avg[1] > Cto[1] and avg > avg[1] and avg[1] < avg[2] and avg > ema3) ? true : false
profit_long = close < close[1] and low < ema3 and close[1] > ema3[1] and close[2] > ema3[2] and barstate.isconfirmed
//var int trend = 0
short = (avg < Cto and avg[1] > Cto[1] and avg < avg[1] or avg[1] < Cto[1] and avg < avg[1] and avg [1] > avg[2] and avg < ema3) ? true : false
profit_short = close > close[1] and high > ema3 and close[1] < ema3[1] and close[2] < ema3[2] and barstate.isconfirmed
plotshape(short ? high: na, title="No Short", style=shape.xcross, location=location.absolute, color=color.yellow, size=size.normal)
plotshape(long ? low: na, title="No Short", style=shape.xcross, location=location.absolute, color=color.blue, size=size.normal)
// logic buy sell improvate end
//////////////////////////******
wma3 = ta.wma(avg, 3)
wma11 = ta.wma(avg, 11)
wma21 = ta.wma(avg, 21)
wma48 = ta.wma(avg, 50)
//plot(wma3, color = color.yellow)
//plot(wma11, color = color.white)
//plot(wma21, color = color.gray)
//plot(wma48, color = color.blue)
tiny_change = math.abs(math.abs(open[1] - open[0]) - avg_change)
//label.new(bar_index, low1d, text=str.format("{0}", math.abs(open[1]-avg_8m) ), textcolor=color.yellow, style=label.style_triangleup, size=size.tiny)
plotshape(math.abs(open-avg) <= 0.001 and math.abs(open[1]-avg) <= 0.07 ? low : na, title="Logic1", style=shape.triangledown, location=location.absolute, color=color.yellow, size=size.normal)
end_up_2 = ta.crossover(open, running_ph) and open[2] < open[1] and open[1] < open and tiny_change > 0.1
plotshape(end_up_2? low : na, title="Logic1", style=shape.triangledown, location=location.absolute, color=color.white, size=size.normal)
is_up = open > avg
start_up_1 = not is_up[10] and not is_up[9] and not is_up[8] and not is_up[7] and not is_up[6] and not is_up[5] and not is_up[4] and not is_up[3] and not is_up[2] and not is_up[1] and is_up
plotshape(start_up_1 ? low : na, title="Logic1", style=shape.triangleup, location=location.absolute, color=color.yellow, size=size.tiny)
///////////////////////MACD START
fast_length = 5
slow_length = 13
signal_length = 8
sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])
// Plot colors
col_macd = input(#2962FF, "MACD Line ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating
fast_ma = ta.ema(avg, fast_length)
slow_ma = ta.ema(avg, slow_length)
macd = fast_ma - slow_ma
signal = ta.ema(macd, signal_length)
hist = macd - signal
//hline(0, "Zero Line", color=color.new(#787B86, 50))
//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
//plot(macd, title="MACD", color=color.white)
//plot(signal, title="Signal", color=color.yellow)
//////////////////////MACD END
/////////////////////RSI START
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
rsiLengthInput = 11
maTypeInput = "SMA"
maLengthInput = 24
bbMultInput = 2.0
up = ta.rma(math.max(ta.change(avg), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(avg), 0), rsiLengthInput)
rsi2 = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
//plot(rsi2, "RSI", color=#7E57C2)
//plot(rsiMA, "RSI-based MA", color=color.yellow)
var bool is_cross_down_rsi = false
var bool is_cross_up_rsi = false
if ta.crossover(rsi2, rsiMA)
is_cross_down_rsi := false
is_cross_up_rsi := true
if ta.crossunder(rsi2, rsiMA)
is_cross_down_rsi := true
is_cross_up_rsi := false
/////////////////////RSI END
longCondition1 = wma3 < wma11 and ta.crossover(open,wma21) and (wma_3m_3[1] < wma_3m_3) and not (wma_3m_8[1] > wma_3m_8)
longCondition2 = wma3 > wma11 and start_up_1 or long[1] and not bottomsupport[2] and bottomsupport[1] and bottomsupport and open[1] < open
longCondition3 = long and not bottomsupport[2] and bottomsupport[1] and bottomsupport and open[1] < open
longCondition4 = ta.crossover(open, wma_3m_8) and ta.crossover(open, wma_5m_5) and not (wma_3m_3 < wma_5m_5 and wma_5m_5 < wma_3m_8) and not (macd[1] > macd)
start_bottom = hist<0 and hist[1] < hist //and signal[1] < signal
longCondition5 = start_bottom and ta.crossover(wma_3m_3, wma_5m_5) and avg[1] < avg
plotshape(longCondition1 ? low : na, title="Logic1", style=shape.circle, location=location.absolute, color=color.yellow, size=size.normal)
plotshape(longCondition2 ? low : na, title="Logic1", style=shape.circle, location=location.absolute, color=color.white, size=size.normal)
plotshape(longCondition3 ? low : na, title="Logic1", style=shape.circle, location=location.absolute, color=color.blue, size=size.normal)
plotshape(longCondition4 ? low : na, title="Logic1", style=shape.circle, location=location.absolute, color=color.gray, size=size.normal)
plotshape(longCondition5 ? low : na, title="Logic1", style=shape.circle, location=location.absolute, color=color.red, size=size.normal)
longCondition = longCondition1 or longCondition2 or longCondition3 or longCondition4 or longCondition5
continue_down = math.abs(wma_3m_8 - wma_8m_8) > math.abs(wma_3m_8[1] - wma_8m_8[1]) and math.abs(wma_3m_8[2] - wma_8m_8[2]) > math.abs(wma_3m_8[3] - wma_8m_8[3])
continue_up = math.abs(wma_3m_8 - wma_8m_8) < math.abs(wma_3m_8[1] - wma_8m_8[1]) and math.abs(wma_3m_8[1] - wma_8m_8[1]) < math.abs(wma_3m_8[2] - wma_8m_8[2])
plotshape(not bar_up ? low1d*0.998: na, title="No Short", style=shape.circle, location=location.absolute, color=color.yellow, size=size.tiny)
plotshape(bar_up ? low1d*0.998: na, title="No Short", style=shape.circle, location=location.absolute, color=color.blue, size=size.tiny)
if ta.crossunder(wma_3m_3, wma_5m_5) or hist[1] > hist or not bar_up//or continue_down//nd wma_3m_8 < wma_8m_8//or rsiMA[1] > rsiMA
longCondition := false
end_up_1 = open[4] < open[3] and open[3] < open[2] and open[2] > open[1] and open[1] > open
h = hour(time_close, 'UTC+7')
m = minute(time_close, 'UTC+7')
lock_time = h >= 2 and h < 7
if (longCondition) and not lock_time
strategy.entry("long", strategy.long)
closeLong4 = hist>0 and hist[1] > hist and not (wma_3m_3[1] < wma_3m_3)
start_short_2 = wma3 > wma11 and open[2] < wma3 and open[1] < wma11 and open < wma11
shortCondition1 = start_short_2 or bigdrop //or end_up_1[1] and not end_up_1 and open < wma3
shortCondition2 = closeLong4 and closeLong4[1] and closeLong4[2]
shortCondition = shortCondition1 or shortCondition2
if bar_up
shortCondition := false
if (shortCondition) and not lock_time
strategy.entry("short", strategy.short)
closeLong1 = end_up_1
closeLong2 = end_up_2
closeLong3 = ta.crossunder(open, wma_3m_3) and not (hist[1] < hist)
closeLong5 = wma_8m_8[1] > wma_8m_8 and open[2] >= open[1] and open[1] >= open
plotshape(closeLong1 ? high : na, title="Logic1", style=shape.xcross, location=location.absolute, color=color.white, size=size.normal)
plotshape(closeLong2 ? high : na, title="Logic1", style=shape.xcross, location=location.absolute, color=color.orange, size=size.normal)
plotshape(closeLong3 ? high : na, title="Logic1", style=shape.xcross, location=location.absolute, color=color.yellow, size=size.normal)
plotshape(closeLong4 ? high : na, title="Logic1", style=shape.xcross, location=location.absolute, color=color.blue, size=size.normal)
closelong = closeLong1 or closeLong2 or closeLong3 or closeLong4 //or closeLong5
if bottomsupport
closelong := false
closeShort2 = wma3 < wma11 and open[1] > wma3[1] and open > wma11 and not (wma_3m_3[1] > wma_3m_3) and not (wma_5m_5[1] > wma_5m_5)
if open < wma21 or is_cross_up_rsi
closeShort2 := false
closeShort1 = start_bottom and (not (open < wma_3m_3 or open[1] < wma_3m_3[1]) or wma_3m_3[1] < wma_3m_3)
//closeShort3 =open[2] < wma_3m_3[2] and open > wma_3m_3 and open[1] < open
closeshort = closeShort1 or closeShort2 //or closeShort3
plotshape(closeShort1 ? low : na, title="Logic1", style=shape.cross, location=location.absolute, color=color.gray, size=size.normal)
plotshape(closeShort2 ? low : na, title="Logic1", style=shape.cross, location=location.absolute, color=color.white, size=size.normal)
//if is_cross_down_rsi
// closeshort := false
if(strategy.position_size > 0)
strategy.close(id="long", when=closelong)
if(strategy.position_size < 0)
strategy.close(id="short", when = closeshort)
if(strategy.position_size > 0)
strategy.exit(id='long', limit=longTake,stop = longStop)
if(strategy.position_size < 0)
strategy.exit(id='short', limit=shortTake,stop = shortStop)