Tim
Tim

Reputation: 105

How to calculate the net change of economic indicators/datasets in the TradingView?

I would like to know how to calculate the net change of economic indicators/datasets in the TradingView. I assume the only way is to use Pine Script?

net change = current reading - previous reading

You can import nicely many useful economic indicators in the TradingView but many of them show only the total cumulative amount and you can't change the unit. I would like to get the net change from the previous reading/month/quarter/year usually monthly and plot the data in the chart. I would also need to adjust the date for some of the economic indicators. For example, the Nonfarm payroll is released typically first Friday of the month but the TradingView shows the date first trading day of the previous month so I would like to adjust the date according to the release date.

For example, if I plot the Nonfarm (PAYEMS) data using the FRED (link below) the unit change is easy as different units are built-in, I just need to "edit graph" and choose the unit from the graph options: thousands of persons, monthly change, change from a year ago, percent change, percent change from year ago etc. I would like to get it done like this in the TradingView.

https://fred.stlouisfed.org/series/PAYEMS#

Upvotes: 1

Views: 382

Answers (1)

Tim
Tim

Reputation: 105

I managed to calculate the net change and plot the data on the chart, please see the example below.

Pine Script has a built-in "change" function for this particular purpose as I would have thought so. Please also see the commented example line if you wanna calculate it manually using the history reference operator "[1]", current value - previous value.

But now comes the tricky part as I would like to offset each bar with a different offset value so the date is the first Friday of the month. I believe Pine Script doesn't have a built-in function for offsetting each bar with a different value. The "plot" function has an offset argument but that will shift the whole series.

//@version=4
study("My Script")
payems = security("FRED:PAYEMS", "D", close)
monthly_change = change(payems, 1)
// monthly_change = payems - payems[1]
plot(monthly_change, style=plot.style_histogram, linewidth=2)

Upvotes: 1

Related Questions