Number of pips between high and low of First Candle in Pine Script

2.4k views Asked by At

I want to write a code in pine script that enables me to calculate the number of pips between the high and low of only the First candle of the day. I also want to use this value in the form of a variable to set stop losses and targets.

I got this on the web but don't know how it works. Can we modify this to meet the above criteria?

getHighLowNumPips() => (high - low) / syminfo.mintick

plot(getHighLowNumPips())

I am a newbie in pine script and I am not able to write the code. Any help will be greatly appreciated :)

Thanks,

1

There are 1 answers

6
e2e4 On BEST ANSWER

In the example below the script will calculate the number of pips according to your getHighLowNumPips function on the first candle of the day and ignore other candles.

getHighLowNumPips() => (high - low) / syminfo.mintick 

bool isNewDay = dayofmonth != dayofmonth[1]

var float highLowPips = na
if isNewDay
    highLowPips := getHighLowNumPips()

plot(highLowPips)

Note that built-in dayofmonth use the exchange's timezone.