简体   繁体   中英

How to get the higher high and lower low values of all the candles in pinescript?

I would need some help please as I'm spending too much time in front of the computer and can't get my idea to work...

I have seen few examples of scripts getting the higher high value of the price in a specific time range, but I can't manage to get it from the whole range of the dataset.

Would it be any way?

I'm trying to create an indicator and normalize the values for each chart, that is why I need the values of the highest point and lowest point of all the candles in the chart.

Thank you!

It might be more beneficial to normalize over a set range, because the amount of total candles you have is arbitrary and may vary from account to account.

If you wanted to, you could use var to initialize variables and assign them values.

var float myHigh = na
var float myLow = na

if na(myHigh)
    myHigh := high
    myLow := low
else
    myHigh := max(myHigh, high)
    myLow := min(myLow, low)

There is probably a more graceful solution, but notice that I did not simply do something like myLow:= min(nz(myLow), low) as producing a value of 0 from na would produce a minimum would likely be lower than that of any commodity's price.

One caveat, if the first bar was the highest or lowest for the entire data set you must consider what happens when that bar is thrown away. Anything that relies on that information and by extension your normalization will be recalculated. This is why I tend to use a specific time to normalize to, or simply pull the high and low from a different timeframe. You could also just use highest(high, p) with a very large p.

I found this somewhere but couldn't find it again. :)

biggest(series) =>
    max = 0.0
    max := nz(max[1], series)
    if series > max
        max := series
    max

smallest(series) =>
    min = 0.0
    min := nz(min[1], series)
    if series < min
        min := series
    min

plot(biggest(close), color=color.green)
plot(smallest(close), color=color.red)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM