3

Is there a function in pine like pct_change() in python, which can calculate percentage change in pine? Since there is not data management system

Slartibartfast
  • 1,058
  • 4
  • 26
  • 60
  • 1
    There is a `change()` function but it just gives the difference between the current value and some previous value. You have to write your own. – vitruvius May 15 '20 at 08:44

2 Answers2

7

roc(source, length) will return 0.5 for 50%.

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
4

So, firstly, there's the function ta.change, which is a difference between current value and the value n bars back in a series. Secondly, there's also the Momentum function ta.mom, which is change in price specifically. Thirdly, there is a function Rate of Change ta.roc, which is Momentum normalised to the price n bars back. Fourthly, you can write your own to have said Momentum normalised to the current price if you prefer:

nmom = 100 * ta.mom(price, n) / price
Alejandro
  • 41
  • 4