Shalafister's
Shalafister's

Reputation: 889

Pine editor get True Range of a specific bar

I'm rather new at pine script. I am trying to calculate the True Range of a specific candle with calculation of lowest low. (This is the stop loss part of a TDS Long Setup)

lastBuyLowestValSTOP = buySetup == 9 ? lowest(low, 9) : nz(lastBuyLowestValSTOP[1])

This finds the lowest low value when buySetup criteria is met. Lets say it is 7th candle(9-2).

Now I have the lowest value, I need that candle's trueRange = high-low data. So I can;

stopPoint = lastBuyLowestValSTOP - trueRange

But I dont know that candle's index neither its high or low. I checked barssince() but it requires a criteria. When I try;

lowestSinceIndex = buySetup == 9 ? barssince(lowest(low, 9)): nz(lowestSinceIndex[1])

This returns 0. How can I get that candle's high and low values. Thanks in advance.

Upvotes: 0

Views: 697

Answers (1)

Bjorn Mistiaen
Bjorn Mistiaen

Reputation: 6905

//@version=4
study("TrueRange", "TR", overlay=true)

ll = lowest(low,9)
lb = lowestbars(9)

hist = abs(lb)

trueRange = high[hist] - low[hist]

plot(na)

Upvotes: 1

Related Questions