-
Notifications
You must be signed in to change notification settings - Fork 1
/
reference_code.pine
90 lines (74 loc) · 2.72 KB
/
reference_code.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
//@version=5
strategy("Optimizer v1", overlay=true)
// Conditions B1 🟢LONG - EMA, SMA, PRICE
ema70 = ta.ema(close, 70)
ema100 = ta.ema(close, 100)
cond_EMA1 = 0
if ema70 > ema100 and ta.crossover(close, ema70)
cond_EMA1 := 1
// Conditions B1.10 🟢LONG PRICE
sma70 = ta.sma(close, 70)
cond_EMA2 = 0
if close > sma70
cond_EMA2 := 1
// Conditions 🟢LONG ADX
adxlen = 14
dilen = 14
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adx
sig = adx(dilen, adxlen)
cond_dmi = 0
if sig > 15
cond_dmi := 1
//Conditions B1.11 🟢LONG CCI
cci = ta.cci(close, 14) /// CCI LENGTH AGREGAR AL CODIGO
cond_cci = 0
if cci > 30
cond_cci := 1
// Conditions 🟢LONG DMI, MACD , RSI'
len = 14
up = ta.change(high)
down = -ta.change(low)
truerange = ta.rma(ta.tr, len)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
cond_macd = 0
if histLine > 0
cond_macd := 1
if cond_EMA1 and cond_EMA2 and cond_dmi and cond_cci and cond_macd
strategy.entry("Long", strategy.long)
// B3 🟡Take Profit
tp1_lot = 25 * strategy.position_size * 0.01
tp2_lot = 25 * strategy.position_size * 0.01
tp3_lot = 100 * strategy.position_size * 0.01
stop_loss_price = 0.0
tp1 = 0.0
tp2 = 0.0
tp3 = 0.0
if strategy.position_size > 0// B4 🟡Stop Loss %
stop_loss_percent = 3
stop_loss_price := strategy.position_avg_price * 0.97 //(1 - stop_loss_percent / 100)
tp1 := strategy.position_avg_price * (1.01)
tp2 := strategy.position_avg_price * (1.02)
tp3 := strategy.position_avg_price * (1.03)
// strategy.exit("Stop Loss", "Long", stop=stop_loss_price)
strategy.exit("TP1", "Long", qty=tp1_lot, limit=tp1, stop=stop_loss_price)
strategy.exit("TP2", "Long", qty=tp2_lot, limit=tp2, stop=stop_loss_price)
strategy.exit("TP3", "Long", qty=tp3_lot, limit=tp3, stop=stop_loss_price)
plot(stop_loss_price ? stop_loss_price : na, "stop_loss_price", color = color.red, style = plot.style_circles)
plot(tp1 ? tp1 : na, "tp1", color = color.green, style = plot.style_circles)
plot(tp2 ? tp2 : na, "tp2", color = color.green, style = plot.style_circles)
plot(tp3 ? tp3 : na, "tp3", color = color.green, style = plot.style_circles)