Aryagm
Aryagm

Reputation: 550

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

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,

Upvotes: 0

Views: 2788

Answers (1)

e2e4
e2e4

Reputation: 3828

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.

Upvotes: 2

Related Questions