We are proud to present the Pine scripting language! TradingView is the first platform of to have this kind of functionality, combined with advanced real-time charting and a super-engaged community of investors discussing ideas. We hope you enjoy using TradingView’s Pine programming language! Try it and let us know your feedback in this thread.
Update (Feb-3 2014): TradingView Pine Script New Features! Read more http://blog.tradingview.com/?p=223
Help get this topic noticed by sharing it on
Twitter,
Facebook, or email.



This topic is no longer open for comments or replies.
next » « previous |
-
I'd like to plot the difference of two MA's in spirit of MACD, but when one MA is shifted with respect to another.
Of course, there will be truncated function definition domain.
How can I do that? -
-
Trying to plot on the extension, or off the chart, if possible.
study(title = "extensionplot", overlay =false)
bc = na(close) ? bc[1] + 1 : n
plot(bc)
Technically, this should do it, if it was possible, right? -
-
Also, I'm looking to target only the current, unclosed bar*, and only plotting a point if that bar is not closed. Once the bar closes**, I want that point to be removed.
Any ideas on how I might be able to do this?
* by unclosed bar I mean, it is the newest bar on the chart, and nothing is after it.
** by closes I mean, a new bar has formed
I've tried a few things that I've used on other platforms and none seem to work, thanks-
We're going to add an ability to show price line independently of the plot itself. It should give you what you need - level on the last bar only. Will it be ok for your use case?
-
-
-
-
it would be nice if the user could input string values in the input object to specify period length for 'D', 'W', 'M', 'Y' instead of having to enter numerical values:
user_period = input(defval = 'W', title = 'Period')
where user_period is of type String.
for ex, at the moment, for the following to work
is_newbar(res, sess) => change(time(res, sess)) != 0
res needs to be hard coded as 'D' or 'W', etc...
i have developed an indicator that would be better if the user could just change in the input dialog the period from 'D' to 'W' and so on. right now, you have to go into the code and type in the change. yikes!
also, it would be great to have the ?: operator overloaded for (bool, string, string) so that we could return string values depending on the results of a conditional test.-
This is already in our plans...
-
-
-
-
I recently got help with adding a moving average to the ROC indicator with the line,
plot(sma(roc(close, 10), 10))
I tried this with the momentum indicator, but it gave me an error message after using a line,
plot(sma(mom(close, 10), 10).
Is there a way to write in moving averages for momentum and the choppiness indicator?
Thanks for any assistance.-
study(title = "My Script 0")
momentum = close - close[10]
plot(sma(momentum,10)) -
-
Thanks!
-
-
-
-
Hey there - I'm trying to create a PInescript that pilots a VStop from a higher timeframe than the current one. I looked at this code:
study(title="High Time Frame MA", overlay=true)
src = close, len = input(9)
out = sma(src, len)
out1 = security(tickerid, 'D', out)
plot(out1)
But vstop doesn't seem to be a standalone function - rather a Pinescript itself. Could you post the code for the Pinescript or is there another way to do this?
Thanks!-
VSTOP is in plans. We'll add it soon.
-
-
-
-
How do I make a comment in Pine??
Every computer language on the planet has this feature. Pine should too.
Or perhaps a better question:
Where is a formal description of the Pine scripting language?
Thanks, David -
-
- view 2 more comments
-
-
-
There are no block comments in pine... But you can select multiple lines of code and press Ctr+/ hotkey to comment/uncomment the selected text.
-
-
cool :)
-
-
-
Is there a way to add a text comment to the Study other than a study() title parameter?
Or is perhaps a better question:
Is there some debug facility?
Is there a way to do "print line" (i.e. print or printf or println or puts ) ??
How do I write "Hello World" ?-
You may plot any variable right on the chart. Text drawing is not yet there. It's planned.
-
-
OK. Plot variables seems the only way to go for now. Looking forward to the Text drawing.
-
-
-
-
guys, i am having a cosmetic/presentation issue. one of the indicators i am working on needs to display some graphical elements n amounts of points away from the low or high BUT this (vertical) offset amount is different depending on how many decimals the price has.
so depending on the instrument, we might have 0 (ie GER30), 1 (ie SPX500), 3 (ie EURJPY), or 5 (ie AUDUSD) decimals.
there seems to be no way to determine how many decimals the price of the currently displayed instrument has. there is now way to create a symbol table as a hash table for quick look-up (or associative array or map). there is no way to write 'if == '. and there is now way to write:
var decimals = current_price.number_of_decimals();
switch decimals {
case 0: {
offset = 5;
}
case 1: {
offset = ....;
}
case 2: {
offset = ...;
}
case 3: {
offset = 0.05;
}
case 4: {
...
}
case 5: {
...
}
default: {
...
} -
-
also, i just realized the scaling factor changes even between 2 instruments quoted with 2 decimals. for ex, it's different between XAUUSD and DXY. so even though i use some computation to keep the vertical offset proportionally away from the high/low, it is too far when displaying XAUUSD and just right when displaying DXY.
that is to say, for ex, that high + 15 appears to be a greater distance on XAUUSD than on DXY chart!
how about exposing a function to return the current chart's scaling factor so that we can use that in our own computation to plot the graphical elements such as dots/circles always at the same (perceived) distance from the candle bars?- view 1 more comment
-
-
This is a great conversation that's separate from the main topic, so I created a new topic to continue the discussion. Please reference the new topic here: Pine Script chart scaling problem
-
-
The topic moved to https://getsatisfaction.com/tradingvi...
-
-
-
re the issue of vertical offset, here is a temporary fix:
high + 0.5 * (high - low)
low - 0.5 * (high - low) -
-
-
study(title = "Coppock curve")
src = close
r1 = roc(src, 11)
r2 = roc(src, 14)
coppock = wma(r1 + r2, 10)
plot(coppock)
From http://stockcharts.com/help/doku.php?... -
-
-
-
guys,
take a look at this code:
study(title = "Yearly High/Low", overlay = true)
is_newbar(res, sess) => change(time(res, sess)) != 0
adopt(r, s) => security(tickerid, r, s)
low_range = valuewhen(is_newbar('12M','0000-0000'), low, 0)
high_range = valuewhen(is_newbar('12M','0000-0000'), high, 0)
down = plot(adopt('12M', low_range), color = green)
up = plot(adopt('12M', high_range), color = red)
fill(down, up, color = red, transp=97)
then take a look at the high for year 2006. seems to work usually except for 2006. what's going on here?- view 5 more comments
-
-
-
-
-
-
This is a great conversation that's separate from the main topic, so I created a new topic to continue the discussion. Please reference the new topic here: Pine Script Heiken-Ashi problem
-
-
-
1 more issue: i get this error:
Error: Cannot call `falling` with arguments (series, series); available overloads: falling(series, integer) => series;
when writing this:
_cross = cross(_sma10, _sma21)
_barssince = barssince(_cross)
_isfalling = falling(_cross, _barssince) ? true : false
the lookback argument 'arg1' into falling(arg0, arg1) is of type 'int'. but the function 'barssince()' only returns the # of bars as a series.
how can we extract an int from a series?-
This is a great conversation that's separate from the main topic, so I created a new topic to continue the discussion. Please reference the new topic here: PINE fallingsince
-
-
-
-
guys, here is an inconsistency issue re the use of the ?: operator:
for ex,
( series conditional_test series ) ? bool : bool --> error
BUT
( series conditional_test series ) ? 1 : 0 --> OK
if '1' and '0' are ok, then so should 'true' and 'false'.-
We'll fix this little issue today. Thanks
-
-
Fixed.
-
-
-
-
something weird is happening: this line
sb1_signal_color = sflag1 ? yellow : na
causes the price chart to disappear (the indicator panes are fine, the candles are gone)
BUT this line:
sb1_signal_color = sflag1 == true ? yellow : na
behaves properly and the plot color is indeed yellow! it's driving me nuts.
so i did one more test:
sflag1 = true (or sflag1 = 1)
sb1_signal_color = sflag1 ? yellow : na
causes no problem.
BUT
sflag1 = (sflag0 and (barssince(_cross(ema, sma) < 0) < 0) ? 1 : 0
sb1_signal_color = sflag1 == true ? yellow : na
also causes NO PROBLEM! obviously, the complex conditional returns 1, so sflag1 == 1 implies sflag1 == true BUT then why doesn't it work when sflag1 ? yellow : na ???
actually, i just tried something else:
sflag1 = 1
sb1_signal_color = sflag1 == true ? yellow : na
and execution goes to the 'else' branch (na)!
so 1 != true .
i had enough for one day. going to sleep.-
This is a great conversation that's separate from the main topic, so I created a new topic to continue the discussion. Please reference the new topic here: Pine Script weird bug
-
-
-
-
We close this topic because it's too long and it is difficult to navigate here. Please write all your new suggestions and problems in a separate topics
https://getsatisfaction.com/tradingvi... -
next » « previous |
Once again: [3] operator shifts not backward by 3 candles, but forward by 3 candles!
Here is the code illustrating it:
-------------------------------------------------------------------
study(title = "Test", shorttitle="Test", overlay = true)
original = sma(close,10)
shifted = original[3]
plot(original,color=red)
plot(shifted,color=blue)
-------------------------------------------------------------------
"Surely it shifts the series forward. It's not possible to shift it backward because it would have to give you NA b/c it's a future."
As I recall, TradStation language lets you move the series' both ways -- forward and backward.
It would be better to manipulate with both signs of shifts. If one of the function in the difference is not defined somewhere, the results should give just gap -- empty values.
macd = fastMA - slowMA[-offset]
It's a bit strange syntax for me but the problem is that it will not be calculated in realtime while giving you correct value on history. Because on every new realtime bar it will try to reference future and get NA. The only alternaive way this could work is recalculating the whole study on every new bar. It seems like excessive resource consumption.
Look, we have 2 MA's, every one coming from the past to the newest bar.
Now we are leaving MA1 alone, and shifting MA2 to the left by OFFSET number of bars. From the programming view point, if you count indices of the bars from the newest one to the left, you just shifting indices enumeration by OFFSET number and getting the negative indices of OFFSET number. The portion of the difference function MACD, corresponding to these negative indices will be just undefined, and on the graph you'll see this final function just shifted to the left with respect to price series.
All in all, I'm sorry to say that, but the whole concept of PINE language looks weird to me. Let me explain why.
The original motivation of the development of this scripting language was, it seems to me, to make life easier even to the person unfamiliar to programming. That is true, but with the PINE you can create really simple subset of indicators, which is of no interest to the pros.
The pros are usually people coming from tech fields with descent knowledge of programming. Suppose that they have some (fairly complex) idea of certain indicator. Now they need to make dual job: (i) formulate the algorithm in terms of regular language (Fortran or Java-like) (ii) translate the algorithm into Pine language.
This is awkward. You'll push customers out of your site toward sites like www.tradery.com, www.mq4.com and the likes. The same thing have already happend when the MQL developers moved from MQL4 to MQL5.
And don't forget, while you are developing PINE, the competitors create HTML5 interfaces similar to yours, but supplied by regular programming tools.
That is sad, since the TradingView interface and graphics are truly outstanding.
What can you do. I understand that you and other developers are under pressure of people in charge of the company toward developing PINE.
Why don't you make PINE just a library of regular FORTRAN/JAVA-like language, which include loops? This would make happy both people-in-charge and customers.
You right. The only missing point is that internally studies have 2 calculation modes - historical and update. Historical mode downloads all historical data and make initial study calculation. Then study switches to update mode when it gets only bar_new/bar_update events. Update mode calculates study on the last/new bar only. It doesn't recalculate whole study on every realtime event. It would be extremely resource consuming. If we had an offset N bars to the future then we would need on every bar update to recalculate last N bars. I agree that it's convenient from the programmers point of view. But currently it's too resource consuming to make it available. Especially when we have a workaround with double shifting.
We're thinking currently in this direction. We'll either create a JAVA SDK or make Pine powerful enough to handle most cases.