-
Notifications
You must be signed in to change notification settings - Fork 5
/
4 - RMA.pine
72 lines (53 loc) · 2.12 KB
/
4 - RMA.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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © stmd
// @version=4
//-------------------------------------
// Release: 2020-08-04
// Author: stmd
// Email: pine@stmd.nl
// Profile: https://www.tradingview.com/u/stmd/
//-------------------------------------
// PURPOSE
//
//-------------------------------------
// FEATURES
//
//-------------------------------------
// NOTES
//
//-------------------------------------
// INDICATOR PARAMETERS
vVersion = "V1.0"
vTitle = "Rolling Moving Average"
vShort = "RMA"
vOverlay = true
vScale = scale.right
vPrecision = 0
study( title = vTitle+" ["+vVersion+"]", shorttitle = vShort, overlay = vOverlay, precision = vPrecision, resolution = "" )
//-------------------------------------
// INPUTS
vRmaSource = input( defval = close, type = input.source, title = "Source" )
vRmaLength = input( defval = 9, minval = 1, maxval = 1024, title = "Length" )
vSmooth = input( defval = 1, minval = 1, maxval = 1024, title = "Smooth" )
vOffSet = input( defval = 0, minval = 0, maxval = 1024, title = "Offset" )
//-------------------------------------
// FUNCTIONS
fMa( n, s, le ) =>
r = float( 0 )
for i = n + 0 to ( n + ( le - 1 ) )
r := ( r + s[ i ] )
a = r / le
fRma( n, s, le ) =>
ma = fMa( n, s, le )
r = float( 0 )
r := ( na( r[ 1 ] ) ? ma : ( ( r[ 1 ] * ( le - 1 ) ) + s[ n ] ) / le )
//-------------------------------------
// COLORS
fColor( n, s ) =>
r = ( s[ n + 1 ] < s[ n ] ) ? #26A69A : #EF5350
r
//-------------------------------------
// PLOT
vRma = fMa( 0, fRma( vOffSet, vRmaSource, vRmaLength ), vSmooth )
vPlotRma = plot( vRma, style = plot.style_line, color = fColor( 0, vRma ), title = "RMA" )
//-------------------------------------