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: guides/faq_and_code/README.md
+96-1Lines changed: 96 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,21 @@
4
4
5
5
## Introduction
6
6
7
-
This is a compendium of frequently asked questions on Pine. Answers are short and often come with examples of code or links where relevant information can be found.
7
+
This is a compendium of frequently asked questions on Pine. Answers often give code examples or link to the best sources on the subject.
8
8
9
9
### Table of Contents
10
10
11
11
-[Built-in variables](#built-in-variables)
12
12
-[Built-in functions](#built-in-functions)
13
+
-[Operators](#operators)
13
14
-[Plotting](#plotting)
14
15
-[Indicators (a.k.a. studies)](#indicators)
15
16
-[Strategies](#strategies)
16
17
-[Alerts](#alerts)
17
18
-[Techniques](#techniques)
18
19
19
20
21
+
<br><br>
20
22
## BUILT-IN VARIABLES
21
23
22
24
@@ -36,28 +38,108 @@ threeGreenCandles = greenCandle and greenCandle[1] and greenCandle[2]
36
38
37
39
38
40
41
+
<br><br>
39
42
## BUILT-IN FUNCTIONS
40
43
41
44
45
+
### Why do I get an error message when using highest() or lowest()?
46
+
Most probably because you are trying to use a series instead of an integer as the second parameter (the length). Either use an integer or use the RicardoSantos replacements [here](https://www.tradingview.com/script/32ohT5SQ-Function-Highest-Lowest/). If you don't know Ricardo, take the time to look at his indicators while you're there. Ricardo is among the most prolific and ingenious Pinescripters out there.
42
47
48
+
49
+
<br><br>
50
+
## OPERATORS
51
+
52
+
53
+
54
+
### What's the difference between `==`, `=` and `:=`?
55
+
`==` is used to test for true/false conditions.<br>
56
+
`=` is used to declare and initialize variables.<br>
57
+
`:=` is used to assign values to variables after initialization, transforming them into *mutable variables*.
58
+
```
59
+
//@version=3
60
+
study("")
61
+
a = 0
62
+
b = 1
63
+
plot(a == 0 ? 1 : 2)
64
+
plot(b == 0 ? 3 : 4, color = orange)
65
+
a := 2
66
+
plot(a == 0 ? 1 : 2, color = aqua)
67
+
```
68
+
69
+
70
+
<br><br>
43
71
## PLOTTING
44
72
45
73
46
74
47
75
### Can I plot diagonals between two points on the chart?
48
76
Yes, using the [`line.new()`](https://www.tradingview.com/pine-script-reference/v4/#fun_line{dot}new) function available in v4.
49
77
78
+
### How do I plot a support line?
79
+
To plot a continuous line in Pine, you need to either:
80
+
1. Look back into elapsed bars to find an occurrence that will return the same value over consecutive bars so you can plot it, or
81
+
1. Find levels and save them so that you can plot them. In this case your saving mechanism will determine how many levels you can save.
82
+
These are examples of three different techniques used to determine and draw support lines:
-[Auto-Support v 0.2 by jamc](https://www.tradingview.com/script/hBrQx1tG-Auto-Support-v-0-2/)
85
+
-[S/R Barry by likebike](https://www.tradingview.com/script/EHqtQi2g-S-R-Barry/)
86
+
87
+
### How many plots, security() calls, variables or lines of code can I use?
88
+
The limit for plots is 64. Note than one plot statement can use up more than one allowed plot, depending on how it is structured.
89
+
The limit for `security()` calls is 40.
90
+
The limit for variables is 1000.
91
+
We do not know of a limit to the number of lines in a script. There is, however a limit of 50K compiled tokens, but they don't correspond to code lines.
92
+
93
+
### How can I use colors in my indicator plots?
94
+
See [Working with colours](https://kodify.net/tradingview/colours/) by kodify.
95
+
96
+
### How do I make my indicator plot over the chart?
97
+
Use `overlay=true` in `strategy()` or `study()` declaration statement, e.g.,:
98
+
```
99
+
study("My Script", overlay=true)
100
+
```
101
+
If your indicator was already in a Pane before applying this change, you will need to use Add to Chart again for the change to become active.
102
+
50
103
51
104
105
+
<br><br>
52
106
## INDICATORS
53
107
54
108
55
109
56
110
### Can I create an indicator that plots like the built-in Volume or Volume Profile indicators?
57
111
No.
58
112
113
+
### How do I feed the output of one script to another script?
From the script's *Inputs* you will then be able to select a plot from another indicator if it present on your chart.
119
+
You can use only one such statement in your script. If you use more than one, the other indicator plots will not be visible from the *Inputs* dropdown.
120
+
You cannot use this technique in strategies.
121
+
122
+
### Can I write a script that plots like the built-in Volume Profile or Volume indicators?
123
+
No. TradingView uses special code for these that is not available to standard Pine scripts.
124
+
125
+
### How can I use one script's output as an input into another?
126
+
See how our [Signal for Backtesting-Trading Engine](https://www.tradingview.com/script/y4CvTwRo-Signal-for-Backtesting-Trading-Engine-PineCoders/) can be integrated as an input to our [Backtesting-Trading Engine](https://www.tradingview.com/script/dYqL95JB-Backtesting-Trading-Engine-PineCoders/).
127
+
128
+
### Is it possible to export indicator data to a file?
129
+
No. The only way for now is through screen scraping.
130
+
131
+
### Can my script place something on the chart when it is running from a pane?
132
+
The only thing that can be changed on the chart from within a pane is the color of the bars. See the [`barcolor()`](https://www.tradingview.com/pine-script-docs/en/v4/annotations/Barcoloring_a_series_with_barcolor.html) function.
133
+
134
+
### Can I merge 2 or more indicators into one?
135
+
Sure, but start by looking at the scale each one is using. If you're thinking of merging a moving average indicator designed to plot on top of candles and in relation to them, you are going to have problems if you also want to include and indicator showing volume bars in the same script because their values are not on the same scale.
59
136
137
+
Once you've made sure your scales will be compatible (or you have devised a way of normalizing/re-scaling them), it's a matter of gathering the code from all indicators into one script and removing any variable name collisions so each indicator's calculations retain their independence and integrity.
60
138
139
+
> Note that if the indicators you've merged are CPU intensive, you may run into runtime limitations when executing the compound script.
140
+
141
+
142
+
<br><br>
61
143
## STRATEGIES
62
144
63
145
@@ -81,8 +163,20 @@ EnterLong = GoLong and TradeDateIsAllowed()
81
163
```
82
164
> Note that with this code snippet, date filtering can be enabled/disabled using a checkbox. This way you don't have to reset dates when filtering is no longer needed; just uncheck the box.
83
165
166
+
### How do I write code for a signal with 2 conditions that occur at different times?
167
+
Backtest Rookies has a [blog post](https://backtest-rookies.com/2018/10/26/tradingview-opening-a-window/) on the subject.
168
+
169
+
### How can I save the entry price in a strategy?
170
+
See [How to Plot Entry Price](https://www.tradingview.com/script/bHTnipgY-HOWTO-Plot-Entry-Price/) by vitvlkv
171
+
172
+
### How do I convert a strategy to a study in order to generate alerts for discretionary trading or a third-party execution app/bot?
173
+
The best way to go about this is to write your strategies in such a way that their behavior depends the least possible on `strategy.*` variables and `strategy.*()` call parameters, because these cannot be converted into an indicator.
174
+
175
+
The PineCoders [Backtesting-Trading Engine](https://www.tradingview.com/script/dYqL95JB-Backtesting-Trading-Engine-PineCoders/) is a framework that allows you to easily convert betweeen strategy and indicator modes because it manages trades using custom Pine code that does not depend on an involved setup of `strategy.*()` call parameters.
176
+
84
177
85
178
179
+
<br><br>
86
180
## ALERTS
87
181
88
182
@@ -116,6 +210,7 @@ If one of the generic indicators supplied with the Screener suits your needs and
0 commit comments