You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-12Lines changed: 30 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -13,26 +13,44 @@
13
13

14
14
15
15
16
-
<divalign="center"><fontsize="+1"><strong>New to Pine?<br></strong></font> Begin your journey with our <ahref="http://www.pinecoders.com/learning_pine_roadmap">Learning Pine Roadmap</a>.</div>
16
+
<divalign="center">
17
+
<fontsize="+1"><strong>New to Pine?</strong></font><br>
18
+
Begin your journey with our <ahref="http://www.pinecoders.com/learning_pine_roadmap">Learning Pine Roadmap</a>.<br><br>
17
19
18
-
<divalign="center"><fontsize="+1"><strong>Have a question?<br></strong></font> Go to our Pine <ahref="http://www.pinecoders.com/faq_and_code">FAQ & Code</a>.</div>
20
+
<fontsize="+1"><strong>Have a question on Pine?</strong></font><br>
21
+
Your answer is probably already in our <ahref="http://www.pinecoders.com/faq_and_code">FAQ & Code</a>.<br>
22
+
If not, look up the <ahref="https://www.tradingview.com/pine-script-reference/v4/">Reference Manual</a>, the <ahref="https://www.tradingview.com/pine-script-docs/en/v4/Introduction.html">User Manual</a>, or search the Web.<br>
23
+
As a last resort, ask in the <ahref="https://www.tradingview.com/chat/#BfmVowG1TZkKO235">Pine Script chat room</a> on TradingView, or on <ahref="https://stackoverflow.com/questions/tagged/pine-script?tab=Newest">Stack Overflow</a>.<br><br>
19
24
20
-
<divalign="center"><fontsize="+1"><strong>Looking for reusable Pine code?<br></strong></font> The <ahref="https://github.com/pinecoders/pine-utils">PineCoders Repository</a> on GitHub is your friend.</div>
25
+
<fontsize="+1"><strong>Want to learn proper Pine coding style?</strong></font><br>
<divalign="center"><fontsize="+1"><strong>Want to learn proper Pine coding style?<br></strong></font> Read our <ahref="http://www.pinecoders.com/coding_conventions">Pine Coding Conventions</a>.</div>
28
+
<fontsize="+1"><strong>Want to stay abreast of Pine news?</strong></font><br>
29
+
Subscribe to our <ahref="https://t.me/PineCodersSquawkBox">PineCoders Squawk Box on Telegram</a>, or follow our <ahref="https://twitter.com/PineCoders">Twitter account</a>.<br><br>
30
+
31
+
<fontsize="+1"><strong>Looking for a professional Pine programmer?</strong></font><br>
32
+
See our <ahref="https://www.pinecoders.com/resources/#trusted-pine-programmers-for-hire">Trusted Pine Programmers for Hire</a>.<br><br>
33
+
34
+
<fontsize="+1"><strong>Looking for more resources on Pine?</strong></font><br>
35
+
Use our <ahref="http://www.pinecoders.com/resources">Pine Resources</a>.<br><br>
36
+
37
+
<fontsize="+1"><strong>Want to make a suggestion to improve Pine, or report a bug?</strong></font><br>
38
+
Send it by email to our <ahref="https://trello.com/c/QA6bcL7l">Trello board</a>.<br><br>
39
+
40
+
<fontsize="+1"><strong>Interested in broadening your vistas?</strong></font><br>
41
+
We have a guide on <ahref="http://www.pinecoders.com/techniques/dsp">Digital Signal Processing in Pine</a> and a <ahref="http://www.pinecoders.com/books">list of books</a>.
42
+
</div>
23
43
24
-
<divalign="center"><fontsize="+1"><strong>Looking for Pine-related tools or resources?<br></strong></font> Use our list of <ahref="http://www.pinecoders.com/resources">Pine Resources</a> or see our <ahref="http://www.pinecoders.com/techniques/dsp">Digital Signal Processing In Pine</a> guide.</div>
25
44
26
45
---
27
46
28
-
PineCoders is a [TradingView](https://www.tradingview.com/)-supported group of programmers using TradingView's [Pine Script](https://www.tradingview.com/pine-script-docs/en/v4/Introduction.html) programming language. We help TV members learn Pine, provide tools and resources for beginning as well as pro coders, and collaborate with TradingView to make using Pine indicators and strategies easier for both coders and the at-large TV community.
29
47
30
-
The [Suggestions For Improvement To Pine](https://trello.com/b/Jmv6c8Cx) Trello board is co-managed by PineCoders and TradingView. This [card](https://trello.com/c/r0jKAKhK) explains how the board works, how any Trello user can comment and vote on suggestions, or contribute new ones.
48
+
PineCoders is a [TradingView](https://www.tradingview.com/)-supported group of programmers who code in [Pine Script](https://www.tradingview.com/pine-script-docs/en/v4/Introduction.html), which is used to write trading indicators and strategies for the TradingView financial charting platform.
49
+
50
+
We collaborate with TradingView's Pine team to steer the future of the language and make Pine indicators and strategies easier to use for the at-large TV community of traders.
31
51
32
-
We also pilot the [PineCoders](https://www.tradingview.com/u/PineCoders/#published-scripts) TV moderator account, from which we moderate script publications, answer questions in the [Pine Script TV chat](https://www.tradingview.com/chat/#BfmVowG1TZkKO235), publish [open source tools and examples in Pine](https://www.tradingview.com/u/PineCoders/#published-scripts), and follow [leading publishers](https://www.tradingview.com/u/PineCoders/#following-people) of opensource scripts on TV, who's code you can learn a great deal from. We also answer questions on Pine at [Stack Overflow](https://stackoverflow.com/questions/tagged/pine-script?sort=Newest).
52
+
We pilot the [PineCoders](https://www.tradingview.com/u/PineCoders/#published-charts)moderator account on TV, from where we moderate scripts published in the [Public Library](https://www.tradingview.com/scripts/), answer questions in the [Pine Script chat](https://www.tradingview.com/chat/#BfmVowG1TZkKO235), publish [open source tools and examples in Pine](https://www.tradingview.com/u/PineCoders/#published-scripts), and follow [leading publishers](https://www.tradingview.com/u/PineCoders/#following-people) of open-source scripts on TV.
33
53
34
-
PineCoders works daily with TradingView's Pine team to identify and validate anomalies, and test upcoming new features.
**Trading Systems and Methods, 6th Edition**, Perry J. Kaufman
19
+
The Bible of system traders. A classic that's been around since 1978 and is still being updated. A general survey of all aspects of systems trading.
20
+
21
+
**Building Winning Algorithmic Trading Systems**, Kevin J. Davey
22
+
His personal methodology for developing systems. Takes us through the complete process and covers all the critical parts of developing small-scale systems, which includes much more than the trading strategy. Has good advice on backtesting.
23
+
24
+
**Advances in Financial Machine Learning**, Marcos Lopez de Prado
25
+
Whereas Davey's approach is small-scale, Prado writes about building larger-scale systems using big data, for example. But he covers essential areas of systems trading with a fresh and realistic perspective that will be useful, even to traders building smaller-scale systems. Includes a section on how to avoid pitfalls in backtesting.
26
+
27
+
**Quantitative Trading**, Ernest P. Chan
28
+
This book is similar to the Kevin Davey book, but written by a quant. Chan paints broad strokes in discussing many of the facets of running a small-scale automated operation.
29
+
30
+
**Professional Automated Trading: Theory and Practice**, Eugene A. Durenard
31
+
Durenard explains how he develops medium-scale adaptive systems using LISP. Plenty examples of code. Good concepts by a real practicioner.
32
+
33
+
**Trend Following, 5th Edition: How to Make a Fortune in Bull, Bear and Black Swan Markets**, Michael Covel
34
+
This book is essentially 3 books in one, it has interviews with many of the greatest traders, evidence based arguments for using trend following, and the facets of system trading. Spoiler alert: If you are looking for the holy grail the author does not include it.
35
+
36
+
37
+
## Trading techniques and indicators usable in automated trading
38
+
39
+
**New Concepts in Technical Trading Systems**, J. Welles Wilder Jr.
40
+
Curiously published in 1978, the same year as Kaufman's *Trading Systems and Methods*, this seminal piece has also become a classic, with many of the indicators presented in here for the first time becoming household names: RSI, ATR, DI, ADX and Parabolic SAR. A brilliant book and an intimate journey into Wilder's original thinking process. He has a knack for keeping calculations simple, yet aiming at the jugular, masterfully capturing the essence of whatever he sets his sights on measuring.
41
+
42
+
**Volume Price Analysis Across The Markets: 4 Books Box Set**, [Anna Coulling](https://www.annacoulling.com)
43
+
Contains great information on how to interpret and use volume for an edge in price action trading. Explains how to spot and utilize the actions of Market Makers.
All around book describing how to read market moves. Apart from other popular techniques like SR, etc, Beggs explains the concepts of strength & weakness and candle sentiment analysis. Laid out in a way, which can be coded into trading system. As an example, this is a [script covering candle sentiment](https://www.tradingview.com/script/5fSgjYoM-YTC-Candlestick-Sentiment/).
47
+
48
+
49
+
50
+
## Explorations
51
+
52
+
**Incerto Series**, Nassim Nicholas Taleb
53
+
An illuminating journey into opacity, uncertainty, randomness, and our general ignorance or misconceptions surrounding them. A humbling study of our shortcomings in appraising the past, present and future. The stimulating and funny work of an unashamedly radical thinker who, after making piles of "fuck you money", decided to take some time off from trading to walk slowly and rethink large parts of what we consider to be knowledge—and what is knowable.
54
+
55
+
**Thinking in Bets: Making Smarter Decisions When You Don't Have All the Facts**, Annie Duke
56
+
An ex-poker player and psychologist has a look at how to improve our thinking in situations where we don't have perfect information but still need to make decisions. She explores our learning process and how we can better distinguish between the quality of outcomes and the quality of our decisions, which because of randomness often cannot be linked.
57
+
58
+
**The Disciplined Trader: Developing Winning Attitudes**, Mark Douglas
59
+
An oft-vehiculated myth about automated trading is that it takes emotions out of the picture. Reality is different. Unchecked emotions and counter-productive thoughts can prevent you from modeling or adequately managing trading systems. This book focuses on the mental processes that can impact your trading. Douglas doesn't mention automated trading at all, and goes whole chapters at a time without even mentioning trading, but his book takes you on an introspective journey that has good probabilities of changing you for the best.
The goal of these Coding Conventions is to present a set of best practices and style guidelines for Pine Script. By making Pine scripts easier to read, these guidelines make open source code more usable, while also providing safeguards that minimize the risk of errors for developers.
16
15
17
16
### Table of Contents
@@ -20,6 +19,7 @@ The goal of these Coding Conventions is to present a set of best practices and s
20
19
-[Naming Conventions](#naming-conventions)
21
20
-[Spacing](#spacing)
22
21
-[Line Wrapping](#line-wrapping)
22
+
-[Example Scripts](#example-scripts)
23
23
24
24
25
25
<br>
@@ -53,17 +53,17 @@ Here is an example of a complete script:
53
53
study("MACD")
54
54
55
55
// ————— Inputs
56
-
fast=input(12, "Fast Length")
56
+
i_fast=input(12, "Fast Length")
57
57
// Calculates slow length from fast length and normalizes it if needed.
58
58
f_getSlowLength(_len) =>
59
59
_tempLen = _len *2
60
60
if _tempLen <20 or _tempLen >30
61
61
_tempLen :=25
62
62
_tempLen
63
-
slow =f_getSlowLength(fast)
63
+
slow =f_getSlowLength(i_fast)
64
64
65
65
// ————— Calculations
66
-
fastMa =ema(close, fast)
66
+
fastMa =ema(close, i_fast)
67
67
slowMa =ema(close, slow)
68
68
macd = fastMa - slowMa
69
69
signal =sma(macd, 9)
@@ -73,7 +73,6 @@ plot(macd, color = color.blue)
73
73
plot(signal, color =color.orange)
74
74
```
75
75
76
-
**[Back to top](#table-of-contents)**
77
76
78
77
<br>
79
78
@@ -83,87 +82,90 @@ plot(signal, color = color.orange)
83
82
84
83
We recommend using camelCase for variable names. Example: `emaLength`, `obLevel`, `showSignal2`, `aLongVariableName`.
85
84
85
+
For large projects, you may find it useful to use prefixes for a few types of variables, to make them more readily identifiable. The following prefixes can then be used:
86
+
87
+
-`i_` for variables initialized through `input()` calls.
88
+
-`c_` for variables containing colors.
89
+
-`p_` for variables used as `plot` or `hline` identifiers for use in `fill()` calls.
90
+
- All caps for constants, i.e., variables often initialized at the beginning of scripts whose value will not change during execution.
91
+
92
+
86
93
### Function Names
87
94
88
95
For function names, we recommend using a Hungarian-style `f_` prefix in combination with the usual camelCase. The `f_` prefix guarantees disambiguation between user-defined and built-in functions. Example: `f_sinh`, `f_daysInMonth`.
89
96
90
97
### Function Parameter Names
91
98
92
99
Function parameters should be prefixed with the underscore in order to differentiate them from global scope variables. Example:
93
-
94
-
```
100
+
```js
95
101
daysInMonth(_year, _month) =>
96
102
```
97
103
98
104
### Function Dependencies
99
105
100
106
When a function requires global scope variables to perform its calculations, these dependencies should be documented in comments. Dependencies are to be avoided whenever possible, as they jeopardize function portability and make code more difficult to read.
101
-
102
-
```
103
-
lenMultiplier = input(2, "Length Multiplier")
107
+
```js
108
+
i_lenMultiplier =input(2, "Length Multiplier")
104
109
105
110
f_getSlowLength(_len) =>
106
-
// Dependencies: lenMultiplier (initialized in inputs).
107
-
_tempLen = _len * lenMultiplier
111
+
// Dependencies: i_lenMultiplier (initialized in inputs).
112
+
_tempLen = _len *i_lenMultiplier
108
113
if _tempLen <20 or _tempLen >30
109
114
_tempLen :=25
110
115
_tempLen
111
116
```
112
117
113
118
This is a preferable way to write the same function, which eliminates dependencies:
114
-
115
-
```
119
+
```js
116
120
f_getSlowLength(_len, _mult) =>
117
121
_tempLen = _len * _mult
118
122
if _tempLen <20 or _tempLen >30
119
123
_tempLen :=25
120
124
_tempLen
121
125
```
126
+
122
127
### Local Scope Variable Names
123
128
124
129
The same underscore prefix used for function parameters should also be used for all local variables. Example:
125
-
```
130
+
```js
126
131
f_getSlowLength(_len) =>
127
132
_tempLen = _len *2
128
133
if _tempLen <20 or _tempLen >30
129
134
_tempLen :=25
130
135
_tempLen
131
136
```
132
-
```
137
+
```js
133
138
if something
134
139
_myLocalVar = something
135
140
```
136
-
```
141
+
```js
137
142
for _i =0 to 100
138
143
_myLocalVar = something[_i]
139
144
```
140
145
141
-
**[Back to top](#table-of-contents)**
142
146
143
147
<br>
144
148
145
149
## Spacing
146
150
147
151
A space should be used on both sides of all operators, whether they be assignment, arithmetic (binary or unary) or logical. A space should also be used after commas. Example:
148
-
149
-
```
152
+
```js
150
153
a = close > open ?1:-1
151
154
var newLen =2
152
155
newLen :=min(20, newlen +1)
153
156
a =- b
154
157
c = d > e ? d - e : d
155
158
index = bar_index %2==0?1:2
156
159
plot(series, color =color.red)
157
-
158
160
```
159
161
162
+
160
163
<br>
161
164
162
165
## Line Wrapping
163
166
164
167
When lines need to be continued on the next, use two spaces to indent each continuation line. Example:
165
-
166
-
```
168
+
```js
167
169
plot(
168
170
series = close,
169
171
title ="Close",
@@ -173,8 +175,7 @@ plot(
173
175
```
174
176
175
177
Tabs may be used to line up elements in order to increase readability.
176
-
177
-
```
178
+
```js
178
179
plot(
179
180
series = close,
180
181
title ="Close",
@@ -183,4 +184,16 @@ plot(
183
184
)
184
185
```
185
186
187
+
<br>
188
+
189
+
## Example Scripts
190
+
191
+
Some authors use the Coding Conventions systematically:
0 commit comments