PineCoders Squawk Box
3.84K subscribers
60 photos
166 links
News & Tips on TradingView's Pine programming language
Download Telegram
🌲 #newfeature
A new timeframe.in_seconds(timeframe) function provides a unified way to more easily compare timeframes. This will be useful in error-checking code, to disable indicators using request.security() when their timeframe would be lower than the chart's, or when deriving secondary timeframes from the chart's TF.

You can use it without an argument to get the chart's TF in seconds: timeframe.in_seconds():
https://www.tradingview.com/pine-script-reference/v5/#fun_timeframe{dot}in_seconds
👍4🔥1
🌲 #newfeature
A new `input.text_area()` function now provides a large input field for long text.
11👍10
🔈 #news
We have updated the text in the Community Scripts page's "About" box. Many Pine coders use Pine to develop their own indicators/strategies. That's great, and why TV develops Pine. A few of those authors also publish their work for the benefit of all TradingViewers. We never miss a chance to thank them because they bring tremendous value to traders all around the world.

We think it's safe to say that TradingView has become the hotbed of new developments in indicators concepts. We owe this to the creativity and generosity of our authors. Warm thanks go to all of you who publish useful scripts. 💙
👍1110
🌲 #newfeature
New array functions
We have added 8 new array functions that allow you to sort, search and do other useful stuff with arrays:
https://www.tradingview.com/pine-script-docs/en/v5/Release_notes.html#march-2022
👍22🔥31
🌲 #newfeature
A new index keyword can now be used in for...in structures to refer to the index of the current iteration:
https://www.tradingview.com/pine-script-reference/v5/#op_for{dot}{dot}{dot}in
👍13🔥112
🌲 #newfeature
You can now use placeholders of the form {{strategy.*}} in the string used with the alert_message parameter of strategy.*() functions. This makes realtime information available in alert messages generated from scripts, just as can be done when using the placeholders from the "Create Alert" dialog box's "Message" field:

//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)

alertString = '{{strategy.order.action}} {{strategy.position_size}} {{ticker}} \nMarket position was {{strategy.prev_market_position}} and is now {{strategy.market_position}}'

longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long, alert_message = alertString)

shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short, alert_message = alertString)
29👍6
🌲 #newfeature
Improvements to request.security() were rolled out. Its expression parameter now supports arguments of "string" type, and "int[]/float[]/bool[]/color[]/string[]" arrays, including in tuples:

//@version=5
indicator("")

bool barUp = close > open
color barColor = barUp ? color.green : color.red
string barDesc = barUp ? "Bar is UP" : "Bar is DOWN"
bool[] arrayBool = array.from(barUp, barUp[1])
color[] arrayColor = array.from(barColor, barColor[1])
string[] arrayString = array.from(barDesc, barDesc[1])
float[] arrayFloat = array.from(close, open)
sBool = request.security(syminfo.tickerid, "1M", close > open)
sColor = request.security(syminfo.tickerid, "1M", barColor)
sString = request.security(syminfo.tickerid, "1M", timeframe.period)
sArrayBool = request.security(syminfo.tickerid, "1M", arrayBool)
sArrayColor = request.security(syminfo.tickerid, "1M", arrayColor)
sArrayString = request.security(syminfo.tickerid, "1M", arrayString)
sArrayFloat = request.security(syminfo.tickerid, "1M", arrayFloat)
[tArrayBool, tArrayColor, tArrayFloat] = request.security(syminfo.tickerid, "1M", [arrayBool, arrayColor, arrayFloat])

if barstate.islast
label.new(bar_index, 0,
sString + "\n" +
str.tostring(sBool) + "\n" +
str.tostring(sArrayBool) + "\n" +
str.tostring(sArrayString) + "\n" +
str.tostring(sArrayFloat) + "\n",
color = array.get(tArrayColor, 0))
👍34🔥76
🔈 #news
You are welcome to join our new Q&A forum for Pine Script coders on Telegram: https://t.me/PineCodersQA

Note that the TradingView channel and this PineCoders Squawk Box are the only two other official TradingView outlets on Telegram.

Our new Telegram Q&A forum complements the two other Q&A forums where we already answer questions:
• The Stack Overflow [pine-script] tag
• The "Pine Script Q&A" public chat on TV
👏42👍1🔥1💩1
PineCoders Squawk Box
🌲 #newfeature Improvements to request.security() were rolled out. Its expression parameter now supports arguments of "string" type, and "int[]/float[]/bool[]/color[]/string[]" arrays, including in tuples: //@version=5 indicator("") bool barUp =…
🌲 #newfeature
The branches of if structures no longer need to return the same type when the if structure is not used to assign a value to a variable. This allows you to use if structures more liberally. Code like this will now compile:

//@version=5
indicator("", "", true)
var line e = na
if close > open
// This branch returns "void".
line.delete(e)
else
// This branch returns the "line" type.
e := line.new(bar_index - 10, high[10], bar_index, high)
17👍13🔥2👏2
🌲 #newfeature
Six new chart.is_* built-in variables help us detect the chart type used.
🔥11👍52
🌲 #newfeature
Variance, standard deviation and covariance built-in functions now have a biased parameter. Its default true value continues to use estimates of the population. When false is used, estimates of the sample can now be used instead.
👍15🤔3😁1
🛠 #fix
math.round(na) used to return zero instead of na, contrary to how other built-ins behave. This has been fixed. math.round(na) now returns na. If needed, you can still reproduce the previous behavior with nz(math.round(x)).
👍11
🌲 #newfeature
You can now extract the exchange or symbol part from any string in the "exchange:symbol" format using syminfo.prefix(string) and syminfo.ticker(string):

//@version=5
indicator("")
symbolInput = input.symbol("FX:USDCAD")
exchangeName = syminfo.prefix(symbolInput)
symbolName = syminfo.ticker(symbolInput)
ticker = ticker.new(exchangeName, symbolName, session.extended)
symbolClose = request.security(ticker, "1D", close)
plot(symbolClose)
if barstate.islastconfirmedhistory
label.new(bar_index, symbolClose, exchangeName + ":" + symbolName)
👍251
🌲 #newfeature
The risk_free_rate parameter was added to strategy(). It allows you to specify the reference rate of return used to calculate Sharpe and Sortino ratios:
https://www.tradingview.com/pine-script-reference/v5/#fun_strategy
👍10👏2🔥1
🌲 #newfeature
Premium accounts can now get more accurate strategy fills on their orders with the new Bar Magnifier feature. Keep in mind that more realistic fills do not necessarily produce more profits:
https://www.tradingview.com/blog/en/accurate-backtesting-with-bar-magnifier-31746/
🔥11👍2👏2
🌲 #newfeature
A new `request.security_lower_tf()` function makes it much easier to access information from intrabars, which are bars at a lower timeframe than the chart's. It returns an array containing one value per intrabar:
https://www.tradingview.com/blog/en/request-more-data-from-your-scripts-31944/
🔥18👍8
🌲 #newfeature
A new `request.economic()` function provides scripts with access to economic data from different regions and sectors:
https://www.tradingview.com/blog/en/request-more-data-from-your-scripts-31944/
👍4🔥41
🌲 #newfeature
A new syminfo.volumetype variable was added, which can help distinguish between base, quote and tick volumes on feeds for which the data vendor makes that information available. See it in use in the most recent "24-hour Volume" built-in indicator:
https://www.tradingview.com/blog/en/new-built-in-indicator-24-hour-volume-31718/
🔥6👍3