1

I cannot for the life of me figure out how to recreate this one line of Thinkscript in Pinescript. I have tried using valuewhen, highest, highestall, highestbars, and pivothigh, but none of them end up achieving the same results as tested in thinkorswim. (Image is Tesla daily since April) Image of thinkorswim results

GetValue(highest, 5), -4)

1 Answers1

3

In Thinkscript negative offsets refer to future bars. This is something that can't be done in Pine. Most likely you will have to refactor the entire script by adjusting offsets so that everything is referenced from the point of view of the current bar looking back only.

For example, a simple three bar pivot high in Thinkscript might be coded like this :

pivoth = GetValue(high, -1) < GetValue(high, 0) and GetValue(high, 1) < GetValue(high, 0)

But will have to be refactored like this for Pine :

pivoth = high < high[1] and high[1] > high[2]

rumpypumpydumpy
  • 3,435
  • 2
  • 5
  • 10
  • Thanks for mentioning this, I am encountering the same problem with this snippet: def isPeak = price > (avg + threshold * stdDev) and price > GetValue(price, 1) and price > GetValue(price, -1); where I am trying to display an indicator to detect a peak by comparing the close to the previous bar close and the future bar close. After reading your solution, I am still unclear how to apply to to my use case in order to get the next future bar close price. – adarvishian Mar 22 '23 at 14:51