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 rather prefer,(together with present indicators alteration like Bollinger Bands on Chande momentum for example) an enlarging of the current list of available indicators like Elder Bull/Bear Power or MACD Forest.
Anyway, new ideas are ALWAYS welcome.
Kind regards from
F.Javier Garcia- Spain- view 2 more comments
-
-
-
how come the chart does not show up
-
-
mychart does not work, how come
-
-
-
Brilliant. Congratulations to the team for its vision, mastery at innovation, and always bringing a new generation of charting tools to the community. Bravo, Sincerely, Beauty
-
-
-
-
-
There's a list of available functions: https://www.tradingview.com/study-scr...
-
-
Great - thanks! (Maybe make sure that's easy to find, if not already?)
-
-
-
-
Provides great flexibility, great idea.
But I am afraid that it would totally refrain trading view from development in this area -
-
great work guys great work,
would be fantastic if there is any counting build in functions.. like count the bars 1, 2,3,4 .. etc based on criterias- view 1 more comment
-
-
If you have operator overloading, only one function's needed for this. (Ie sum with one parameter = cum)
-
-
Actually we have overloaded functions. Nice idea.
-
-
-
Nice work guys - Pine looks like a great language for this - simple and clear. In the first hour I've known about this, I have made two new indicators by modifying existing indicators. Thanks!
-
-
I think code for some of the indicators is missing from the script editor; eg no zig zag filter...
-
Not all indicators can be translated to Pine currently. We'll be working on this going forward.
-
-
-
-
Great new addition! Very user friendly, good job. I would say this is the cherry on the sunday :)
-
-
This looks great. Could you let me know if you plan to have semantics to create events on the chart based on critical events such as an EMA cross, or a BollingerBand breached ? Any visible indication on the chart, such as a text-box would be interesting.
If this is already possible, could you point me to documentation, thanks!- view 5 more comments
-
-
-
-
-
-
just wondering if the serverside alerts is still beeing worked on? .. regards
-
-
Yes. We're working on it.
-
-
-
A step in the right direction. Good Job Stan and the the TradingView team. #gamechanger.
-
-
Ive already made some progress with it, but still I have problems figuring out the conditional operation.
im trying to execute a simple : If then else operation
and im having a hard time, theres the IFF function who seems to be it but theres no example anywhere.
Could you guys add a few conditional operation examples ? :D
thanx again this is really a giant step forward, love the site- view 2 more comments
-
-
-
Currently 'else' part is mandatory. So try this
plot(out1 == out2 ? out : na, title="detected", color="fuchsia", style=cross, linewidth=2)
'na' reads as 'not available'
BTW, if you want a cross of two series then use functioncross(series1, series2)
. It should be something likeplot(cross(out1, out2) ? out : na)
-
-
thanx :) this is awesome you guys deserve a lot of money for this
-
-
-
How does one add inputs to custom scripts? For eg, I want to be able to change inputs to ROC and plot different lengths.
- view 2 more comments
-
-
-
Inputs has been implemented. Currently it accepts integers, floats and bools. We will add strings and expressions a bit later.
For example:
length = input(10)
plot(sma(close, length))
Check documentation for more details. -
-
Nice work...:)
-
-
-
Block Ifs, block loops, switches would be nice to have.
Is there a way to maintain state?
Or self reference? ...
MyVar = log((2 * close) / (high + low))
MyNewVar = MyVar[n - 1]
plot(MyVar - MyNewVar, color=green)-
You can try
study(title='Moving Sum')
len = 5
sum = nz(close) + nz(sum[1]) - nz(close[len])
plot(sum) -
-
-
-
I need the ability to paint or highlight specific bars in Pine based on calculations.
A nice elliptical colored background or a color on the bar itself is a good way to point out specific days from a Pine script.
A second capability I'd like to have is the ability to offset moving averages. I know I can offset when plotting. Sometimes I need to build an offset array of closes.
Thanks, Pine is a great new direction!- view 1 more comment
-
-
On bar color, thanks. On array offsets, sometimes I need to offset arrays for calculations rather than plotting.
-
-
Looks like you need offset operator (square brackets):
ma = sma(close, 10)
plot(ma[10]) -
-
-
How could I implement DeMarker indicator? The definition states:
The DeMax(i) is calculated:
If high(i) > high(i-1) , then DeMax(i) = high(i)-high(i-1), otherwise DeMax(i) = 0
The DeMin(i) is calculated:
If low(i) < low(i-1), then DeMin(i) = low(i-1)-low(i), otherwise DeMin(i) = 0
The value of the DeMarker is calculated as:
DMark(N) = SMA(DeMax, N)/(SMA(DeMax, N)+SMA(DeMin, N))
I figured out some lines of code but seems I am making some mistakes:
high > high[1] ? DeMax = high - high[1] : DeMax = 0
low < low[1] then DeMin = low[1] - low : DeMin = 0
DMark = sma(DeMax, n)/(sma(DeMax, n) + sma(DeMin, n))
plot(DMark, color=lime)
Could you please give me a hand on this?-
Try this:
DeMax = high>high[1] ? high-high[1] : 0
DeMin = low<low[1] ? low[1]-low : 0
len = 9
DMark = sma(DeMax, len)/(sma(DeMax, len)+sma(DeMin, len))
plot(DMark) -
-
The more I get into this language the more I love it. I really appreciate your work. Thank you for your help!
-
-
-
-
I also wanted to add for anyone looking into PINE scripts never put a '.' in the title or short title.
Things like "study(title="MACD1.1", shorttitle="MACD1.2")" will turn your charts into blank white pages permanently until you manage to erase the script-
Fixed.
-
-
-
-
I like very much your new scripting language for Trading View. Having the ability to custom code indicators is a great feature to have. It is especially impressive that you have done this for an online charting tool. Great job. I look forward to your further enhancements to this already great feature set.
-
-
I miss a few things.
1. Looping _or_ tail recursion functions (for looping ;)
2. Generalized if-conditionals for multi-route source
3. Easier to spread code over multiple lines
4. Arrays / lists - Sooo many cases where it would do wonders.
examples: list of color pairs for easy referencing in multi-case colorer for histagram, list of params for multiple EMA's, etc.
Thanks for a great job!
Cheers,
Oscar- view 1 more comment
-
-
>>>>>3. Easier to spread code over multiple lines
You can write a function call with long arguments list on a few lines like this (if you don't know):
plot(close,
offset=5,
style=cross) -
-
2) "Pine is a functional language" -- ugh. Too bad. Hopefully it will evolve be a more of a hybrid. Everything else seems great so far.
-
-
-
Something I've been struggling to do: conditional operations depending on view-period.
Tried:
metalsOffset = period == '1' ? 6 : period == 'D' ? 1 : 0
But apparantly string comparison is prohibited.
I would love it if there was an integer based, minute based variable with the current view period length.-
Thanks. We'll add it. Meantime you can use functions isdwm, isintraday, isdaily and interval.
-
-
Please look at the 'interval' built-in variable of integer type. I think it is what you need:
https://www.tradingview.com/study-scr... -
-
-
-
I just wanted to ask if there's a simple way to write in a moving avg for ROC.indicator.
I wanted to find out if Pine script is based on similar syntax as other popular platforms. I've been able to find the script for various indicators via searches, but didn't know how much modification would be needed for cut and paste from script written for these other platforms to Trading View's Script window, to create new indicators. Thanks for any help.-
Try this
plot(sma(roc(close, 10), 10))
-
-
Thanks!
-
-
-
-
Plot shapes.
Pine is great - another very useful capability would be the ability to plot shapes:
a triangle, square, circle, delta, diamond, etc, filled or unfilled and with a controllable size and color above or below a price bar will allow us to display signals on charts.-
Thanks for suggestion. It's already in plans.
-
-
-
-
I'm amazed at how functional the scripting facility is, given when you released it. Congrats.
Would like:
The ability to reference a particular bar on the chart, or index value of a variable. Example, I want to use the first calculated value of a series, as a constant. Currently I have to work around it with an arithmetic if-statement like below:
VarA = atr(length)
VarB = na(VarA[1]) ? VarA : VarA[1]
Index functions that return the number of visible bars, iterate through them, etc would allow for more advanced scripts. -
-
-
ConnorsRSI will be possible to write in Pine in 3-4 weeks. It's already in plans.
-
-
-
-
Hey whats up GODS OF PINE SCRIPTS :) Im having a hard time with a script im working on. It seems that I cant switch colors in a fill depending on certain conditions.
here is the mess :
-----------------start of code--------------------
study(title="EMA TUNNEL", shorttitle="EMA TUNNEL", overlay=true)
src = close
len1 = input(12, minval=1, title="Length")
len2 = input(144, minval=1, title="Length")
len3 = input(169, minval=1, title="Length")
out1 = ema(src, len1)
out2 = ema(src, len2)
out3 = ema(src, len3)
bound_a = plot(out1, title="EMA", color=yellow, linewidth=2)
bound_b = plot(out2, title="EMA", color=green, linewidth=2)
bound_c = plot(out3, title="EMA", color=red, linewidth=2)
colorsense = out3 < out2 ? green : red // Culprit #1
fill(bound_b, bound_c, color=white, transp=75)
fill(bound_a, bound_b, color=colorsense, transp=60) // Culprit #2
------------------------end of code-------------------------
im trying to fill RED OR GREEN depending on the trend.
it seems the 2 lines where ive wrote CULPRIT at the end are breaking my code and im getting : Converting circular structure to JSON.
Am I trying to do something crazy or is this a bug?
maybe I should use 2 different fill. anyways keep up the good work love this- view 1 more comment
-
-
Hello! I confirm that fill function doesn't support expressions for 'color' parameter (https://www.tradingview.com/study-scr...).
-
-
Currently fill doesn't support expression. We'll fix this, though it's not a top priority.
-
-
-
I wondered if there might be a way to script a moving average for the Momentum indicator. I would like to somehow figure out a script for the Squeeze indicator which is based on it and shows red dots when the Bollinger Bands contract within the Keltner channel.
Also wanted to find if there's a way to script a two-color EMA that changes color based on up or down direction like the Awesome Indicator.
Thanks again for the great additions to Trading View!
-
1. If i got you right you need a way to print a red dot on some bar based on some condition. It's possible with something like
plot(close > open ? close : na, style=circles, linewidth = 4, color = red)
2. Plot different colors based on some condition you can with
plot(close, color = open > close ? red : green)
-
-
-
-
How can we create a indicator which is essentially % difference between WMA(10) & WMA(40) and convert into a histogram?
Any help is appreciated.... -
-
I think you can open the Script Editor, then choose New, then choose the Awesome Indicator, and substitute wma for sma where appropriate, and change the numbers from h12,5 and h12,34 to h12,10 and h12,40 respectively.
-
-
Thanks for prompt reply, after few trial & error, I was able to build the custom indicator.
-
-
i think i found a bug:
this works fine:
src = close
hma = wma(src, 5)
plot(hma, color=blue)
but this does not:
src = close
hulllen = input(type=integer, defval=27, minval=1, title="Hull Period")
hma = wma(src, floor(sqrt(hulllen)))
plot(hma, color=blue)
the script does compile without any errors but upon attaching it to the chart, the latter version triggers the following error msg: 'script error' and the script title turns red.
isn't floor() supposed to return an integer?-
Thanks for report. Has already been fixed and should be deployed to production on Tuesday.
-
-
-
-
ok there is something strange with the sqrt function's return value: i tried to plot the final variable hma after doing this assignment:
flrHullsqrt = sqrt(16) == 4 ? 5 : 27
hma = wma(src, flrHullsqrt)
and i keep getting 'script error'. either way, sqrt(16) should equal 4 and the ternary expression should return an integer no matter what.
if i type instead:
flrHullsqrt = 5
hma = wma(src, flrHullsqrt)
hma plots fine.
(src, of course, is a series such as close or open, etc...)
ok, i'll let you guys look into this as i have no patience left anymore.- view 2 more comments
-
-
-
It's in testing right now. Should be in production on Monday.
-
-
Fixed. Remember to use round because floor returns float.
hma = wma(src, round(floor(sqrt(16))) ) -
-
-
request:
pivot high, left and right strenght
pivot low, left and right strenght
drawing trendline between 2 points -
-
I was also messing around with creating a hull function. It looks like predefined functions like wma() don't accept variable values. For example, if you set length as a constant input, but then calc length/2 and use that as an input to wma, you get n/a on the chart.
We'll see whether the fixes that come out on Tues mentioned above also address this issue.-
also, and i think this is relevant to the point fractaltrader is bringing up (i also tried to implement the Hull MA) but the only valid type as input into one of the moving average functions is restricted to 'integer' and in the case of Hull we need to take the square root of a value which returns, of course, a float, which can't be passed as an argument to any of the MA functions.
overloading those MA function signatures would be helpful. -
-
-
-
-
Yes, it is.
study(title="MyScriptStudy", shorttitle="MSS", overlay=true) -
-
-
-
Hello
I want Draw two color indicator
x = bearCondition ? value : 0
y = bullishConditio ? value : 0
plot(x, color=green, title="UpTrend",style=line)
plot(y, color=red, title="DnTrend",style=line)
I want not draw green line when I have a bearish condition- view 1 more comment
-
-
Thanks Admin
I use this
x = bearCondition ? value : na
y = bullishConditio ? value : na
x = 10 y = na
x = 11 y = na
x = 12 y = na -> A
x = na y = -10
x = na y = -21
x = 10 y = na -> B
When B set.
A connect to B with line
I do not want to be connected points
thanks -
-
It's not currently possible. But you can use the following:
plot(bear or bullish ? value : na, color = bear ? red : green)
So, use single plot instead of two separated. Will that work? -
-
-
Are we allowed to build custom tools (like the ones on left hand side of trading view) instead of custom indicators using scripts?
-
No. Currently script allows to develope indicators only. We're discussing possibility to expose drawing tools through Pine but it's not yet decided.
-
-
-
-
re Error: Cannot call `operator ==` with arguments (string, string);
was trying
x = ((ticker == 'EURUSD') or (ticker == 'GBPUSD')) ? someValue0 : someValue1
how can one specify conditional computations based on what the current symbol happens to be?
so, having regex and some basic string manip functions available would be useful so that one, instead of specifying the full string 'EURUSD', for ex, could simply specify '*USD' so that the computation would be selected only for those pairs whose quote ccy is the USD. that way there is no need to hardcode all possible if/then cases. -
-
It's in our plans but so far working with strings is not implemented.
-
-
guys, why does this line of code:
hline(highest(close, 4), color=loline_color, linestyle=dotted)
generate the following error:
Error: Cannot call `hline` with arguments (series, color, integer); available overloads: hline(float, literal__string, color, integer, integer, string) => hline
???
isn't highest() supposed to return a float and not a series?
the API page says that highest returns the 'Highest value for a given number of bars back.' by value i assume you mean a single number value, yes?-
highest() returns series. Currently there are no ways to do what you're looking for. We're thinking in this direction though.
-
-
-
-
valuewhen (Built-in function) : can someone give an example of this?
-
See 'Divergence Indicator'
-
-
-
-
guys,
great job. just noticed all the new indicator scripts.
2 questions though:
1- is it possible to call a script from another script, i.e. with the same syntax as a function call?
2- why does this conditional not work?
x = (open / 1000) > 1 ? input(2.9, type=float, minval = 1, title='delta') : input(0.29, type=float, minval = 0.1, title='delta')
in other words, depending on the condition, shouldn't one input or the other be assigned to the variable x?
instead, once the indicator is displayed and you click on the gear icon to change the default inputs, there are now 2 'delta' input fields displayed, both with the 0.29 value even though open / 1000 > 1 is true. it makes no sense.- view 4 more comments
-
-
-
-
-
*** damn it!! i was using '< --' instead of '=' and apparently if you type ' < -- ' with no space between the < and -, it confuses getsatisfaction and the post gets mangled ***
if (cond == true) then
x = assign some value from arithmetic expression
else
x = assign another value from arithmetic expression
in c/c++/java/javascript/python etc... it doesn't matter whether the value to be assigned results from some arithmetic computation or is simply the return value of some function call as in:
if (cond == true) then
x = function1(...) { computation1}
else
x = function2(...) {computation2}
i thought that the ternary operator ?: was equivalent to if/then/else. therefore i thought that calling a function such as input() in either branch would assign the return value.
i guess i don't understand why 'entity of a different abstraction level' is relevant. if input() is a function returning a value, then we should be able to call that function from within an if/then/else statement or it's shorthand equivalent ?:
or am i missing something here? do some entities in pine look like they have function syntax but are not or cannot be treated as functions?
finally, if only one branch of the conditional construct ?: is executed, then why does the pine runtime environment also take into account what is in the other branch (in this case, both input() calls)? shouldn't only input() call be executed since we are dealing with a binary true/false condition? that is what i cannot make sense of.
do you guys have a wiki page by any chance we could use as a reference so we can understand more about how different pine is from other more common scripting languages out there? -
-
or am i missing something here? do some entities in pine look like they have function syntax but are not or cannot be treated as functions?
>>>>> That's right, input, study, plot, fill, hline look like functions and in some cases they behave like funcitons. But not completely. They are declarations, something related to metaprogramming (Java Annotations, .NET Attributes). This could be confusing, I agree
Declaration functions in pine use keyword arguments. This differs them from usual functions. -
-
-
one more issue:
had a script running just fine when suddenly the plot disappears and i get a 'script error' msg next to the script name. that happened after running without problems for a couple of hours. i isolated the problem to this statement:
hma = wma(2 * wma(src, hulllen/2) - wma(src, hulllen), round(sqrt(hulllen)))
replace round(sqrt(hulllen)) by an integer literal, say 5 for example, and the script works fine again.
apparently some issue with the round() function.-
It's a known issue, will be fixed soon https://getsatisfaction.com/tradingvi...
-
-
-
-
i'm going to repeat my self:
pivot high
pivot low
didnt get any reply on it.. is this something available some day? .. i tried to code it myself but it seems pine is not able to do it yet. (no loops)
correct me if i'm wrong.- view 3 more comments
-
-
-
-
thanks.. i'll have a look.. in the weekend
-
-
so i found a way to do it manually :
pivothigh = valuewhen((high[6]=high[2] and high[3]>=high[1] and high[3]>=high),high[3],0)
pivotlow = valuewhen((low[6]>=low[3] and low[5]>=low[3] and low[4]>=low[3]) and (low[3]<=low),low[3],0)
thats 2bars left and 2 right ..
now the problem is. if i want to have like 5 bars left or right.. ill have to write a lot of code .. if only i could do it with some loop..
i did try with lowest and highest, bar sinse;... functions but they dont seem to be giving same results .. tips welcome -
-
-
How do I plot a line for just one day based off of a single bar so that it stays at that place regardless of timeframe that I am in.
- view 5 more comments
-
-
-
-
-
-
One quick follow up message, how do i disconnect the lines between each day's OR? Thanks again.
-
-
Currently it's not possible. We'll probably add it.
-
-
-
Very good job on the pine script :)
...but...
There is no way to compare or operate on string variables ie.
if (ticker == "EURUSD") "then plot security('GBP' + 'first three letters from current ticker')"
Additional functions like charAt / indexOf etc... would be appreciated
That would be helpfull to calculate pip value for current instrument.-
String functions are planned.
-
-
-
-
TradingView Pine Script New Features! Read more http://blog.tradingview.com/?p=223
-
very pleased with the new functions..
-
-
great work, excited to try some of the new features
-
-
-
-
Divergence Indicator does not work. It seems to be a problem with the brackets [ ] calling the previous value. (ie: bullishNDiv[1]). This seems to also impact scripts of mine that worked last Friday the 31st but do not work today after the addition of the new features over the weekend.
-
We're working on it.
-
-
We've fixed the bug. Check please.
-
-
-
-
new bug:
this line used to work fine until today feb 3 it suddenly stopped working--haven't changed anything in the script:
this line causes error: unexpected number of arguments
plot(varseries, color=sell_signal_color, style=circles, linewidth=4)
and when i replace the series with, say, open, like so:
plot(open, color=sell_signal_color, style=circles, linewidth=4)
i get another error: script error
after some investigating i narrowed the new bug down to this part of the code:
(this is the chande momentum osc which still works fine)
cmolen = input(defval=10, title='CMO Period', type=integer)
smalen= input(defval=9, title='CMO SMA Period', type=integer)
losses = sum(open>close, cmolen)
gains = sum(open 50 and cmo[1] > cmosma[1] and cmo < -50 and cmo[1] < cmosma[1] and cmo >= cmosma
i found out that now these 2 vars are not assigned properly anymore.
so i tried to plot cmo, cmosma, and cmosma[1]. no problem.
BUT if i plot cmo[1], then i get the error 'script error'.
like i said, the script didn't change between yesterday and today. was fine yesterday.
why is cmosma[1] ok but cmo[1] is not?- view 1 more comment
-
-
We've fixed the bug. Check please.
-
-
all good again. thanks.
-
-
next » « previous |