-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
poison_rat_v2.pine
94 lines (80 loc) · 4.71 KB
/
poison_rat_v2.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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DataCrypto Analytics
//
// https://datacryptoanalytics.com/
//
// Twitter: @dc_analytics
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//@version=4
study("Poison Rat v2.1 - DataCrypto Analytics", "", true)
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// COLETA DE DADOS
///////////////////////////////////////////////////////////////////////////////////////////////////////////
tempo = input("30", title = "🕗 Timeframe", group = "Configurações ⚙️", type = input.resolution, options = ["1","5","15","30","60", "120", "240","360","720", "D", "W"])
showcross = input(true, "Mostrar Sinais")
lime = color.new(#17a302, 0)
verde = color.new(#1b5e20, 0)
verm = color.new(#811c1c, 0)
red = color.new(#a30202, 0)
bran = color.new(#ffffff, 65)
up = close > open
down = open > close
vol = volume
silver = color.silver
gray = color.new(#4a4a49, 0)
azu = color.new(#ff8c05, 0)
// RMA = Média móvel usada no RSI. É a média móvel ponderada exponencialmente com alfa = 1/comprimento.
s = rma(close, 16)
v = rma(close, 4)
k = rma(close, 9)
sma1 = sma(close,100)
sma2 = sma(close,200)
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// PERCEBE CRUZAMENTO DAS MÉDIAS MÓVEIS
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// 200 sma fica acima da 100sma "SMA X ⇡" 200 sma fica abaixo da 100sma "SMA X ⇣"
xUp = crossover(sma2, sma1)
xDw = crossunder(sma2, sma1)
a = security(syminfo.tickerid, tempo, s)
b = security(syminfo.tickerid, tempo, v)
r = security(syminfo.tickerid, tempo, k)
c = b > a ? lime : red
crossdn = a > b and a[1] < b[1]
crossup = b > a and b[1] < a[1]
crossx = b > r and b[1] < r[1]
plotshape(showcross and crossdn ? a : na, location=location.abovebar, style=shape.labeldown, color=verm, title="Mostrar Venda",size=size.tiny, text = "⇣", textcolor=color.red, offset=0)
plotshape(showcross and crossup ? a : na, location=location.belowbar, style=shape.labelup, color=verde, title="Mostrar Compra",size=size.tiny, text = "⇡", textcolor=color.green, offset=0)
plotshape(xDw, location=location.belowbar, style=shape.labelup, color=color.black, title="Tendência ⇡",size=size.small, text = "T ⇡", textcolor=color.green, offset=0)
plotshape(xUp, location=location.abovebar, style=shape.labeldown, color=color.black, title="Tendência ⇣",size=size.small, text = "T ⇣", textcolor=color.red, offset=0)
//fill(P1, P2, color=#e07800, transp=92)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PLOT COLOR CANDLES
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
barcolor((showcross and crossup)? lime:(showcross and crossdn)?red:up?silver:gray)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PLOT TABELA
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var table perfTable = table.new(position.top_right, 3, 2, border_width = 3)
LIGHTTRANSP = 90
AVGTRANSP = 80
HEAVYTRANSP = 70
i_posColor = input(color.rgb(38, 166, 154), title="Positive Color")
i_negColor = input(color.rgb(240, 83, 80), title="Negative Color")
f_rateOfreturn(_v1, _v2) => (_v1 - _v2) * 100 / abs(_v2)
f_performance(_barsBack) =>
_performance = security(syminfo.tickerid, "1D", f_rateOfreturn(close, close[_barsBack]))
_performance
lastYearClose = security(syminfo.tickerid, "12M", close[1], lookahead=barmerge.lookahead_on)
f_fillCell(_table, _column, _row, _value, _timeframe) =>
_c_color = _value >= 0 ? i_posColor : i_negColor
_transp = abs(_value) > 10 ? HEAVYTRANSP : abs(_value) > 5 ? AVGTRANSP : LIGHTTRANSP
_cellText = tostring(_value, "#.##") + "%\n" + _timeframe
table.cell(_table, _column, _row, _cellText, bgcolor = color.new(_c_color, _transp), text_color = _c_color, width = 6)
if barstate.islast
f_fillCell(perfTable, 0, 0, f_performance(5), "1W")
f_fillCell(perfTable, 1, 0, f_performance(21), "1M")
f_fillCell(perfTable, 2, 0, f_performance(63), "3M")
f_fillCell(perfTable, 0, 1, f_performance(126), "6M")
f_fillCell(perfTable, 1, 1, f_rateOfreturn(close, lastYearClose), "YTD")
f_fillCell(perfTable, 2, 1, f_performance(251), "1Y")