-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cross_sma.pine
35 lines (33 loc) · 1.95 KB
/
cross_sma.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
// 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("Cross SMA - DataCrypto Analytics", "", true)
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// COLETA DE DADOS
///////////////////////////////////////////////////////////////////////////////////////////////////////////
SMA30 = sma(close, 30)
SMA100 = sma(close, 100)
xUp = crossover(SMA100, SMA30)
xDw = crossunder(SMA100, SMA30)
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ALERTAS
///////////////////////////////////////////////////////////////////////////////////////////////////////////
if xUp
// Trigger the alert the first time a cross occurs during the real-time bar.
alert("SMA30 (" + tostring(close) + ") cruzou SMA100 (" + tostring(SMA30) + ").", alert.freq_once_per_bar)
if xDw
alert("SMA30 (" + tostring(close) + ") cruzou SMA100 (" + tostring(SMA30) + ").", alert.freq_once_per_bar)
////////////////////////////////////////////////////////////////////////////////
/// PLOT
////////////////////////////////////////////////////////////////////////////////
P1 = plot(SMA30, color=color.green, title="Plot SMA30", transp=80)
P2 = plot(SMA100, color=color.red, title="Plot SMA100", transp=80)
plotshape(xUp, location=location.abovebar, style=shape.labeldown, color=color.black, title="Plot SELL",size=size.small, text = "Sell ⇣", textcolor=color.red, transp=0, offset=0)
plotshape(xDw, location=location.belowbar, style=shape.labelup, color=color.black, title="Plot BUY",size=size.small, text = "Buy ⇡", textcolor=color.green, transp=0, offset=0)
fill(P1, P2, color=#e07800, transp=92)