Skip to content

Commit 2f89263

Browse files
authored
Update README.md
1 parent 428e360 commit 2f89263

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

coding_conventions/README.md

+15-25
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ The goal of these Coding Conventions is to present a set of best practices and s
1818
- [Naming Conventions](#naming-conventions)
1919
- [Spacing](#spacing)
2020
- [Line Wrapping](#line-wrapping)
21-
<br>
2221

23-
## Script Structure
2422

23+
<br>
24+
## Script Structure
2525
The Pine compiler is not very strict on exact positioning of specific statements or compiler directives. While many other arrangements are syntactically correct, these guidelines aim to provide a standard way of ordering elements in scripts:
2626

2727
1. The first line of a script should be the `//@version=X` compiler directive, where `X` is replaced by the version of Pine the script is written for. While the compiler defaults to Pine version 1 when no directive is used, scripts written using version 1 of Pine should nonetheless contain the `//@version=1` directive on their first line.
@@ -71,12 +71,11 @@ plot(signal, color = color.orange)
7171

7272
**[Back to top](#table-of-contents)**
7373

74-
<br>
7574

75+
<br>
7676
## Naming Conventions
7777

7878
### Variable Names
79-
8079
We recommend using camelCase for variable names. Example: `emaLength`, `obLevel`, `showSignal2`, `aLongVariableName`.
8180

8281
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:
@@ -88,22 +87,17 @@ For large projects, you may find it useful to use prefixes for a few types of va
8887

8988

9089
### Function Names
91-
9290
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`.
9391

9492
### Function Parameter Names
95-
9693
Function parameters should be prefixed with the underscore in order to differentiate them from global scope variables. Example:
97-
98-
```
94+
```js
9995
daysInMonth(_year, _month) =>
10096
```
10197

10298
### Function Dependencies
103-
10499
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.
105-
106-
```
100+
```js
107101
lenMultiplier = input(2, "Length Multiplier")
108102

109103
f_getSlowLength(_len) =>
@@ -115,59 +109,55 @@ f_getSlowLength(_len) =>
115109
```
116110

117111
This is a preferable way to write the same function, which eliminates dependencies:
118-
119-
```
112+
```js
120113
f_getSlowLength(_len, _mult) =>
121114
_tempLen = _len * _mult
122115
if _tempLen < 20 or _tempLen > 30
123116
_tempLen := 25
124117
_tempLen
125118
```
126119
### Local Scope Variable Names
127-
128120
The same underscore prefix used for function parameters should also be used for all local variables. Example:
129-
```
121+
```js
130122
f_getSlowLength(_len) =>
131123
_tempLen = _len * 2
132124
if _tempLen < 20 or _tempLen > 30
133125
_tempLen := 25
134126
_tempLen
135127
```
136-
```
128+
```js
137129
if something
138130
_myLocalVar = something
139131
```
140-
```
132+
```js
141133
for _i = 0 to 100
142134
_myLocalVar = something[_i]
143135
```
144136

145137
**[Back to top](#table-of-contents)**
146138

147-
<br>
148139

140+
<br>
149141
## Spacing
150142

151143
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:
152144

153-
```
145+
```js
154146
a = close > open ? 1 : -1
155147
var newLen = 2
156148
newLen := min(20, newlen + 1)
157149
a = - b
158150
c = d > e ? d - e : d
159151
index = bar_index % 2 == 0 ? 1 : 2
160152
plot(series, color = color.red)
161-
162153
```
163154

164-
<br>
165155

156+
<br>
166157
## Line Wrapping
167158

168159
When lines need to be continued on the next, use two spaces to indent each continuation line. Example:
169-
170-
```
160+
```js
171161
plot(
172162
series = close,
173163
title = "Close",
@@ -177,8 +167,7 @@ plot(
177167
```
178168

179169
Tabs may be used to line up elements in order to increase readability.
180-
181-
```
170+
```js
182171
plot(
183172
series = close,
184173
title = "Close",
@@ -187,6 +176,7 @@ plot(
187176
)
188177
```
189178

179+
<br>
190180
## Example Scripts
191181

192182
Some authors use the Coding Conventions systematically:

0 commit comments

Comments
 (0)